Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#3941 closed defect (invalid)

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 (3)

comment:1 by Even Rouault, 13 years ago

Milestone: 1.8.1
Resolution: invalid
Status: newclosed

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

comment:2 by vibrog, 13 years ago

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'"

comment:3 by Even Rouault, 13 years ago

yes, that should work

Note: See TracTickets for help on using tickets.