Ticket #3941 (closed defect: invalid)

Opened 2 years ago

Last modified 2 years ago

GeoJSON to GPX fails on mixed features

Reported by: vibrog Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.8.0
Severity: normal Keywords: gpx, geojson, ogr2ogr
Cc:

Description

I'm using ogr2ogr to convert GeoJSON created by OpenLayers? 2.10, and it fails when the GeoJSON contains a mix of Points and LineStrings?. But GeoJSON with only one feature type at a time works fine. Is this an expected behaviour?

Change History

Changed 2 years ago by rouault

  • status changed from new to closed
  • resolution set to invalid
  • milestone 1.8.1 deleted

Yes this is expected behaviour and not much can be done to improve that. This is mainly due to the structure of GPX files where points must be written before lines to validate the XML schema, so if they appear in random order in the GeoJSON, this is bound to fail.

More details in the "Creation issues" section of  http://gdal.org/ogr/drv_gpx.html

You could workaround this by doing something like :

mkdir tmp
ogr2ogr tmp/points.shp your.geojson -sql "select * from OGRGeoJSON where OGR_GEOMETRY = 'POINT'"
ogr2ogr tmp/lines.shp your.geojson -sql "select * from OGRGeoJSON where OGR_GEOMETRY = 'LINESTRING'"
ogr2ogr -f GPX out.gpx tmp points lines

Changed 2 years ago by vibrog

should i expect this to work, e.g. throw away Points if any?

ogr2ogr -f GPX stdout your.geojson \
   -sql "select * from OGRGeoJSON where OGR_GEOMETRY = 'LINESTRING'"

Changed 2 years ago by rouault

yes, that should work

Note: See TracTickets for help on using tickets.