Skip to content

Commit

Permalink
flat geom (remove Z) if provider is 2D and geom is 3D + test
Browse files Browse the repository at this point in the history
  • Loading branch information
luipir committed Sep 26, 2017
1 parent 016363f commit 3264709
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,16 @@ QgsGeometry* QgsVectorDataProvider::convertToProviderType( const QgsGeometry* ge
outputGeom->addMValue();
}

// remove Z if provider does not have
if ( !QgsWKBTypes::hasZ( providerGeomType ) && QgsWKBTypes::hasZ( geometry->wkbType() ) )
{
if ( !outputGeom )
{
outputGeom = geometry->clone();
}
outputGeom->dropZValue();
}

if ( outputGeom )
{
return new QgsGeometry( outputGeom );
Expand Down
12 changes: 8 additions & 4 deletions tests/src/python/test_qgsvectorlayereditbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
QgsFeature,
QgsGeometry,
QgsPoint,
QgsField)
QgsField,
QgsWKBTypes,
QGis)
from qgis.testing import start_app, unittest
start_app()

Expand Down Expand Up @@ -100,11 +102,13 @@ def testAddFeatures(self):
[QgsPoint(1, 1), QgsPoint(2, 2)],
[QgsPoint(3, 3), QgsPoint(4, 4)],
]
geom = QgsGeometry.fromMultiPolyline(multiline)
f1 = QgsFeature(layer.fields(), 1)
f1.setGeometry(QgsGeometry.fromMultiPolyline(multiline))
f1.setGeometry(geom)
f1.setAttributes(["test", 123])
self.assertFalse(layer.addFeatures([f1]))
# self.assertFalse(layer.commitChanges())

self.assertTrue(QgsWKBTypes.isMultiType(QGis.fromOldWkbType(geom.wkbType())))
self.assertFalse((layer.editBuffer().addFeatures([f1])))

def testAddMultipleFeatures(self):
# test adding multiple features to an edit buffer
Expand Down

0 comments on commit 3264709

Please sign in to comment.