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.

1 Answer 1


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
    Commented Aug 16, 2019 at 15:41
  • Specifying multiple layers fails. From the help output it looks like the layers should simply be separated by space. Exporting the layers one-by-one works.
    – olejorgenb
    Commented Aug 19, 2023 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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