0

Is ogr2ogr capable of merging two GeoJSON files to a new one? It is possible to merge shapefiles to one GeoJSON using the VRT driver. But when trying to do the same using GeoJSON files ogr2ogr fails.

VRT is:

<OGRVRTDataSource> <OGRVRTUnionLayer name="union"> <OGRVRTLayer name="Bundeslaender"> <SrcDataSource>C:\Users\root\AppData\Local\OGR_Contextmenue\Bundeslaender.geojson</SrcDataSource> </OGRVRTLayer> <OGRVRTLayer name="standorte"> <SrcDataSource>C:\Users\root\AppData\Local\OGR_Contextmenue\standorte.geojson</SrcDataSource> </OGRVRTLayer> <GeometryType>wkbGeometryCollection</GeometryType> </OGRVRTUnionLayer> </OGRVRTDataSource>

And the ogr command:

ogr2ogr.exe -f "GeoJSON" "C:\Users\root\Desktop\Plugin_new\Shapefiles_Karte\Bundeslaender\Bundeslaender.geojson" "C:\Users\root\AppData\Local\OGR_Contextmenue\vrt.vrt" -overwrite

The error ogr2ogr gives me is:

ERROR 1: Failed to find layer 'Bundeslaender' on datasource 'C:\Users\root\AppData\Local\OGR_Contextmenue\Bundeslaender.geojson'. ERROR 1: Failed to find layer 'standorte' on datasource 'C:\Users\root\AppData\Local\OGR_Contextmenue\standorte.geojson'.

To clear out: the files are existing at the path given in the vrt. I double checked it. Also the path where the merged GeoJSON file should be created exists and is accessible. Doing the same with Shapefiles is no problem! So what am I missing here?

  • 1
    Have you noticed that for the GDAL geojson driver the layer name is always OGRGeoJSON? – user30184 Jul 14 '16 at 9:49
  • I don't know what you want to say with that? – Leo.1906 Jul 14 '16 at 12:40
1

You can "merge" GeoJSON with ogr2ogr by appending the second to the first or writing both into one new file if you want to keep the original files. In your example: use bundeslaender.geojson and standorte.geojson as parameters. This works for me:

ogr2ogr -f GeoJSON bundeslaenderUndStandorte.geojson bundeslander.geojson
ogr2ogr -f GeoJSON -append bundeslaenderUndStandorte.geojson standorte.geojson

Maybe it even works with VTR if you use -append instead of -overwrite

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.