[gdal-dev] Writing a GML file containing multiple layers

Even Rouault even.rouault at mines-paris.org
Wed Apr 3 04:22:22 PDT 2013


Selon Matt L <mlangley at geoplex.com.au>:

> Hi Everyone,
>
> I am attempting to use ogr2ogr to convert GeoJSON to GML. It works well for
> a single json file. But I would like to convert several files, such that
> each input file ends up as a separate layer in a single GML output file.
>
> The GML help doc seems to suggest that GML can be written with multiple
> layers - i.e. "On export all layers are written to a single GML file all in
> a single feature collection. Each layer's name is used as the element name
> for objects from that layer."
>
> I tired at first by simply adding additional json files to the command line
> :
>
> ogr2ogr -f GML output.gml roads.json buildings.json
>
> But this fails with the error :
>
> "FAILURE: Couldn't fetch requested layer 'buildings.json'!"
>
> (this is a valid file by the way - and can be converted on it's own).
>
> Can anyone shed any light on this? Is it possible to write multiple layers
> (for example, from an input file representing roads, and an input file
> representing buildings) to a GML file using ogr2ogr? If not, can this be
> done in code somehow?

You cannot specify several input datasources to ogr2ogr. As the error message
suggests the 3rd name "buildings.json" is interpretated as a layer name of
roads.json.
To do what you want to do, you could for example convert both JSONs to
shapefiles (in a directory) and convert the shapefile directory (which will be
seen as a multilayer datasource) as GML

ogr2ogr temp_shapefiles roads.json -nln roads
ogr2ogr -update temp_shapefiles buildings.json -nln buildings
ogr2ogr -f GML output_gml temp_shapefiles

Another way is to create a OGR VRT that has 2 layers made of roads.json and
buildings.json and convert it to GML with ogr2ogr. See
http://gdal.org/ogr/drv_vrt.html for the syntax of OGR VRT files.

>
> Any help greatly appreciated.
>
> Regards,
> Matt
>
>
>
> --
> View this message in context:
>
http://osgeo-org.1560.n6.nabble.com/Writing-a-GML-file-containing-multiple-layers-tp5044264.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>




More information about the gdal-dev mailing list