Skip to content
Permalink
Browse files

[ogr] Read GPX elevation values as geometry Z values

(cherry-picked from 4080aad)
  • Loading branch information
nyalldawson committed Jul 1, 2016
1 parent 7e85d29 commit 4d8bb8b306f7411594ee1e4899993eb3ebe81791
@@ -2841,6 +2841,7 @@ void QgsOgrProvider::open( OpenMode mode )
QgsDebugMsg( "mLayerName: " + mLayerName );
QgsDebugMsg( "mSubsetString: " + mSubsetString );
CPLSetConfigOption( "OGR_ORGANIZE_POLYGONS", "ONLY_CCW" ); // "SKIP" returns MULTIPOLYGONs for multiringed POLYGONs
CPLSetConfigOption( "GPX_ELE_AS_25D", "YES" ); // use GPX elevation as z values

if ( mFilePath.startsWith( "MySQL:" ) && !mLayerName.isEmpty() && !mFilePath.endsWith( ",tables=" + mLayerName ) )
{
@@ -153,5 +153,23 @@ def testNoDanglingFileDescriptorAfterCloseVariant2(self):
os.unlink(datasource)
self.assertFalse(os.path.exists(datasource))

def testGpxElevation(self):
# GPX without elevation data
datasource = os.path.join(TEST_DATA_DIR, 'noelev.gpx')
vl = QgsVectorLayer(u'{}|layername=routes'.format(datasource), u'test', u'ogr')
self.assertTrue(vl.isValid())
f = next(vl.getFeatures())
self.assertEqual(f.constGeometry().geometry().wkbType(), QgsWKBTypes.LineString)

# GPX with elevation data
datasource = os.path.join(TEST_DATA_DIR, 'elev.gpx')
vl = QgsVectorLayer(u'{}|layername=routes'.format(datasource), u'test', u'ogr')
self.assertTrue(vl.isValid())
f = next(vl.getFeatures())
self.assertEqual(f.constGeometry().geometry().wkbType(), QgsWKBTypes.LineString25D)
self.assertEqual(f.constGeometry().geometry().pointN(0).z(), 1)
self.assertEqual(f.constGeometry().geometry().pointN(1).z(), 2)
self.assertEqual(f.constGeometry().geometry().pointN(2).z(), 3)

if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<gpx version="1.1" creator="GDAL 1.11.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata><bounds minlat="56.134840267383296" minlon="-3.877982991747363" maxlat="56.135514185147493" maxlon="-3.852565020533009"/></metadata>
<rte>
<rtept lat="56.134840267383296" lon="-3.877982991747363">
<ele>1</ele>
</rtept>
<rtept lat="56.134933668432737" lon="-3.865962243986197">
<ele>2</ele>
</rtept>
<rtept lat="56.135514185147493" lon="-3.852565020533009">
<ele>3</ele>
</rtept>
</rte>
</gpx>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<gpx version="1.1" creator="GDAL 1.11.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata><bounds minlat="56.134840267383240" minlon="-3.877982991747359" maxlat="56.135514185147436" maxlon="-3.852565020533005"/></metadata>
<rte>
<rtept lat="56.13484026738324" lon="-3.877982991747359">
</rtept>
<rtept lat="56.13493366843268" lon="-3.865962243986193">
</rtept>
<rtept lat="56.135514185147436" lon="-3.852565020533005">
</rtept>
</rte>
</gpx>

0 comments on commit 4d8bb8b

Please sign in to comment.
You can’t perform that action at this time.