0

I'm struggling to use ogr2ogr to convert a GML file into a GeoJSON file. My input is zipped GML files with several layers. I'm only interested in the layer with name 'TopographicArea'.

I've tried converting using the following at the command line:

ogr2ogr -f GeoJSON .\3925845-HW5929.geo.json .\3925845-HW5929.gz

This fails with the error:

ERROR 1: Layer 'TopographicPoint' does not already exist in the output dataset, and cannot be created by the output driver.

I'm presuming this is because GeoJSON doesn't support layers.

How can I tell ogr2ogr to ignore all layers except one?

P.S. I have thousands of GML files to process, so this needs to be scriptable.

3

Use the 'layer' option:

ogr2ogr -f GeoJSON .\3925845-HW5929.geo.json .\3925845-HW5929.gz LayerNameHere

Alternatively, if you need more control, you could use a SQL query with the '-sql' option.

  • 1
    The syntax is actually ogr2ogr -f GeoJSON .\3925845-HW5929.geo.json .\3925845-HW5929.gz LayerNameHere. You can check what layers exist in the .gz file with ogrinfo .\3925845-HW5929.gz. – user30184 Aug 16 at 15:41
  • Good catch, thanks! – Alex Aug 16 at 15:42

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.