-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Geometry] Fix various issues related to Wkb/Wkt import
- Make QgsCurvePolygonV2::fromWkb() accept CompoundCurveM sub-geometries - Make QgsGeometryCollectionV2::fromWkb() validate the sub-geometry type, so that QgsGeometryCollectionV2 subclasses do not import incompatible sub-geometries - Make QgsGeometryCollectionV2::fromWkt() accept curve sub-geometries - Make QgsMultiPolygonV2::addGeometry() accept only Polygon and not CurvePolygon - Add tests
- Loading branch information
Showing
4 changed files
with
73 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3304,6 +3304,62 @@ def testDeleteVertexCurvePolygon(self): | |
expected_wkt = "CurvePolygon (CompoundCurve (CircularString (0 0, 1 1, 2 0),(2 0, 0 0)))" | ||
self.assertEqual(geom.exportToWkt(), QgsGeometry.fromWkt(expected_wkt).exportToWkt()) | ||
|
||
def testMisc(self): | ||
|
||
# Test that we cannot add a CurvePolygon in a MultiPolygon | ||
multipolygon = QgsMultiPolygonV2() | ||
cp = QgsCurvePolygonV2() | ||
cp.fromWkt("CurvePolygon ((0 0,0 1,1 1,0 0))") | ||
assert not multipolygon.addGeometry( cp ) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rouault
Author
Contributor
|
||
|
||
# Test that importing an invalid WKB (a MultiPolygon with a CurvePolygon) fails | ||
geom = QgsGeometry.fromWkt('MultiSurface(((0 0,0 1,1 1,0 0)), CurvePolygon ((0 0,0 1,1 1,0 0)))') | ||
wkb = geom.asWkb() | ||
wkb = bytearray(wkb) | ||
if wkb[1] == QgsWKBTypes.MultiSurface: | ||
wkb[1] = QgsWKBTypes.MultiPolygon | ||
elif wkb[1+4] == QgsWKBTypes.MultiSurface: | ||
wkb[1+4] = QgsWKBTypes.MultiPolygon | ||
else: | ||
self.assertTrue(False) | ||
geom = QgsGeometry() | ||
geom.fromWkb(wkb) | ||
self.assertEqual(geom.exportToWkt(), QgsMultiPolygonV2().asWkt()) | ||
|
||
# Test that fromWkt() on a GeometryCollection works with all possible geometries | ||
wkt = "GeometryCollection( " | ||
wkt += "Point(0 1)" | ||
wkt += "," | ||
wkt += "LineString(0 0,0 1)" | ||
wkt += "," | ||
wkt += "Polygon ((0 0,1 1,1 0,0 0))" | ||
wkt += "," | ||
wkt += "CurvePolygon ((0 0,1 1,1 0,0 0))" | ||
wkt += "," | ||
wkt += "CircularString (0 0,1 1,2 0)" | ||
wkt += "," | ||
wkt += "CompoundCurve ((0 0,0 1))" | ||
wkt += "," | ||
wkt += "MultiPoint ((0 0))" | ||
wkt += "," | ||
wkt += "MultiLineString((0 0,0 1))" | ||
wkt += "," | ||
wkt += "MultiCurve((0 0,0 1))" | ||
wkt += "," | ||
wkt += "MultiPolygon (((0 0,1 1,1 0,0 0)))" | ||
wkt += "," | ||
wkt += "MultiSurface (((0 0,1 1,1 0,0 0)))" | ||
wkt += "," | ||
wkt += "GeometryCollection (Point(0 0))" | ||
wkt += ")" | ||
geom = QgsGeometry.fromWkt(wkt) | ||
assert geom is not None | ||
wkb1 = geom.asWkb() | ||
geom = QgsGeometry() | ||
geom.fromWkb(wkb1) | ||
wkb2 = geom.asWkb() | ||
self.assertEqual(wkb1, wkb2) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
@rouault can you explain why we cannot add a curve polygon to a multi polygon?
How would you do with add part map tool then?