Thursday, 8 November 2018

SQL statement with GeoJSON driver in GDAL 2.2 not working


In GDAL 2.1.2 I was able to query from a GeoJSON data source using the following:


ogr2ogr -f geojson -dialect sqlite -sql "select * from OGRGeoJSON where NAME in ('Albania','Algeria')" countries.json world.json 

Whereas in GDAL 2.2.4 this results in the following error:



ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(select * from OGRGeoJSON where NAME in ('Albania','Algeria')):
no such table: OGRGeoJSON

What's changed?



Answer



According to the GeoJSON documentation for GDAL 2.2:



Starting with GDAL 2.2, the layer name is built with the following logic:


If a "name" member is found at the FeatureCollection level, it is used. Otherwise if the filename is regular (ie not a URL with query parameters), then the filename without extension and path is used as the layer name. Otherwise OGRGeoJSON is used.




From this it seems the new syntax should be:


ogr2ogr -f geojson -dialect sqlite -sql "select * from world where NAME in ('Albania','Algeria')" countries.json world.json 

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...