mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
Merge pull request #33021 from rouault/fx_writing_to_kml_with_gdal_3
QgsVectorFileWriter: fix axis order issue with GDAL 3 (fixes #33014)
This commit is contained in:
commit
a485b476c3
@ -398,6 +398,12 @@ void QgsVectorFileWriter::init( QString vectorFileName,
|
||||
QString srsWkt = srs.toWkt();
|
||||
QgsDebugMsg( "WKT to save as is " + srsWkt );
|
||||
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().constData() );
|
||||
#if GDAL_VERSION_MAJOR >= 3
|
||||
if ( mOgrRef )
|
||||
{
|
||||
OSRSetAxisMappingStrategy( mOgrRef, OAMS_TRADITIONAL_GIS_ORDER );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// datasource created, now create the output layer
|
||||
|
@ -1144,6 +1144,40 @@ class TestQgsVectorFileWriter(unittest.TestCase):
|
||||
del vl
|
||||
os.unlink(filename + '.gpkg')
|
||||
|
||||
def testWriteKMLAxisOrderIssueGDAL3(self):
|
||||
"""Check axis order issue when writing KML with EPSG:4326."""
|
||||
|
||||
if not ogr.GetDriverByName('KML'):
|
||||
return
|
||||
|
||||
vl = QgsVectorLayer(
|
||||
'PointZ?crs=epsg:4326&field=name:string(20)',
|
||||
'test',
|
||||
'memory')
|
||||
|
||||
self.assertTrue(vl.isValid(), 'Provider not initialized')
|
||||
|
||||
ft = QgsFeature()
|
||||
ft.setGeometry(QgsGeometry.fromWkt('Point(2 49)'))
|
||||
myResult, myFeatures = vl.dataProvider().addFeatures([ft])
|
||||
self.assertTrue(myResult)
|
||||
self.assertTrue(myFeatures)
|
||||
|
||||
dest_file_name = os.path.join(str(QDir.tempPath()), 'testWriteKMLAxisOrderIssueGDAL3.kml')
|
||||
write_result, error_message = QgsVectorFileWriter.writeAsVectorFormat(
|
||||
vl,
|
||||
dest_file_name,
|
||||
'utf-8',
|
||||
vl.crs(),
|
||||
'KML')
|
||||
self.assertEqual(write_result, QgsVectorFileWriter.NoError, error_message)
|
||||
|
||||
# Open result and check
|
||||
created_layer = QgsVectorLayer(dest_file_name, 'test', 'ogr')
|
||||
self.assertTrue(created_layer.isValid())
|
||||
f = next(created_layer.getFeatures(QgsFeatureRequest()))
|
||||
self.assertEqual(f.geometry().asWkt(), 'PointZ (2 49 0)')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user