2

ogrinfo ":memory:" -dialect sqlite -sql "SELECT ST_GeomFromText('Point(1 2)')" gives me a dataset with a geometry column:

INFO: Open of `:memory:' using driver `SQLite' successful. Layer name: SELECT Geometry: Unknown (any) Feature Count: 1 Extent: (1.000000, 2.000000) - (1.000000, 2.000000) Layer SRS WKT: (unknown) Geometry Column = ST_GeomFromText('Point(1 2)') OGRFeature(SELECT):0 POINT (1 2) 

but this does not work with some curve geometries, e. g. CIRCULARSTRING.

ogrinfo ":memory:" -dialect sqlite -sql "SELECT ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)')"

for example results in:

INFO: Open of `:memory:' using driver `SQLite' successful. Layer name: SELECT Geometry: None Feature Count: 1 Layer SRS WKT: (unknown) ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)'): String (0.0) OGRFeature(SELECT):0 ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)') (String) = (null) 

How can I work with such geometries when using the sqlite dialect? I would be fine with turning them into linear geometries in the query. Using -nlt CONVERT_TO_LINEAR is not a solution for me. The actual problem I am trying to solve is in third-party software that uses the same logic and there we can only edit the query (QGIS layer filters).

References:

1 Answer 1

2

The GDAL SQLite dialect supports the basic SQLite functions https://www.sqlite.org/c3ref/funclist.html and spatial functions from SpatiaLite https://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html. Using SQLite dialect means that data are converted temporarily into SQLite/SpatiaLite format. SpatiaLite does not support geometries like CircularString so what you want to do is unfortunately impossible. The geometrytypes that SpatiaLite supports can be found for example from the header file https://www.gaia-gis.it/gaia-sins/splite-doxy-5.0.1/gg__const_8h_source.html.

I am not sure if there is any good workaround. If you save the data into PostGIS instead of memory, then the default SQL dialect will be the PostgreSQL/PostGIS one.

Proof of concept with an in-line geometry:

ogrinfo PG:"host=localhost port=5432 dbname=my_db user=user password=password" -sql "SELECT ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)')" Layer name: sql_statement Geometry: Unknown (any) Feature Count: 1 Extent: (0.990399, 1.490399) - (7.000000, 5.000000) Layer SRS WKT: (unknown) OGRFeature(sql_statement):1 CIRCULARSTRING (1 5,6 2,7 3) 
1
  • Thanks, I feared that (saw an open ticket about CIRCULARSTRING, COMPOUNDCURVE and CURVEPOLYGON at gaia-gis.it/fossil/libspatialite/tktview/…) :( We are working with GeoPackages so sadly the PostGIS engine won't be a solution. Commented Dec 5, 2022 at 15:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.