From c50ee6d42f53fe06b7c4cedd996a3d4aed338641 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 25 Oct 2017 17:48:19 +1000 Subject: [PATCH] Update python code to new API --- .../algs/qgis/EliminateSelection.py | 4 +- .../plugins/processing/algs/qgis/Explode.py | 6 +- .../algs/qgis/ExportGeometryInfo.py | 2 +- .../processing/algs/qgis/ExtractNodes.py | 2 +- .../algs/qgis/ExtractSpecificNodes.py | 2 +- .../processing/algs/qgis/FindProjection.py | 4 +- .../processing/algs/qgis/GeometryConvert.py | 18 +-- .../processing/algs/qgis/Intersection.py | 6 +- .../processing/algs/qgis/LinesToPolygons.py | 2 +- .../algs/qgis/MinimumBoundingGeometry.py | 6 +- .../algs/qgis/PointsAlongGeometry.py | 2 +- .../algs/qgis/PointsDisplacement.py | 2 +- .../algs/qgis/PointsFromPolygons.py | 2 +- .../processing/algs/qgis/PointsInPolygon.py | 4 +- .../processing/algs/qgis/PointsToPaths.py | 2 +- .../processing/algs/qgis/Polygonize.py | 6 +- .../processing/algs/qgis/PolygonsToLines.py | 2 +- .../processing/algs/qgis/RegularPoints.py | 4 +- .../algs/qgis/ReverseLineDirection.py | 2 +- .../plugins/processing/algs/qgis/SetMValue.py | 2 +- .../plugins/processing/algs/qgis/SetZValue.py | 2 +- .../processing/algs/qgis/SpatialJoin.py | 4 +- .../algs/qgis/SpatialJoinSummary.py | 4 +- .../plugins/processing/algs/qgis/SumLines.py | 4 +- .../processing/algs/qgis/TopoColors.py | 8 +- python/plugins/processing/algs/qgis/Union.py | 12 +- tests/src/python/featuresourcetestbase.py | 24 ++-- tests/src/python/test_provider_ogr.py | 12 +- tests/src/python/test_provider_shapefile.py | 4 +- tests/src/python/test_provider_wfs.py | 20 ++-- tests/src/python/test_qgsfillsymbollayers.py | 2 +- tests/src/python/test_qgsgeometry.py | 104 +++++++++--------- tests/src/python/test_qgsjsonutils.py | 6 +- tests/src/python/test_qgslinesymbollayers.py | 2 +- tests/src/python/test_qgssymbol.py | 8 +- tests/src/python/test_qgssymbollayer.py | 4 +- tests/src/python/test_qgsvectorlayer.py | 8 +- .../python/test_qgsvectorlayereditbuffer.py | 6 +- tests/testdata/polys_overlapping_with_id.dbf | Bin 1329 -> 1329 bytes 39 files changed, 157 insertions(+), 157 deletions(-) diff --git a/python/plugins/processing/algs/qgis/EliminateSelection.py b/python/plugins/processing/algs/qgis/EliminateSelection.py index d03a9c8dc13..144a4604110 100644 --- a/python/plugins/processing/algs/qgis/EliminateSelection.py +++ b/python/plugins/processing/algs/qgis/EliminateSelection.py @@ -147,7 +147,7 @@ class EliminateSelection(QgisAlgorithm): selFeat = QgsFeature() # use prepared geometries for faster intersection tests - engine = QgsGeometry.createGeometryEngine(geom2Eliminate.geometry()) + engine = QgsGeometry.createGeometryEngine(geom2Eliminate.constGet()) engine.prepareGeometry() while fit.nextFeature(selFeat): @@ -156,7 +156,7 @@ class EliminateSelection(QgisAlgorithm): selGeom = selFeat.geometry() - if engine.intersects(selGeom.geometry()): + if engine.intersects(selGeom.constGet()): # We have a candidate iGeom = geom2Eliminate.intersection(selGeom) diff --git a/python/plugins/processing/algs/qgis/Explode.py b/python/plugins/processing/algs/qgis/Explode.py index 2af46588f21..de7b511f0ae 100644 --- a/python/plugins/processing/algs/qgis/Explode.py +++ b/python/plugins/processing/algs/qgis/Explode.py @@ -89,11 +89,11 @@ class Explode(QgisAlgorithm): def extractAsSingleSegments(self, geom): segments = [] if geom.isMultipart(): - for part in range(geom.geometry().numGeometries()): - segments.extend(self.getPolylineAsSingleSegments(geom.geometry().geometryN(part))) + for part in range(geom.constGet().numGeometries()): + segments.extend(self.getPolylineAsSingleSegments(geom.constGet().geometryN(part))) else: segments.extend(self.getPolylineAsSingleSegments( - geom.geometry())) + geom.constGet())) return segments def getPolylineAsSingleSegments(self, polyline): diff --git a/python/plugins/processing/algs/qgis/ExportGeometryInfo.py b/python/plugins/processing/algs/qgis/ExportGeometryInfo.py index cedbaabffcc..7bfd7ed86cc 100644 --- a/python/plugins/processing/algs/qgis/ExportGeometryInfo.py +++ b/python/plugins/processing/algs/qgis/ExportGeometryInfo.py @@ -155,7 +155,7 @@ class ExportGeometryInfo(QgisAlgorithm): def point_attributes(self, geometry): pt = None if not geometry.isMultipart(): - pt = geometry.geometry() + pt = geometry.constGet() else: if geometry.numGeometries() > 0: pt = geometry.geometryN(0) diff --git a/python/plugins/processing/algs/qgis/ExtractNodes.py b/python/plugins/processing/algs/qgis/ExtractNodes.py index b081f09e066..436e4c025e2 100644 --- a/python/plugins/processing/algs/qgis/ExtractNodes.py +++ b/python/plugins/processing/algs/qgis/ExtractNodes.py @@ -99,7 +99,7 @@ class ExtractNodes(QgisAlgorithm): sink.addFeature(f, QgsFeatureSink.FastInsert) else: i = 0 - for part in input_geometry.geometry().coordinateSequence(): + for part in input_geometry.constGet().coordinateSequence(): for ring in part: if feedback.isCanceled(): break diff --git a/python/plugins/processing/algs/qgis/ExtractSpecificNodes.py b/python/plugins/processing/algs/qgis/ExtractSpecificNodes.py index 4e9e9c8d3a6..6dec5a074ca 100644 --- a/python/plugins/processing/algs/qgis/ExtractSpecificNodes.py +++ b/python/plugins/processing/algs/qgis/ExtractSpecificNodes.py @@ -104,7 +104,7 @@ class ExtractSpecificNodes(QgisAlgorithm): if not input_geometry: sink.addFeature(f, QgsFeatureSink.FastInsert) else: - total_nodes = input_geometry.geometry().nCoordinates() + total_nodes = input_geometry.constGet().nCoordinates() for node in indices: if node < 0: diff --git a/python/plugins/processing/algs/qgis/FindProjection.py b/python/plugins/processing/algs/qgis/FindProjection.py index 5f4049fad47..7b04a720598 100644 --- a/python/plugins/processing/algs/qgis/FindProjection.py +++ b/python/plugins/processing/algs/qgis/FindProjection.py @@ -95,7 +95,7 @@ class FindProjection(QgisAlgorithm): fields, QgsWkbTypes.NoGeometry, QgsCoordinateReferenceSystem()) # make intersection tests nice and fast - engine = QgsGeometry.createGeometryEngine(target_geom.geometry()) + engine = QgsGeometry.createGeometryEngine(target_geom.constGet()) engine.prepareGeometry() layer_bounds = QgsGeometry.fromRect(source.sourceExtent()) @@ -121,7 +121,7 @@ class FindProjection(QgisAlgorithm): except: continue - if engine.intersects(transformed_bounds.geometry()): + if engine.intersects(transformed_bounds.constGet()): feedback.pushInfo(self.tr('Found candidate CRS: {}').format(candidate_crs.authid())) f = QgsFeature(fields) f.setAttributes([candidate_crs.authid()]) diff --git a/python/plugins/processing/algs/qgis/GeometryConvert.py b/python/plugins/processing/algs/qgis/GeometryConvert.py index 0d9c6247b5b..3fd007549f9 100644 --- a/python/plugins/processing/algs/qgis/GeometryConvert.py +++ b/python/plugins/processing/algs/qgis/GeometryConvert.py @@ -151,7 +151,7 @@ class GeometryConvert(QgisAlgorithm): mp = QgsMultiPointV2() # TODO: mega inefficient - needs rework when geometry iterators land # (but at least it doesn't lose Z/M values) - for g in geom.geometry().coordinateSequence(): + for g in geom.constGet().coordinateSequence(): for r in g: for p in r: mp.addGeometry(p) @@ -170,7 +170,7 @@ class GeometryConvert(QgisAlgorithm): else: # polygons to lines # we just use the boundary here - that consists of all rings in the (multi)polygon - boundary = QgsGeometry(geom.geometry().boundary()) + boundary = QgsGeometry(geom.constGet().boundary()) # boundary will be multipart return boundary.asGeometryCollection() @@ -184,15 +184,15 @@ class GeometryConvert(QgisAlgorithm): else: # line to multiLine ml = QgsMultiLineString() - ml.addGeometry(geom.geometry().clone()) + ml.addGeometry(geom.constGet().clone()) return [QgsGeometry(ml)] else: # polygons to multilinestring # we just use the boundary here - that consists of all rings in the (multi)polygon - return [QgsGeometry(geom.geometry().boundary())] + return [QgsGeometry(geom.constGet().boundary())] def convertToPolygon(self, geom): - if QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.PointGeometry and geom.geometry().nCoordinates() < 3: + if QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.PointGeometry and geom.constGet().nCoordinates() < 3: raise QgsProcessingException( self.tr('Cannot convert from Point to Polygon').format(QgsWkbTypes.displayString(geom.wkbType()))) elif QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.PointGeometry: @@ -200,7 +200,7 @@ class GeometryConvert(QgisAlgorithm): # TODO: mega inefficient - needs rework when geometry iterators land # (but at least it doesn't lose Z/M values) points = [] - for g in geom.geometry().coordinateSequence(): + for g in geom.constGet().coordinateSequence(): for r in g: for p in r: points.append(p) @@ -212,9 +212,9 @@ class GeometryConvert(QgisAlgorithm): elif QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.LineGeometry: if QgsWkbTypes.isMultiType(geom): parts = [] - for i in range(geom.geometry().numGeometries()): + for i in range(geom.constGet().numGeometries()): p = QgsPolygonV2() - linestring = geom.geometry().geometryN(i).clone() + linestring = geom.constGet().geometryN(i).clone() linestring.close() p.setExteriorRing(linestring) parts.append(QgsGeometry(p)) @@ -222,7 +222,7 @@ class GeometryConvert(QgisAlgorithm): else: # linestring to polygon p = QgsPolygonV2() - linestring = geom.geometry().clone() + linestring = geom.constGet().clone() linestring.close() p.setExteriorRing(linestring) return [QgsGeometry(p)] diff --git a/python/plugins/processing/algs/qgis/Intersection.py b/python/plugins/processing/algs/qgis/Intersection.py index ce5ed7974d9..379fbf9143d 100644 --- a/python/plugins/processing/algs/qgis/Intersection.py +++ b/python/plugins/processing/algs/qgis/Intersection.py @@ -152,7 +152,7 @@ class Intersection(QgisAlgorithm): engine = None if len(intersects) > 0: # use prepared geometries for faster intersection tests - engine = QgsGeometry.createGeometryEngine(geom.geometry()) + engine = QgsGeometry.createGeometryEngine(geom.constGet()) engine.prepareGeometry() for featB in sourceB.getFeatures(request): @@ -160,11 +160,11 @@ class Intersection(QgisAlgorithm): break tmpGeom = featB.geometry() - if engine.intersects(tmpGeom.geometry()): + if engine.intersects(tmpGeom.constGet()): out_attributes = [featA.attributes()[i] for i in field_indices_a] out_attributes.extend([featB.attributes()[i] for i in field_indices_b]) int_geom = QgsGeometry(geom.intersection(tmpGeom)) - if int_geom.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(int_geom.geometry().wkbType()) == QgsWkbTypes.GeometryCollection: + if int_geom.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(int_geom.wkbType()) == QgsWkbTypes.GeometryCollection: int_com = geom.combine(tmpGeom) int_geom = QgsGeometry() if int_com: diff --git a/python/plugins/processing/algs/qgis/LinesToPolygons.py b/python/plugins/processing/algs/qgis/LinesToPolygons.py index 8d58d59e8e7..3c6ac280eeb 100644 --- a/python/plugins/processing/algs/qgis/LinesToPolygons.py +++ b/python/plugins/processing/algs/qgis/LinesToPolygons.py @@ -101,7 +101,7 @@ class LinesToPolygons(QgisFeatureBasedAlgorithm): return multi_wkb def convertToPolygons(self, geometry): - surfaces = self.getSurfaces(geometry.geometry()) + surfaces = self.getSurfaces(geometry.constGet()) output_wkb = self.convertWkbToPolygons(geometry.wkbType()) out_geom = None if QgsWkbTypes.flatType(output_wkb) == QgsWkbTypes.MultiPolygon: diff --git a/python/plugins/processing/algs/qgis/MinimumBoundingGeometry.py b/python/plugins/processing/algs/qgis/MinimumBoundingGeometry.py index a759a503ff8..13a7df2fd84 100644 --- a/python/plugins/processing/algs/qgis/MinimumBoundingGeometry.py +++ b/python/plugins/processing/algs/qgis/MinimumBoundingGeometry.py @@ -238,7 +238,7 @@ class MinimumBoundingGeometry(QgisAlgorithm): while True: if feedback.isCanceled(): break - found, point = g.geometry().nextVertex(vid) + found, point = g.constGet().nextVertex(vid) if found: multi_point.addGeometry(point) else: @@ -270,8 +270,8 @@ class MinimumBoundingGeometry(QgisAlgorithm): elif type == 3: # convex hull output_geometry = geometry.convexHull() - attrs.append(output_geometry.geometry().area()) - attrs.append(output_geometry.geometry().perimeter()) + attrs.append(output_geometry.constGet().area()) + attrs.append(output_geometry.constGet().perimeter()) f = QgsFeature() f.setAttributes(attrs) f.setGeometry(output_geometry) diff --git a/python/plugins/processing/algs/qgis/PointsAlongGeometry.py b/python/plugins/processing/algs/qgis/PointsAlongGeometry.py index 886149fa68f..2874cd6d57b 100644 --- a/python/plugins/processing/algs/qgis/PointsAlongGeometry.py +++ b/python/plugins/processing/algs/qgis/PointsAlongGeometry.py @@ -108,7 +108,7 @@ class PointsAlongGeometry(QgisAlgorithm): sink.addFeature(input_feature, QgsFeatureSink.FastInsert) else: if input_geometry.type == QgsWkbTypes.PolygonGeometry: - length = input_geometry.geometry().perimeter() + length = input_geometry.constGet().perimeter() else: length = input_geometry.length() - end_offset current_distance = start_offset diff --git a/python/plugins/processing/algs/qgis/PointsDisplacement.py b/python/plugins/processing/algs/qgis/PointsDisplacement.py index fbbf5c515df..92a31027363 100644 --- a/python/plugins/processing/algs/qgis/PointsDisplacement.py +++ b/python/plugins/processing/algs/qgis/PointsDisplacement.py @@ -169,7 +169,7 @@ class PointsDisplacement(QgisAlgorithm): dy = radius * cosinusCurrentAngle # we want to keep any existing m/z values - point = f.geometry().geometry().clone() + point = f.geometry().constGet().clone() point.setX(old_point.x() + dx) point.setY(old_point.y() + dy) f.setGeometry(QgsGeometry(point)) diff --git a/python/plugins/processing/algs/qgis/PointsFromPolygons.py b/python/plugins/processing/algs/qgis/PointsFromPolygons.py index 513d4016d3a..c3b204bc7f4 100644 --- a/python/plugins/processing/algs/qgis/PointsFromPolygons.py +++ b/python/plugins/processing/algs/qgis/PointsFromPolygons.py @@ -117,7 +117,7 @@ class PointsFromPolygons(QgisAlgorithm): (endRow, endColumn) = raster.mapToPixel(xMax, yMin, geoTransform) # use prepared geometries for faster intersection tests - engine = QgsGeometry.createGeometryEngine(geom.geometry()) + engine = QgsGeometry.createGeometryEngine(geom.constGet()) engine.prepareGeometry() for row in range(startRow, endRow + 1): diff --git a/python/plugins/processing/algs/qgis/PointsInPolygon.py b/python/plugins/processing/algs/qgis/PointsInPolygon.py index d43d0db7760..869042b4763 100644 --- a/python/plugins/processing/algs/qgis/PointsInPolygon.py +++ b/python/plugins/processing/algs/qgis/PointsInPolygon.py @@ -129,7 +129,7 @@ class PointsInPolygon(QgisAlgorithm): output_feature = QgsFeature() if polygon_feature.hasGeometry(): geom = polygon_feature.geometry() - engine = QgsGeometry.createGeometryEngine(geom.geometry()) + engine = QgsGeometry.createGeometryEngine(geom.constGet()) engine.prepareGeometry() count = 0 @@ -143,7 +143,7 @@ class PointsInPolygon(QgisAlgorithm): if feedback.isCanceled(): break - if engine.contains(point_feature.geometry().geometry()): + if engine.contains(point_feature.geometry().constGet()): if weight_field_index >= 0: weight = point_feature.attributes()[weight_field_index] try: diff --git a/python/plugins/processing/algs/qgis/PointsToPaths.py b/python/plugins/processing/algs/qgis/PointsToPaths.py index 85a2f180741..decfadfd9ea 100644 --- a/python/plugins/processing/algs/qgis/PointsToPaths.py +++ b/python/plugins/processing/algs/qgis/PointsToPaths.py @@ -133,7 +133,7 @@ class PointsToPaths(QgisAlgorithm): if not f.hasGeometry(): continue - point = f.geometry().geometry().clone() + point = f.geometry().constGet().clone() if group_field_index >= 0: group = f.attributes()[group_field_index] else: diff --git a/python/plugins/processing/algs/qgis/Polygonize.py b/python/plugins/processing/algs/qgis/Polygonize.py index 8f93b754d5e..a2f1e769169 100644 --- a/python/plugins/processing/algs/qgis/Polygonize.py +++ b/python/plugins/processing/algs/qgis/Polygonize.py @@ -104,13 +104,13 @@ class Polygonize(QgisAlgorithm): if not polygons.isEmpty(): feedback.pushInfo('Saving polygons...') - total = 50.0 / polygons.geometry().numGeometries() - for i in range(polygons.geometry().numGeometries()): + total = 50.0 / polygons.constGet().numGeometries() + for i in range(polygons.constGet().numGeometries()): if feedback.isCanceled(): break outFeat = QgsFeature() - geom = QgsGeometry(polygons.geometry().geometryN(i).clone()) + geom = QgsGeometry(polygons.constGet().geometryN(i).clone()) outFeat.setGeometry(geom) sink.addFeature(outFeat, QgsFeatureSink.FastInsert) feedback.setProgress(50 + int(current * total)) diff --git a/python/plugins/processing/algs/qgis/PolygonsToLines.py b/python/plugins/processing/algs/qgis/PolygonsToLines.py index a19ffd3cbac..0b6d7098222 100644 --- a/python/plugins/processing/algs/qgis/PolygonsToLines.py +++ b/python/plugins/processing/algs/qgis/PolygonsToLines.py @@ -92,7 +92,7 @@ class PolygonsToLines(QgisFeatureBasedAlgorithm): return multi_wkb def convertToLines(self, geometry): - rings = self.getRings(geometry.geometry()) + rings = self.getRings(geometry.constGet()) output_wkb = self.convertWkbToLines(geometry.wkbType()) out_geom = None if QgsWkbTypes.flatType(output_wkb) == QgsWkbTypes.MultiLineString: diff --git a/python/plugins/processing/algs/qgis/RegularPoints.py b/python/plugins/processing/algs/qgis/RegularPoints.py index 7e0be212ac8..84bce72462e 100644 --- a/python/plugins/processing/algs/qgis/RegularPoints.py +++ b/python/plugins/processing/algs/qgis/RegularPoints.py @@ -124,7 +124,7 @@ class RegularPoints(QgisAlgorithm): y = extent.yMaximum() - inset extent_geom = QgsGeometry.fromRect(extent) - extent_engine = QgsGeometry.createGeometryEngine(extent_geom.geometry()) + extent_engine = QgsGeometry.createGeometryEngine(extent_geom.constGet()) extent_engine.prepareGeometry() while y >= extent.yMinimum(): @@ -140,7 +140,7 @@ class RegularPoints(QgisAlgorithm): else: geom = QgsGeometry().fromPoint(QgsPointXY(x, y)) - if extent_engine.intersects(geom.geometry()): + if extent_engine.intersects(geom.constGet()): f.setAttribute('id', count) f.setGeometry(geom) sink.addFeature(f, QgsFeatureSink.FastInsert) diff --git a/python/plugins/processing/algs/qgis/ReverseLineDirection.py b/python/plugins/processing/algs/qgis/ReverseLineDirection.py index 695a870f1e5..41946d039ac 100644 --- a/python/plugins/processing/algs/qgis/ReverseLineDirection.py +++ b/python/plugins/processing/algs/qgis/ReverseLineDirection.py @@ -57,7 +57,7 @@ class ReverseLineDirection(QgisFeatureBasedAlgorithm): def processFeature(self, feature, feedback): if feature.geometry(): inGeom = feature.geometry() - reversedLine = inGeom.geometry().reversed() + reversedLine = inGeom.constGet().reversed() if not reversedLine: raise QgsProcessingException( self.tr('Error reversing line')) diff --git a/python/plugins/processing/algs/qgis/SetMValue.py b/python/plugins/processing/algs/qgis/SetMValue.py index 5499622a274..3beeb90e492 100644 --- a/python/plugins/processing/algs/qgis/SetMValue.py +++ b/python/plugins/processing/algs/qgis/SetMValue.py @@ -74,7 +74,7 @@ class SetMValue(QgisFeatureBasedAlgorithm): def processFeature(self, feature, feedback): input_geometry = feature.geometry() if input_geometry: - new_geom = input_geometry.geometry().clone() + new_geom = input_geometry.constGet().clone() if QgsWkbTypes.hasM(new_geom.wkbType()): # addMValue won't alter existing M values, so drop them first new_geom.dropMValue() diff --git a/python/plugins/processing/algs/qgis/SetZValue.py b/python/plugins/processing/algs/qgis/SetZValue.py index 81c7a9198ba..afd42cb2a7a 100644 --- a/python/plugins/processing/algs/qgis/SetZValue.py +++ b/python/plugins/processing/algs/qgis/SetZValue.py @@ -74,7 +74,7 @@ class SetZValue(QgisFeatureBasedAlgorithm): def processFeature(self, feature, feedback): input_geometry = feature.geometry() if input_geometry: - new_geom = input_geometry.geometry().clone() + new_geom = input_geometry.constGet().clone() if QgsWkbTypes.hasZ(new_geom.wkbType()): # addZValue won't alter existing Z values, so drop them first new_geom.dropZValue() diff --git a/python/plugins/processing/algs/qgis/SpatialJoin.py b/python/plugins/processing/algs/qgis/SpatialJoin.py index d51b6004837..613e2a55715 100644 --- a/python/plugins/processing/algs/qgis/SpatialJoin.py +++ b/python/plugins/processing/algs/qgis/SpatialJoin.py @@ -195,11 +195,11 @@ class SpatialJoin(QgisAlgorithm): join_attributes.append(f.attributes()[a]) if engine is None: - engine = QgsGeometry.createGeometryEngine(f.geometry().geometry()) + engine = QgsGeometry.createGeometryEngine(f.geometry().constGet()) engine.prepareGeometry() for predicate in predicates: - if getattr(engine, predicate)(test_feat.geometry().geometry()): + if getattr(engine, predicate)(test_feat.geometry().constGet()): added_set.add(test_feat.id()) # join attributes and add diff --git a/python/plugins/processing/algs/qgis/SpatialJoinSummary.py b/python/plugins/processing/algs/qgis/SpatialJoinSummary.py index e8f4ed17c66..9f6c20af962 100644 --- a/python/plugins/processing/algs/qgis/SpatialJoinSummary.py +++ b/python/plugins/processing/algs/qgis/SpatialJoinSummary.py @@ -286,11 +286,11 @@ class SpatialJoinSummary(QgisAlgorithm): join_attributes.append(test_feat.attributes()[a]) if engine is None: - engine = QgsGeometry.createGeometryEngine(f.geometry().geometry()) + engine = QgsGeometry.createGeometryEngine(f.geometry().constGet()) engine.prepareGeometry() for predicate in predicates: - if getattr(engine, predicate)(test_feat.geometry().geometry()): + if getattr(engine, predicate)(test_feat.geometry().constGet()): values.append(join_attributes) break diff --git a/python/plugins/processing/algs/qgis/SumLines.py b/python/plugins/processing/algs/qgis/SumLines.py index 8d9fcc8a468..c5f6fc162d7 100644 --- a/python/plugins/processing/algs/qgis/SumLines.py +++ b/python/plugins/processing/algs/qgis/SumLines.py @@ -124,7 +124,7 @@ class SumLines(QgisAlgorithm): if len(lines) > 0: has_intersections = True # use prepared geometries for faster intersection tests - engine = QgsGeometry.createGeometryEngine(poly_geom.geometry()) + engine = QgsGeometry.createGeometryEngine(poly_geom.constGet()) engine.prepareGeometry() if has_intersections: @@ -133,7 +133,7 @@ class SumLines(QgisAlgorithm): if feedback.isCanceled(): break - if engine.intersects(line_feature.geometry().geometry()): + if engine.intersects(line_feature.geometry().constGet()): outGeom = poly_geom.intersection(line_feature.geometry()) length += distArea.measureLength(outGeom) count += 1 diff --git a/python/plugins/processing/algs/qgis/TopoColors.py b/python/plugins/processing/algs/qgis/TopoColors.py index 32f2bc20d53..8319185c291 100644 --- a/python/plugins/processing/algs/qgis/TopoColors.py +++ b/python/plugins/processing/algs/qgis/TopoColors.py @@ -161,7 +161,7 @@ class TopoColor(QgisAlgorithm): if min_distance > 0: g = g.buffer(min_distance, 5) - engine = QgsGeometry.createGeometryEngine(g.geometry()) + engine = QgsGeometry.createGeometryEngine(g.constGet()) engine.prepareGeometry() feature_bounds = g.boundingBox() @@ -170,7 +170,7 @@ class TopoColor(QgisAlgorithm): intersections = index.intersects(feature_bounds) for l2 in intersections: f2 = features_with_geometry[l2] - if engine.intersects(f2.geometry().geometry()): + if engine.intersects(f2.geometry().constGet()): s.add_edge(f.id(), f2.id()) s.add_edge(f2.id(), f.id()) if id_graph: @@ -247,7 +247,7 @@ class ColoringAlgorithm: color_areas[feature_color] += features[feature_id].geometry().area() elif balance == 2: min_distances = {c: sys.float_info.max for c in available_colors} - this_feature_centroid = features[feature_id].geometry().centroid().geometry() + this_feature_centroid = features[feature_id].geometry().centroid().constGet() # find features for all available colors other_features = {f_id: c for (f_id, c) in feature_colors.items() if c in available_colors} @@ -259,7 +259,7 @@ class ColoringAlgorithm: break other_geometry = features[other_feature_id].geometry() - other_centroid = other_geometry.centroid().geometry() + other_centroid = other_geometry.centroid().constGet() distance = this_feature_centroid.distanceSquared(other_centroid) if distance < min_distances[c]: diff --git a/python/plugins/processing/algs/qgis/Union.py b/python/plugins/processing/algs/qgis/Union.py index 19d344d9c66..dc211285ad9 100644 --- a/python/plugins/processing/algs/qgis/Union.py +++ b/python/plugins/processing/algs/qgis/Union.py @@ -116,14 +116,14 @@ class Union(QgisAlgorithm): request = QgsFeatureRequest().setFilterFids(intersects).setSubsetOfAttributes([]) request.setDestinationCrs(sourceA.sourceCrs()) - engine = QgsGeometry.createGeometryEngine(geom.geometry()) + engine = QgsGeometry.createGeometryEngine(geom.constGet()) engine.prepareGeometry() for featB in sourceB.getFeatures(request): atMapB = featB.attributes() tmpGeom = featB.geometry() - if engine.intersects(tmpGeom.geometry()): + if engine.intersects(tmpGeom.constGet()): int_geom = geom.intersection(tmpGeom) lstIntersectingB.append(tmpGeom) @@ -134,7 +134,7 @@ class Union(QgisAlgorithm): else: int_geom = QgsGeometry(int_geom) - if int_geom.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(int_geom.geometry().wkbType()) == QgsWkbTypes.GeometryCollection: + if int_geom.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(int_geom.wkbType()) == QgsWkbTypes.GeometryCollection: # Intersection produced different geomety types temp_list = int_geom.asGeometryCollection() for i in temp_list: @@ -168,7 +168,7 @@ class Union(QgisAlgorithm): intB = QgsGeometry.unaryUnion(lstIntersectingB) diff_geom = diff_geom.difference(intB) - if diff_geom.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(diff_geom.geometry().wkbType()) == QgsWkbTypes.GeometryCollection: + if diff_geom.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(diff_geom.wkbType()) == QgsWkbTypes.GeometryCollection: temp_list = diff_geom.asGeometryCollection() for i in temp_list: if i.type() == geom.type(): @@ -211,14 +211,14 @@ class Union(QgisAlgorithm): request.setDestinationCrs(sourceA.sourceCrs()) # use prepared geometries for faster intersection tests - engine = QgsGeometry.createGeometryEngine(diff_geom.geometry()) + engine = QgsGeometry.createGeometryEngine(diff_geom.constGet.ge()) engine.prepareGeometry() for featB in sourceA.getFeatures(request): atMapB = featB.attributes() tmpGeom = featB.geometry() - if engine.intersects(tmpGeom.geometry()): + if engine.intersects(tmpGeom.constGet()): add = True diff_geom = QgsGeometry(diff_geom.difference(tmpGeom)) else: diff --git a/tests/src/python/featuresourcetestbase.py b/tests/src/python/featuresourcetestbase.py index ff9f19fafd1..6ef4b7a7443 100644 --- a/tests/src/python/featuresourcetestbase.py +++ b/tests/src/python/featuresourcetestbase.py @@ -512,15 +512,15 @@ class FeatureSourceTestCase(object): request = QgsFeatureRequest().setDestinationCrs(QgsCoordinateReferenceSystem('epsg:3785')) features = {f['pk']: f for f in self.source.getFeatures(request)} # test that features have been reprojected - self.assertAlmostEqual(features[1].geometry().geometry().x(), -7829322, -5) - self.assertAlmostEqual(features[1].geometry().geometry().y(), 9967753, -5) - self.assertAlmostEqual(features[2].geometry().geometry().x(), -7591989, -5) - self.assertAlmostEqual(features[2].geometry().geometry().y(), 11334232, -5) + self.assertAlmostEqual(features[1].geometry().constGet().x(), -7829322, -5) + self.assertAlmostEqual(features[1].geometry().constGet().y(), 9967753, -5) + self.assertAlmostEqual(features[2].geometry().constGet().x(), -7591989, -5) + self.assertAlmostEqual(features[2].geometry().constGet().y(), 11334232, -5) self.assertFalse(features[3].hasGeometry()) - self.assertAlmostEqual(features[4].geometry().geometry().x(), -7271389, -5) - self.assertAlmostEqual(features[4].geometry().geometry().y(), 14531322, -5) - self.assertAlmostEqual(features[5].geometry().geometry().x(), -7917376, -5) - self.assertAlmostEqual(features[5].geometry().geometry().y(), 14493008, -5) + self.assertAlmostEqual(features[4].geometry().constGet().x(), -7271389, -5) + self.assertAlmostEqual(features[4].geometry().constGet().y(), 14531322, -5) + self.assertAlmostEqual(features[5].geometry().constGet().x(), -7917376, -5) + self.assertAlmostEqual(features[5].geometry().constGet().y(), 14493008, -5) # when destination crs is set, filter rect should be in destination crs rect = QgsRectangle(-7650000, 10500000, -7200000, 15000000) @@ -528,10 +528,10 @@ class FeatureSourceTestCase(object): features = {f['pk']: f for f in self.source.getFeatures(request)} self.assertEqual(set(features.keys()), {2, 4}) # test that features have been reprojected - self.assertAlmostEqual(features[2].geometry().geometry().x(), -7591989, -5) - self.assertAlmostEqual(features[2].geometry().geometry().y(), 11334232, -5) - self.assertAlmostEqual(features[4].geometry().geometry().x(), -7271389, -5) - self.assertAlmostEqual(features[4].geometry().geometry().y(), 14531322, -5) + self.assertAlmostEqual(features[2].geometry().constGet().x(), -7591989, -5) + self.assertAlmostEqual(features[2].geometry().constGet().y(), 11334232, -5) + self.assertAlmostEqual(features[4].geometry().constGet().x(), -7271389, -5) + self.assertAlmostEqual(features[4].geometry().constGet().y(), 14531322, -5) # bad rect for transform rect = QgsRectangle(-99999999999, 99999999999, -99999999998, 99999999998) diff --git a/tests/src/python/test_provider_ogr.py b/tests/src/python/test_provider_ogr.py index 20b4cec79f1..bedfe5ed9d9 100644 --- a/tests/src/python/test_provider_ogr.py +++ b/tests/src/python/test_provider_ogr.py @@ -136,17 +136,17 @@ class PyQgsOGRProvider(unittest.TestCase): vl = QgsVectorLayer('{}|layername=routes'.format(datasource), 'test', 'ogr') self.assertTrue(vl.isValid()) f = next(vl.getFeatures()) - self.assertEqual(f.geometry().geometry().wkbType(), QgsWkbTypes.LineString) + self.assertEqual(f.geometry().wkbType(), QgsWkbTypes.LineString) # GPX with elevation data datasource = os.path.join(TEST_DATA_DIR, 'elev.gpx') vl = QgsVectorLayer('{}|layername=routes'.format(datasource), 'test', 'ogr') self.assertTrue(vl.isValid()) f = next(vl.getFeatures()) - self.assertEqual(f.geometry().geometry().wkbType(), QgsWkbTypes.LineString25D) - self.assertEqual(f.geometry().geometry().pointN(0).z(), 1) - self.assertEqual(f.geometry().geometry().pointN(1).z(), 2) - self.assertEqual(f.geometry().geometry().pointN(2).z(), 3) + self.assertEqual(f.geometry().wkbType(), QgsWkbTypes.LineString25D) + self.assertEqual(f.geometry().constGet().pointN(0).z(), 1) + self.assertEqual(f.geometry().constGet().pointN(1).z(), 2) + self.assertEqual(f.geometry().constGet().pointN(2).z(), 3) def testNoDanglingFileDescriptorAfterCloseVariant1(self): ''' Test that when closing the provider all file handles are released ''' @@ -286,7 +286,7 @@ class PyQgsOGRProvider(unittest.TestCase): f = QgsFeature() self.assertTrue(vl.getFeatures(QgsFeatureRequest(1)).nextFeature(f)) self.assertTrue(f.geometry()) - self.assertEqual(f.geometry().geometry().asWkt(), row[2]) + self.assertEqual(f.geometry().constGet().asWkt(), row[2]) """PolyhedralSurface, Tin => mapped to MultiPolygon Triangle => mapped to Polygon diff --git a/tests/src/python/test_provider_shapefile.py b/tests/src/python/test_provider_shapefile.py index 1f75c08ab78..24f9ae8e270 100644 --- a/tests/src/python/test_provider_shapefile.py +++ b/tests/src/python/test_provider_shapefile.py @@ -269,7 +269,7 @@ class TestPyQgsShapefileProvider(unittest.TestCase, ProviderTestCase): values = [f_iter['pk'] for f_iter in features] self.assertEqual(values, [200]) - got_geom = [f_iter.geometry() for f_iter in features][0].geometry() + got_geom = [f_iter.geometry() for f_iter in features][0].constGet() self.assertEqual((got_geom.x(), got_geom.y()), (2.0, 49.0)) self.assertTrue(vl.dataProvider().changeGeometryValues({fid: QgsGeometry.fromWkt('Point (3 50)')})) @@ -278,7 +278,7 @@ class TestPyQgsShapefileProvider(unittest.TestCase, ProviderTestCase): features = [f_iter for f_iter in vl.getFeatures(QgsFeatureRequest().setFilterFid(fid))] values = [f_iter['pk'] for f_iter in features] - got_geom = [f_iter.geometry() for f_iter in features][0].geometry() + got_geom = [f_iter.geometry() for f_iter in features][0].constGet() self.assertEqual((got_geom.x(), got_geom.y()), (3.0, 50.0)) self.assertTrue(vl.dataProvider().deleteFeatures([fid])) diff --git a/tests/src/python/test_provider_wfs.py b/tests/src/python/test_provider_wfs.py index 43845165e41..8750582b8c1 100644 --- a/tests/src/python/test_provider_wfs.py +++ b/tests/src/python/test_provider_wfs.py @@ -459,7 +459,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(values, [QDateTime(2016, 4, 10, 12, 34, 56, 789, Qt.TimeSpec(Qt.UTC))]) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (426858.0, 5427937.0)) self.assertEqual(vl.featureCount(), 1) @@ -564,7 +564,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): """.encode('UTF-8')) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (426858.0, 5427937.0)) # Test with explicit OUTPUTFORMAT as parameter @@ -588,7 +588,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): """.encode('UTF-8')) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (1.0, 2.0)) # Test with explicit OUTPUTFORMAT in URL @@ -612,7 +612,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): """.encode('UTF-8')) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (3.0, 4.0)) def testWFS10_latlongboundingbox_in_WGS84(self): @@ -781,7 +781,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(values, [QDateTime(2016, 4, 10, 12, 34, 56, 789, Qt.TimeSpec(Qt.UTC))]) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (2.0, 49.0)) # Test changeGeometryValues @@ -805,7 +805,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertTrue(vl.dataProvider().changeGeometryValues({1: QgsGeometry.fromWkt('Point (3 50)')})) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (3.0, 50.0)) values = [f['intfield'] for f in vl.getFeatures()] @@ -852,7 +852,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(values, [QDateTime(2015, 4, 10, 12, 34, 56, 789, Qt.TimeSpec(Qt.UTC))]) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (3.0, 50.0)) # Test deleteFeatures @@ -2269,7 +2269,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertTrue(vl.isValid()) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (2.0, 49.0)) def testDescribeFeatureTypeWithInlineType(self): @@ -2357,7 +2357,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertTrue(vl.isValid()) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (2.0, 49.0)) def testWFS20TransactionsDisabled(self): @@ -2561,7 +2561,7 @@ class TestPyQgsWFSProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(values, [1]) got_f = [f for f in vl.getFeatures()] - got = got_f[0].geometry().geometry() + got = got_f[0].geometry().constGet() self.assertEqual((got.x(), got.y()), (426858.0, 5427937.0)) diff --git a/tests/src/python/test_qgsfillsymbollayers.py b/tests/src/python/test_qgsfillsymbollayers.py index af55f1c87c4..b9d4a3f34b7 100644 --- a/tests/src/python/test_qgsfillsymbollayers.py +++ b/tests/src/python/test_qgsfillsymbollayers.py @@ -70,7 +70,7 @@ class TestQgsFillSymbolLayers(unittest.TestCase): f = QgsFeature() f.setGeometry(geom) - extent = geom.geometry().boundingBox() + extent = geom.constGet().boundingBox() # buffer extent by 10% extent = extent.buffered((extent.height() + extent.width()) / 20.0) diff --git a/tests/src/python/test_qgsgeometry.py b/tests/src/python/test_qgsgeometry.py index 42e93e97a40..c16bed7e60d 100644 --- a/tests/src/python/test_qgsgeometry.py +++ b/tests/src/python/test_qgsgeometry.py @@ -103,21 +103,21 @@ class TestQgsGeometry(unittest.TestCase): wkt = 'MultiPoint ((10 15),(20 30))' geom = QgsGeometry.fromWkt(wkt) self.assertEqual(geom.wkbType(), QgsWkbTypes.MultiPoint, ('Expected:\n%s\nGot:\n%s\n' % (QgsWkbTypes.Point, geom.type()))) - self.assertEqual(geom.geometry().numGeometries(), 2) - self.assertEqual(geom.geometry().geometryN(0).x(), 10) - self.assertEqual(geom.geometry().geometryN(0).y(), 15) - self.assertEqual(geom.geometry().geometryN(1).x(), 20) - self.assertEqual(geom.geometry().geometryN(1).y(), 30) + self.assertEqual(geom.constGet().numGeometries(), 2) + self.assertEqual(geom.constGet().geometryN(0).x(), 10) + self.assertEqual(geom.constGet().geometryN(0).y(), 15) + self.assertEqual(geom.constGet().geometryN(1).x(), 20) + self.assertEqual(geom.constGet().geometryN(1).y(), 30) # Check MS SQL format wkt = 'MultiPoint (11 16, 21 31)' geom = QgsGeometry.fromWkt(wkt) self.assertEqual(geom.wkbType(), QgsWkbTypes.MultiPoint, ('Expected:\n%s\nGot:\n%s\n' % (QgsWkbTypes.Point, geom.type()))) - self.assertEqual(geom.geometry().numGeometries(), 2) - self.assertEqual(geom.geometry().geometryN(0).x(), 11) - self.assertEqual(geom.geometry().geometryN(0).y(), 16) - self.assertEqual(geom.geometry().geometryN(1).x(), 21) - self.assertEqual(geom.geometry().geometryN(1).y(), 31) + self.assertEqual(geom.constGet().numGeometries(), 2) + self.assertEqual(geom.constGet().geometryN(0).x(), 11) + self.assertEqual(geom.constGet().geometryN(0).y(), 16) + self.assertEqual(geom.constGet().geometryN(1).x(), 21) + self.assertEqual(geom.constGet().geometryN(1).y(), 31) def testFromPoint(self): myPoint = QgsGeometry.fromPoint(QgsPointXY(10, 10)) @@ -179,12 +179,12 @@ class TestQgsGeometry(unittest.TestCase): # test num points in geometry exp_nodes = int(row['num_points']) - self.assertEqual(geom.geometry().nCoordinates(), exp_nodes, "Node count {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp_nodes, geom.geometry().nCoordinates())) + self.assertEqual(geom.constGet().nCoordinates(), exp_nodes, "Node count {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp_nodes, geom.constGet().nCoordinates())) # test num geometries in collections exp_geometries = int(row['num_geometries']) try: - self.assertEqual(geom.geometry().numGeometries(), exp_geometries, "Geometry count {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp_geometries, geom.geometry().numGeometries())) + self.assertEqual(geom.constGet().numGeometries(), exp_geometries, "Geometry count {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp_geometries, geom.constGet().numGeometries())) except: # some geometry types don't have numGeometries() assert exp_geometries <= 1, "Geometry count {}: Expected:\n{} geometries but could not call numGeometries()\n".format(i + 1, exp_geometries) @@ -192,15 +192,15 @@ class TestQgsGeometry(unittest.TestCase): # test count of rings exp_rings = int(row['num_rings']) try: - self.assertEqual(geom.geometry().numInteriorRings(), exp_rings, "Ring count {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp_rings, geom.geometry().numInteriorRings())) + self.assertEqual(geom.constGet().numInteriorRings(), exp_rings, "Ring count {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp_rings, geom.constGet().numInteriorRings())) except: # some geometry types don't have numInteriorRings() - assert exp_rings <= 1, "Ring count {}: Expected:\n{} rings but could not call numInteriorRings()\n{}".format(i + 1, exp_rings, geom.geometry()) + assert exp_rings <= 1, "Ring count {}: Expected:\n{} rings but could not call numInteriorRings()\n{}".format(i + 1, exp_rings, geom.constGet()) # test isClosed exp = (row['is_closed'] == '1') try: - self.assertEqual(geom.geometry().isClosed(), exp, "isClosed {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, True, geom.geometry().isClosed())) + self.assertEqual(geom.constGet().isClosed(), exp, "isClosed {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, True, geom.constGet().isClosed())) except: # some geometry types don't have isClosed() assert not exp, "isClosed {}: Expected:\n isClosed() but could not call isClosed()\n".format(i + 1) @@ -211,7 +211,7 @@ class TestQgsGeometry(unittest.TestCase): assert compareWkt(result, exp, 0.00001), "Centroid {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result) # test bounding box limits - bbox = geom.geometry().boundingBox() + bbox = geom.constGet().boundingBox() exp = float(row['x_min']) result = bbox.xMinimum() self.assertAlmostEqual(result, exp, 5, "Min X {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result)) @@ -227,17 +227,17 @@ class TestQgsGeometry(unittest.TestCase): # test area calculation exp = float(row['area']) - result = geom.geometry().area() + result = geom.constGet().area() self.assertAlmostEqual(result, exp, 5, "Area {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result)) # test length calculation exp = float(row['length']) - result = geom.geometry().length() + result = geom.constGet().length() self.assertAlmostEqual(result, exp, 5, "Length {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result)) # test perimeter calculation exp = float(row['perimeter']) - result = geom.geometry().perimeter() + result = geom.constGet().perimeter() self.assertAlmostEqual(result, exp, 5, "Perimeter {}: mismatch Expected:\n{}\nGot:\n{}\n".format(i + 1, exp, result)) def testIntersection(self): @@ -1422,7 +1422,7 @@ class TestQgsGeometry(unittest.TestCase): # test adding a part with Z values point = QgsGeometry.fromPoint(points[0]) - point.geometry().addZValue(4.0) + point.get().addZValue(4.0) self.assertEqual(point.addPointsV2([QgsPoint(points[1][0], points[1][1], 3.0, wkbType=QgsWkbTypes.PointZ)]), 0) expwkt = "MultiPointZ ((0 0 4), (1 0 3))" wkt = point.exportToWkt() @@ -1451,7 +1451,7 @@ class TestQgsGeometry(unittest.TestCase): # test adding a part with Z values polyline = QgsGeometry.fromPolylineXY(points[0]) - polyline.geometry().addZValue(4.0) + polyline.get().addZValue(4.0) points2 = [QgsPoint(p[0], p[1], 3.0, wkbType=QgsWkbTypes.PointZ) for p in points[1]] self.assertEqual(polyline.addPointsV2(points2), QgsGeometry.Success) expwkt = "MultiLineStringZ ((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 0 4),(3 0 3, 3 1 3, 5 1 3, 5 0 3, 6 0 3))" @@ -1495,7 +1495,7 @@ class TestQgsGeometry(unittest.TestCase): # test adding a part with Z values polygon = QgsGeometry.fromPolygon(points[0]) - polygon.geometry().addZValue(4.0) + polygon.get().addZValue(4.0) points2 = [QgsPoint(pi[0], pi[1], 3.0, wkbType=QgsWkbTypes.PointZ) for pi in points[1][0]] self.assertEqual(polygon.addPointsV2(points2), QgsGeometry.Success) expwkt = "MultiPolygonZ (((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 2 4, 0 2 4, 0 0 4)),((4 0 3, 5 0 3, 5 2 3, 3 2 3, 3 1 3, 4 1 3, 4 0 3)))" @@ -1820,24 +1820,24 @@ class TestQgsGeometry(unittest.TestCase): # circular string geom = QgsGeometry.fromWkt('CircularString (1 5, 6 2, 7 3)') - assert geom.geometry().addZValue(2) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.CircularStringZ) + assert geom.constGet().addZValue(2) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CircularStringZ) expWkt = 'CircularStringZ (1 5 2, 6 2 2, 7 3 2)' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addZValue to CircularString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # compound curve geom = QgsGeometry.fromWkt('CompoundCurve ((5 3, 5 13),CircularString (5 13, 7 15, 9 13),(9 13, 9 3),CircularString (9 3, 7 1, 5 3))') - assert geom.geometry().addZValue(2) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.CompoundCurveZ) + assert geom.constGet().addZValue(2) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CompoundCurveZ) expWkt = 'CompoundCurveZ ((5 3 2, 5 13 2),CircularStringZ (5 13 2, 7 15 2, 9 13 2),(9 13 2, 9 3 2),CircularStringZ (9 3 2, 7 1 2, 5 3 2))' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addZValue to CompoundCurve failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # curve polygon geom = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))') - assert geom.geometry().addZValue(3) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.PolygonZ) + assert geom.constGet().addZValue(3) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PolygonZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.PolygonZ) expWkt = 'PolygonZ ((0 0 3, 1 0 3, 1 1 3, 2 1 3, 2 2 3, 0 2 3, 0 0 3))' wkt = geom.exportToWkt() @@ -1845,8 +1845,8 @@ class TestQgsGeometry(unittest.TestCase): # geometry collection geom = QgsGeometry.fromWkt('MultiPoint ((1 2),(2 3))') - assert geom.geometry().addZValue(4) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.MultiPointZ) + assert geom.constGet().addZValue(4) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.MultiPointZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.MultiPointZ) expWkt = 'MultiPointZ ((1 2 4),(2 3 4))' wkt = geom.exportToWkt() @@ -1854,8 +1854,8 @@ class TestQgsGeometry(unittest.TestCase): # LineString geom = QgsGeometry.fromWkt('LineString (1 2, 2 3)') - assert geom.geometry().addZValue(4) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.LineStringZ) + assert geom.constGet().addZValue(4) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.LineStringZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.LineStringZ) expWkt = 'LineStringZ (1 2 4, 2 3 4)' wkt = geom.exportToWkt() @@ -1863,8 +1863,8 @@ class TestQgsGeometry(unittest.TestCase): # Point geom = QgsGeometry.fromWkt('Point (1 2)') - assert geom.geometry().addZValue(4) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.PointZ) + assert geom.constGet().addZValue(4) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PointZ) self.assertEqual(geom.wkbType(), QgsWkbTypes.PointZ) expWkt = 'PointZ (1 2 4)' wkt = geom.exportToWkt() @@ -1875,48 +1875,48 @@ class TestQgsGeometry(unittest.TestCase): # circular string geom = QgsGeometry.fromWkt('CircularString (1 5, 6 2, 7 3)') - assert geom.geometry().addMValue(2) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.CircularStringM) + assert geom.constGet().addMValue(2) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CircularStringM) expWkt = 'CircularStringM (1 5 2, 6 2 2, 7 3 2)' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addMValue to CircularString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # compound curve geom = QgsGeometry.fromWkt('CompoundCurve ((5 3, 5 13),CircularString (5 13, 7 15, 9 13),(9 13, 9 3),CircularString (9 3, 7 1, 5 3))') - assert geom.geometry().addMValue(2) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.CompoundCurveM) + assert geom.constGet().addMValue(2) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.CompoundCurveM) expWkt = 'CompoundCurveM ((5 3 2, 5 13 2),CircularStringM (5 13 2, 7 15 2, 9 13 2),(9 13 2, 9 3 2),CircularStringM (9 3 2, 7 1 2, 5 3 2))' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addMValue to CompoundCurve failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # curve polygon geom = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0))') - assert geom.geometry().addMValue(3) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.PolygonM) + assert geom.constGet().addMValue(3) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PolygonM) expWkt = 'PolygonM ((0 0 3, 1 0 3, 1 1 3, 2 1 3, 2 2 3, 0 2 3, 0 0 3))' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addMValue to CurvePolygon failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # geometry collection geom = QgsGeometry.fromWkt('MultiPoint ((1 2),(2 3))') - assert geom.geometry().addMValue(4) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.MultiPointM) + assert geom.constGet().addMValue(4) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.MultiPointM) expWkt = 'MultiPointM ((1 2 4),(2 3 4))' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addMValue to GeometryCollection failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # LineString geom = QgsGeometry.fromWkt('LineString (1 2, 2 3)') - assert geom.geometry().addMValue(4) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.LineStringM) + assert geom.constGet().addMValue(4) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.LineStringM) expWkt = 'LineStringM (1 2 4, 2 3 4)' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addMValue to LineString failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) # Point geom = QgsGeometry.fromWkt('Point (1 2)') - assert geom.geometry().addMValue(4) - self.assertEqual(geom.geometry().wkbType(), QgsWkbTypes.PointM) + assert geom.constGet().addMValue(4) + self.assertEqual(geom.constGet().wkbType(), QgsWkbTypes.PointM) expWkt = 'PointM (1 2 4)' wkt = geom.exportToWkt() assert compareWkt(expWkt, wkt), "addMValue to Point failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) @@ -4138,7 +4138,7 @@ class TestQgsGeometry(unittest.TestCase): # QGIS native algorithms are bad! if False: - result = QgsGeometry(input.geometry().centroid()).exportToWkt() + result = QgsGeometry(input.get().centroid()).exportToWkt() self.assertTrue(compareWkt(result, exp, 0.00001), "centroid: mismatch using QgsAbstractGeometry methods Input {} \n Expected:\n{}\nGot:\n{}\n".format(t[0], exp, result)) @@ -4214,8 +4214,8 @@ class TestQgsGeometry(unittest.TestCase): # make sure area is unchanged self.assertAlmostEqual(input.area(), o.area(), 5) max_points = 999999 - for p in range(o.geometry().numGeometries()): - part = o.geometry().geometryN(p) + for p in range(o.constGet().numGeometries()): + part = o.constGet().geometryN(p) self.assertLessEqual(part.nCoordinates(), max(t[1], 8)) if t[2]: @@ -4291,11 +4291,11 @@ class TestQgsGeometry(unittest.TestCase): if as_painter_path: path = QPainterPath() - geom.geometry().addToPainterPath(path) + geom.constGet().addToPainterPath(path) painter.drawPath(path) else: if as_polygon: - geom.geometry().drawAsPolygon(painter) + geom.constGet().drawAsPolygon(painter) else: geom.draw(painter) painter.end() @@ -4343,7 +4343,7 @@ class TestQgsGeometry(unittest.TestCase): rendered_image = self.renderGeometry(geom, test['use_pen']) assert self.imageCheck(test['name'], test['reference_image'], rendered_image) - if hasattr(geom.geometry(), 'addToPainterPath'): + if hasattr(geom.constGet(), 'addToPainterPath'): # also check using painter path rendered_image = self.renderGeometry(geom, test['use_pen'], as_painter_path=True) assert self.imageCheck(test['name'], test['reference_image'], rendered_image) diff --git a/tests/src/python/test_qgsjsonutils.py b/tests/src/python/test_qgsjsonutils.py index 8b802be717f..d780810c5fe 100644 --- a/tests/src/python/test_qgsjsonutils.py +++ b/tests/src/python/test_qgsjsonutils.py @@ -58,7 +58,7 @@ class TestQgsJsonUtils(unittest.TestCase): self.assertEqual(len(features), 1) self.assertFalse(features[0].geometry().isNull()) self.assertEqual(features[0].geometry().wkbType(), QgsWkbTypes.Point) - point = features[0].geometry().geometry() + point = features[0].geometry().constGet() self.assertEqual(point.x(), 125.0) self.assertEqual(point.y(), 10.0) self.assertEqual(features[0]['name'], "Dinagat Islands") @@ -68,13 +68,13 @@ class TestQgsJsonUtils(unittest.TestCase): self.assertEqual(len(features), 2) self.assertFalse(features[0].geometry().isNull()) self.assertEqual(features[0].geometry().wkbType(), QgsWkbTypes.Point) - point = features[0].geometry().geometry() + point = features[0].geometry().constGet() self.assertEqual(point.x(), 125.0) self.assertEqual(point.y(), 10.0) self.assertEqual(features[0]['name'], "Dinagat Islands") self.assertFalse(features[1].geometry().isNull()) self.assertEqual(features[1].geometry().wkbType(), QgsWkbTypes.Point) - point = features[1].geometry().geometry() + point = features[1].geometry().constGet() self.assertEqual(point.x(), 110.0) self.assertEqual(point.y(), 20.0) self.assertEqual(features[1]['name'], "Henry Gale Island") diff --git a/tests/src/python/test_qgslinesymbollayers.py b/tests/src/python/test_qgslinesymbollayers.py index 687bbfebe79..e312836b2da 100644 --- a/tests/src/python/test_qgslinesymbollayers.py +++ b/tests/src/python/test_qgslinesymbollayers.py @@ -70,7 +70,7 @@ class TestQgsLineSymbolLayers(unittest.TestCase): f = QgsFeature() f.setGeometry(geom) - extent = geom.geometry().boundingBox() + extent = geom.constGet().boundingBox() # buffer extent by 10% extent = extent.buffered((extent.height() + extent.width()) / 20.0) diff --git a/tests/src/python/test_qgssymbol.py b/tests/src/python/test_qgssymbol.py index 404f3a76fad..e6d2d88dc87 100644 --- a/tests/src/python/test_qgssymbol.py +++ b/tests/src/python/test_qgssymbol.py @@ -114,18 +114,18 @@ class TestQgsSymbol(unittest.TestCase): #test with Z geom_z = QgsGeometry.fromWkt(test['wkt']) - geom_z.geometry().addZValue(5) + geom_z.get().addZValue(5) rendered_image = self.renderGeometry(geom_z) assert self.imageCheck(test['name'] + 'Z', test['reference_image'], rendered_image) #test with ZM - geom_z.geometry().addMValue(15) + geom_z.get().addMValue(15) rendered_image = self.renderGeometry(geom_z) assert self.imageCheck(test['name'] + 'ZM', test['reference_image'], rendered_image) #test with M geom_m = QgsGeometry.fromWkt(test['wkt']) - geom_m.geometry().addMValue(15) + geom_m.get().addMValue(15) rendered_image = self.renderGeometry(geom_m) assert self.imageCheck(test['name'] + 'M', test['reference_image'], rendered_image) @@ -137,7 +137,7 @@ class TestQgsSymbol(unittest.TestCase): painter = QPainter() ms = QgsMapSettings() - extent = geom.geometry().boundingBox() + extent = geom.get().boundingBox() # buffer extent by 10% if extent.width() > 0: extent = extent.buffered((extent.height() + extent.width()) / 20.0) diff --git a/tests/src/python/test_qgssymbollayer.py b/tests/src/python/test_qgssymbollayer.py index 0f0bef18946..b6c3d37ab72 100644 --- a/tests/src/python/test_qgssymbollayer.py +++ b/tests/src/python/test_qgssymbollayer.py @@ -380,7 +380,7 @@ class TestQgsSymbolLayer(unittest.TestCase): f = QgsFeature() f.setGeometry(geom) - extent = geom.geometry().boundingBox() + extent = geom.constGet().boundingBox() # buffer extent by 10% extent = extent.buffered((extent.height() + extent.width()) / 20.0) @@ -445,7 +445,7 @@ class TestQgsSymbolLayer(unittest.TestCase): f = QgsFeature() f.setGeometry(geom) - extent = geom.geometry().boundingBox() + extent = geom.constGet().boundingBox() # buffer extent by 10% extent = extent.buffered((extent.height() + extent.width()) / 20.0) diff --git a/tests/src/python/test_qgsvectorlayer.py b/tests/src/python/test_qgsvectorlayer.py index 5aa60366838..86399dd0ebd 100644 --- a/tests/src/python/test_qgsvectorlayer.py +++ b/tests/src/python/test_qgsvectorlayer.py @@ -2561,15 +2561,15 @@ class TestQgsVectorLayer(unittest.TestCase, FeatureSourceTestCase): features = [f for f in layer.getFeatures(request)] # virtual field value should not change, even though geometry has self.assertAlmostEqual(features[0]['virtual'], -71.123, 2) - self.assertAlmostEqual(features[0].geometry().geometry().x(), -7917376, -5) + self.assertAlmostEqual(features[0].geometry().constGet().x(), -7917376, -5) self.assertEqual(features[1]['virtual'], NULL) self.assertFalse(features[1].hasGeometry()) self.assertAlmostEqual(features[2]['virtual'], -70.332, 2) - self.assertAlmostEqual(features[2].geometry().geometry().x(), -7829322, -5) + self.assertAlmostEqual(features[2].geometry().constGet().x(), -7829322, -5) self.assertAlmostEqual(features[3]['virtual'], -68.2, 2) - self.assertAlmostEqual(features[3].geometry().geometry().x(), -7591989, -5) + self.assertAlmostEqual(features[3].geometry().constGet().x(), -7591989, -5) self.assertAlmostEqual(features[4]['virtual'], -65.32, 2) - self.assertAlmostEqual(features[4].geometry().geometry().x(), -7271389, -5) + self.assertAlmostEqual(features[4].geometry().constGet().x(), -7271389, -5) class TestQgsVectorLayerSourceAddedFeaturesInBuffer(unittest.TestCase, FeatureSourceTestCase): diff --git a/tests/src/python/test_qgsvectorlayereditbuffer.py b/tests/src/python/test_qgsvectorlayereditbuffer.py index 016d050db55..fdc9bd1a528 100644 --- a/tests/src/python/test_qgsvectorlayereditbuffer.py +++ b/tests/src/python/test_qgsvectorlayereditbuffer.py @@ -283,7 +283,7 @@ class TestQgsVectorLayerEditBuffer(unittest.TestCase): # test contents of buffer self.assertEqual(list(layer.editBuffer().changedGeometries().keys()), [1]) - self.assertEqual(layer.editBuffer().changedGeometries()[1].geometry().x(), 10) + self.assertEqual(layer.editBuffer().changedGeometries()[1].constGet().x(), 10) self.assertTrue(layer.editBuffer().isFeatureGeometryChanged(1)) self.assertFalse(layer.editBuffer().isFeatureGeometryChanged(2)) @@ -291,8 +291,8 @@ class TestQgsVectorLayerEditBuffer(unittest.TestCase): # test contents of buffer self.assertEqual(set(layer.editBuffer().changedGeometries().keys()), set([1, 2])) - self.assertEqual(layer.editBuffer().changedGeometries()[1].geometry().x(), 10) - self.assertEqual(layer.editBuffer().changedGeometries()[2].geometry().x(), 20) + self.assertEqual(layer.editBuffer().changedGeometries()[1].constGet().x(), 10) + self.assertEqual(layer.editBuffer().changedGeometries()[2].constGet().x(), 20) self.assertTrue(layer.editBuffer().isFeatureGeometryChanged(1)) self.assertTrue(layer.editBuffer().isFeatureGeometryChanged(2)) diff --git a/tests/testdata/polys_overlapping_with_id.dbf b/tests/testdata/polys_overlapping_with_id.dbf index b6ed926ce205bcbdef105b9fa588f409d26f58ef..333af4f0d0af1f0868ec1fd4bc908bde6f895fd9 100644 GIT binary patch delta 13 UcmdnUwULX3xs*$CBa1F802tT;{Qv*} delta 13 UcmdnUwULX3xs*$IBa1F802sOg_W%F@