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?


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 
  • And there is no need to guess the name of the layer because you can check if with ogrinfo world.json. – user30184 May 7 '18 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.