Skip to content
Permalink
Browse files

Update python code to new API

  • Loading branch information
nyalldawson committed Oct 25, 2017
1 parent 00e8690 commit c50ee6d42f53fe06b7c4cedd996a3d4aed338641
Showing with 157 additions and 157 deletions.
  1. +2 −2 python/plugins/processing/algs/qgis/EliminateSelection.py
  2. +3 −3 python/plugins/processing/algs/qgis/Explode.py
  3. +1 −1 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  4. +1 −1 python/plugins/processing/algs/qgis/ExtractNodes.py
  5. +1 −1 python/plugins/processing/algs/qgis/ExtractSpecificNodes.py
  6. +2 −2 python/plugins/processing/algs/qgis/FindProjection.py
  7. +9 −9 python/plugins/processing/algs/qgis/GeometryConvert.py
  8. +3 −3 python/plugins/processing/algs/qgis/Intersection.py
  9. +1 −1 python/plugins/processing/algs/qgis/LinesToPolygons.py
  10. +3 −3 python/plugins/processing/algs/qgis/MinimumBoundingGeometry.py
  11. +1 −1 python/plugins/processing/algs/qgis/PointsAlongGeometry.py
  12. +1 −1 python/plugins/processing/algs/qgis/PointsDisplacement.py
  13. +1 −1 python/plugins/processing/algs/qgis/PointsFromPolygons.py
  14. +2 −2 python/plugins/processing/algs/qgis/PointsInPolygon.py
  15. +1 −1 python/plugins/processing/algs/qgis/PointsToPaths.py
  16. +3 −3 python/plugins/processing/algs/qgis/Polygonize.py
  17. +1 −1 python/plugins/processing/algs/qgis/PolygonsToLines.py
  18. +2 −2 python/plugins/processing/algs/qgis/RegularPoints.py
  19. +1 −1 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  20. +1 −1 python/plugins/processing/algs/qgis/SetMValue.py
  21. +1 −1 python/plugins/processing/algs/qgis/SetZValue.py
  22. +2 −2 python/plugins/processing/algs/qgis/SpatialJoin.py
  23. +2 −2 python/plugins/processing/algs/qgis/SpatialJoinSummary.py
  24. +2 −2 python/plugins/processing/algs/qgis/SumLines.py
  25. +4 −4 python/plugins/processing/algs/qgis/TopoColors.py
  26. +6 −6 python/plugins/processing/algs/qgis/Union.py
  27. +12 −12 tests/src/python/featuresourcetestbase.py
  28. +6 −6 tests/src/python/test_provider_ogr.py
  29. +2 −2 tests/src/python/test_provider_shapefile.py
  30. +10 −10 tests/src/python/test_provider_wfs.py
  31. +1 −1 tests/src/python/test_qgsfillsymbollayers.py
  32. +52 −52 tests/src/python/test_qgsgeometry.py
  33. +3 −3 tests/src/python/test_qgsjsonutils.py
  34. +1 −1 tests/src/python/test_qgslinesymbollayers.py
  35. +4 −4 tests/src/python/test_qgssymbol.py
  36. +2 −2 tests/src/python/test_qgssymbollayer.py
  37. +4 −4 tests/src/python/test_qgsvectorlayer.py
  38. +3 −3 tests/src/python/test_qgsvectorlayereditbuffer.py
  39. BIN tests/testdata/polys_overlapping_with_id.dbf
@@ -147,7 +147,7 @@ def processAlgorithm(self, parameters, context, feedback):
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 @@ def processAlgorithm(self, parameters, context, feedback):

selGeom = selFeat.geometry()

if engine.intersects(selGeom.geometry()):
if engine.intersects(selGeom.constGet()):
# We have a candidate
iGeom = geom2Eliminate.intersection(selGeom)

@@ -89,11 +89,11 @@ def processAlgorithm(self, parameters, context, feedback):
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):
@@ -155,7 +155,7 @@ def processAlgorithm(self, parameters, context, feedback):
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)
@@ -99,7 +99,7 @@ def processAlgorithm(self, parameters, context, feedback):
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
@@ -104,7 +104,7 @@ def processAlgorithm(self, parameters, context, feedback):
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:
@@ -95,7 +95,7 @@ def processAlgorithm(self, parameters, context, feedback):
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 @@ def processAlgorithm(self, parameters, context, feedback):
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()])
@@ -151,7 +151,7 @@ def convertToNodes(self, geom):
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 @@ def convertToLineStrings(self, geom):
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,23 +184,23 @@ def convertToMultiLineStrings(self, geom):
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:
# multipoint with at least 3 points
# 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,17 +212,17 @@ def convertToPolygon(self, geom):
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))
return QgsGeometry.collectGeometry(parts)
else:
# linestring to polygon
p = QgsPolygonV2()
linestring = geom.geometry().clone()
linestring = geom.constGet().clone()
linestring.close()
p.setExteriorRing(linestring)
return [QgsGeometry(p)]
@@ -152,19 +152,19 @@ def processAlgorithm(self, parameters, context, feedback):
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):
if feedback.isCanceled():
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:
@@ -101,7 +101,7 @@ def convertWkbToPolygons(self, wkb):
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:
@@ -238,7 +238,7 @@ def createFeature(self, feedback, feature_id, type, geometries, class_field=None
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 @@ def createFeature(self, feedback, feature_id, type, geometries, class_field=None
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)
@@ -108,7 +108,7 @@ def processAlgorithm(self, parameters, context, feedback):
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
@@ -169,7 +169,7 @@ def searchRect(p):
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))
@@ -117,7 +117,7 @@ def processAlgorithm(self, parameters, context, feedback):
(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):
@@ -129,7 +129,7 @@ def processAlgorithm(self, parameters, context, feedback):
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 @@ def processAlgorithm(self, parameters, context, feedback):
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:
@@ -133,7 +133,7 @@ def processAlgorithm(self, parameters, context, feedback):
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:
@@ -104,13 +104,13 @@ def processAlgorithm(self, parameters, context, feedback):

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))
@@ -92,7 +92,7 @@ def convertWkbToLines(self, wkb):
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:
@@ -124,7 +124,7 @@ def processAlgorithm(self, parameters, context, feedback):
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 @@ def processAlgorithm(self, parameters, context, feedback):
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)
@@ -57,7 +57,7 @@ def inputLayerTypes(self):
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'))
@@ -74,7 +74,7 @@ def prepareAlgorithm(self, parameters, context, feedback):
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()
@@ -74,7 +74,7 @@ def prepareAlgorithm(self, parameters, context, feedback):
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()
@@ -195,11 +195,11 @@ def processAlgorithm(self, parameters, context, feedback):
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
@@ -286,11 +286,11 @@ def addField(original, stat, type):
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

@@ -124,7 +124,7 @@ def processAlgorithm(self, parameters, context, feedback):
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 @@ def processAlgorithm(self, parameters, context, feedback):
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

0 comments on commit c50ee6d

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