Skip to content
Permalink
Browse files
Add context argument to vector.features
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent f3cfb8b commit adc7cf0ec2c06398c08b7b197ded090f971e342a
Showing with 174 additions and 173 deletions.
  1. +1 −1 python/plugins/processing/algs/exampleprovider/ExampleAlgorithm.py
  2. +1 −1 python/plugins/processing/algs/qgis/AddTableField.py
  3. +1 −1 python/plugins/processing/algs/qgis/AutoincrementalField.py
  4. +1 −1 python/plugins/processing/algs/qgis/BasicStatistics.py
  5. +1 −1 python/plugins/processing/algs/qgis/BasicStatisticsNumbers.py
  6. +1 −1 python/plugins/processing/algs/qgis/BasicStatisticsStrings.py
  7. +1 −1 python/plugins/processing/algs/qgis/Boundary.py
  8. +1 −1 python/plugins/processing/algs/qgis/BoundingBox.py
  9. +3 −3 python/plugins/processing/algs/qgis/Buffer.py
  10. +1 −1 python/plugins/processing/algs/qgis/Centroids.py
  11. +3 −3 python/plugins/processing/algs/qgis/CheckValidity.py
  12. +3 −2 python/plugins/processing/algs/qgis/Clip.py
  13. +3 −3 python/plugins/processing/algs/qgis/ConvexHull.py
  14. +1 −1 python/plugins/processing/algs/qgis/Delaunay.py
  15. +1 −1 python/plugins/processing/algs/qgis/DeleteColumn.py
  16. +1 −1 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
  17. +1 −1 python/plugins/processing/algs/qgis/DeleteHoles.py
  18. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometries.py
  19. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  20. +1 −1 python/plugins/processing/algs/qgis/Difference.py
  21. +1 −1 python/plugins/processing/algs/qgis/Dissolve.py
  22. +1 −1 python/plugins/processing/algs/qgis/DropGeometry.py
  23. +1 −1 python/plugins/processing/algs/qgis/EquivalentNumField.py
  24. +1 −1 python/plugins/processing/algs/qgis/ExecuteSQL.py
  25. +1 −1 python/plugins/processing/algs/qgis/Explode.py
  26. +1 −1 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  27. +1 −1 python/plugins/processing/algs/qgis/ExtendLines.py
  28. +3 −3 python/plugins/processing/algs/qgis/ExtentFromLayer.py
  29. +3 −3 python/plugins/processing/algs/qgis/ExtractByLocation.py
  30. +1 −1 python/plugins/processing/algs/qgis/ExtractNodes.py
  31. +1 −1 python/plugins/processing/algs/qgis/ExtractSpecificNodes.py
  32. +1 −1 python/plugins/processing/algs/qgis/FieldPyculator.py
  33. +1 −1 python/plugins/processing/algs/qgis/FieldsCalculator.py
  34. +1 −1 python/plugins/processing/algs/qgis/FieldsMapper.py
  35. +1 −1 python/plugins/processing/algs/qgis/FixGeometry.py
  36. +2 −2 python/plugins/processing/algs/qgis/FixedDistanceBuffer.py
  37. +1 −1 python/plugins/processing/algs/qgis/GeometryByExpression.py
  38. +1 −1 python/plugins/processing/algs/qgis/GeometryConvert.py
  39. +1 −1 python/plugins/processing/algs/qgis/Gridify.py
  40. +1 −1 python/plugins/processing/algs/qgis/Heatmap.py
  41. +1 −1 python/plugins/processing/algs/qgis/HubDistanceLines.py
  42. +1 −1 python/plugins/processing/algs/qgis/HubDistancePoints.py
  43. +2 −2 python/plugins/processing/algs/qgis/HubLines.py
  44. +1 −1 python/plugins/processing/algs/qgis/HypsometricCurves.py
  45. +1 −1 python/plugins/processing/algs/qgis/Intersection.py
  46. +2 −2 python/plugins/processing/algs/qgis/JoinAttributes.py
  47. +1 −1 python/plugins/processing/algs/qgis/LinesIntersection.py
  48. +1 −1 python/plugins/processing/algs/qgis/LinesToPolygons.py
  49. +1 −1 python/plugins/processing/algs/qgis/MeanCoords.py
  50. +1 −1 python/plugins/processing/algs/qgis/MergeLines.py
  51. +1 −1 python/plugins/processing/algs/qgis/MultipartToSingleparts.py
  52. +1 −1 python/plugins/processing/algs/qgis/NearestNeighbourAnalysis.py
  53. +1 −1 python/plugins/processing/algs/qgis/OffsetLine.py
  54. +6 −6 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  55. +1 −1 python/plugins/processing/algs/qgis/Orthogonalize.py
  56. +8 −8 python/plugins/processing/algs/qgis/PointDistance.py
  57. +1 −1 python/plugins/processing/algs/qgis/PointOnSurface.py
  58. +1 −1 python/plugins/processing/algs/qgis/PointsAlongGeometry.py
  59. +1 −1 python/plugins/processing/algs/qgis/PointsDisplacement.py
  60. +1 −1 python/plugins/processing/algs/qgis/PointsFromLines.py
  61. +1 −1 python/plugins/processing/algs/qgis/PointsFromPolygons.py
  62. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygon.py
  63. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygonUnique.py
  64. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygonWeighted.py
  65. +1 −1 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  66. +1 −1 python/plugins/processing/algs/qgis/PointsToPaths.py
  67. +1 −1 python/plugins/processing/algs/qgis/PoleOfInaccessibility.py
  68. +1 −1 python/plugins/processing/algs/qgis/PolygonCentroids.py
  69. +1 −1 python/plugins/processing/algs/qgis/Polygonize.py
  70. +1 −1 python/plugins/processing/algs/qgis/PolygonsToLines.py
  71. +1 −1 python/plugins/processing/algs/qgis/RandomExtract.py
  72. +3 −3 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  73. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  74. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  75. +1 −1 python/plugins/processing/algs/qgis/RandomSelectionWithinSubsets.py
  76. +1 −1 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  77. +1 −1 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  78. +1 −1 python/plugins/processing/algs/qgis/RemoveNullGeometry.py
  79. +1 −1 python/plugins/processing/algs/qgis/ReprojectLayer.py
  80. +1 −1 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  81. +2 −2 python/plugins/processing/algs/qgis/SelectByLocation.py
  82. +1 −1 python/plugins/processing/algs/qgis/ServiceAreaFromLayer.py
  83. +1 −1 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  84. +1 −1 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  85. +1 −1 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  86. +1 −1 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  87. +1 −1 python/plugins/processing/algs/qgis/SingleSidedBuffer.py
  88. +1 −1 python/plugins/processing/algs/qgis/Smooth.py
  89. +1 −1 python/plugins/processing/algs/qgis/SnapGeometries.py
  90. +2 −2 python/plugins/processing/algs/qgis/SpatialJoin.py
  91. +1 −1 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  92. +2 −2 python/plugins/processing/algs/qgis/SplitWithLines.py
  93. +1 −1 python/plugins/processing/algs/qgis/StatisticsByCategories.py
  94. +1 −1 python/plugins/processing/algs/qgis/SumLines.py
  95. +2 −2 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  96. +1 −1 python/plugins/processing/algs/qgis/TextToFloat.py
  97. +1 −1 python/plugins/processing/algs/qgis/TopoColors.py
  98. +1 −1 python/plugins/processing/algs/qgis/Translate.py
  99. +2 −2 python/plugins/processing/algs/qgis/Union.py
  100. +1 −2 python/plugins/processing/algs/qgis/VariableDistanceBuffer.py
  101. +1 −1 python/plugins/processing/algs/qgis/VectorSplit.py
  102. +1 −1 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  103. +1 −1 python/plugins/processing/algs/qgis/ZonalStatistics.py
  104. +4 −4 python/plugins/processing/core/GeoAlgorithm.py
  105. +2 −2 python/plugins/processing/core/parameters.py
  106. +4 −2 python/plugins/processing/gui/AlgorithmDialog.py
  107. +2 −2 python/plugins/processing/gui/AlgorithmExecutor.py
  108. +20 −22 python/plugins/processing/tests/ToolsTest.py
  109. +5 −4 python/plugins/processing/tools/vector.py
@@ -113,7 +113,7 @@ def processAlgorithm(self, context, feedback):
# selection that might exist in layer and the configuration that
# indicates should algorithm use only selected features or all
# of them
features = vector.features(vectorLayer)
features = vector.features(vectorLayer, context)
for f in features:
writer.addFeature(f)

@@ -99,7 +99,7 @@ def processAlgorithm(self, context, feedback):
writer = output.getVectorWriter(fields, layer.wkbType(),
layer.crs())
outFeat = QgsFeature()
features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
@@ -69,7 +69,7 @@ def processAlgorithm(self, context, feedback):
writer = output.getVectorWriter(fields, vlayer.wkbType(),
vlayer.crs())
outFeat = QgsFeature()
features = vector.features(vlayer)
features = vector.features(vlayer, context)
total = 100.0 / len(features)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
@@ -129,7 +129,7 @@ def processAlgorithm(self, context, feedback):
output_file = self.getOutputValue(self.OUTPUT_HTML_FILE)

request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([field_name], layer.fields())
features = vector.features(layer, request)
features = vector.features(layer, context, request)

data = []
data.append(self.tr('Analyzed layer: {}').format(layer.name()))
@@ -123,7 +123,7 @@ def processAlgorithm(self, context, feedback):

request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName], layer.fields())
stat = QgsStatisticalSummary()
features = vector.features(layer, request)
features = vector.features(layer, context, request)
count = len(features)
total = 100.0 / float(count)
for current, ft in enumerate(features):
@@ -110,7 +110,7 @@ def processAlgorithm(self, context, feedback):
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName],
layer.fields())
stat = QgsStringStatisticalSummary()
features = vector.features(layer, request)
features = vector.features(layer, context, request)
count = len(features)
total = 100.0 / float(count)
for current, ft in enumerate(features):
@@ -83,7 +83,7 @@ def processAlgorithm(self, context, feedback):
output_wkb,
layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

for current, input_feature in enumerate(features):
@@ -72,7 +72,7 @@ def processAlgorithm(self, context, feedback):
QgsWkbTypes.Polygon,
layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

for current, input_feature in enumerate(features):
@@ -30,16 +30,16 @@
from processing.tools import vector


def buffering(feedback, writer, distance, field, useField, layer, dissolve,
segments, endCapStyle=1, joinStyle=1, mitreLimit=2):
def buffering(feedback, context, writer, distance, field, useField, layer, dissolve, segments, endCapStyle=1,
joinStyle=1, mitreLimit=2):

if useField:
field = layer.fields().lookupField(field)

outFeat = QgsFeature()

current = 0
features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / float(len(features))

# With dissolve
@@ -73,7 +73,7 @@ def processAlgorithm(self, context, feedback):
QgsWkbTypes.Point,
layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, input_feature in enumerate(features):
output_feature = input_feature
@@ -95,11 +95,11 @@ def processAlgorithm(self, context, feedback):
if method != 0:
settings.setValue(settings_method_key, method)
try:
self.doCheck(feedback)
self.doCheck(context, feedback)
finally:
settings.setValue(settings_method_key, initial_method_setting)

def doCheck(self, feedback):
def doCheck(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))

@@ -136,7 +136,7 @@ def doCheck(self, feedback):
layer.crs())
error_count = 0

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
geom = inFeat.geometry()
@@ -78,7 +78,7 @@ def processAlgorithm(self, context, feedback):

# first build up a list of clip geometries
clip_geoms = []
for maskFeat in vector.features(mask_layer, QgsFeatureRequest().setSubsetOfAttributes([])):
for maskFeat in vector.features(mask_layer, context, QgsFeatureRequest().setSubsetOfAttributes([])):
clip_geoms.append(maskFeat.geometry())

# are we clipping against a single feature? if so, we can show finer progress reports
@@ -96,7 +96,8 @@ def processAlgorithm(self, context, feedback):
tested_feature_ids = set()

for i, clip_geom in enumerate(clip_geoms):
input_features = [f for f in vector.features(source_layer, QgsFeatureRequest().setFilterRect(clip_geom.boundingBox()))]
input_features = [f for f in vector.features(source_layer, context,
QgsFeatureRequest().setFilterRect(clip_geom.boundingBox()))]

if not input_features:
continue
@@ -112,15 +112,15 @@ def processAlgorithm(self, context, feedback):

fid = 0
val = None
features = vector.features(layer)
features = vector.features(layer, context)
if useField:
unique = layer.uniqueValues(index)
current = 0
total = 100.0 / (len(features) * len(unique))
for i in unique:
first = True
hull = []
features = vector.features(layer)
features = vector.features(layer, context)
for f in features:
idVar = f[fieldName]
if str(idVar).strip() == str(i).strip():
@@ -149,7 +149,7 @@ def processAlgorithm(self, context, feedback):
else:
hull = []
total = 100.0 / layer.featureCount()
features = vector.features(layer)
features = vector.features(layer, context)
for current, f in enumerate(features):
inGeom = f.geometry()
points = vector.extractPoints(inGeom)
@@ -84,7 +84,7 @@ def processAlgorithm(self, context, feedback):
ptDict = {}
ptNdx = -1
c = voronoi.Context()
features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
geom = QgsGeometry(inFeat.geometry())
@@ -85,7 +85,7 @@ def processAlgorithm(self, context, feedback):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

for current, f in enumerate(features):
@@ -67,7 +67,7 @@ def processAlgorithm(self, context, feedback):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)

total = 100.0 / len(features)
geoms = dict()
@@ -81,7 +81,7 @@ def processAlgorithm(self, context, feedback):
layer.wkbType(),
layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

for current, f in enumerate(features):
@@ -87,7 +87,7 @@ def processAlgorithm(self, context, feedback):
self.OUTPUT).getVectorWriter(layer.fields().toList(),
layer.wkbType(), layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, f in enumerate(features):
feature = f
@@ -81,7 +81,7 @@ def processAlgorithm(self, context, feedback):
self.OUTPUT).getVectorWriter(layer.fields().toList(),
layer.wkbType(), layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, f in enumerate(features):
feature = f
@@ -79,7 +79,7 @@ def processAlgorithm(self, context, feedback):

outFeat = QgsFeature()
index = vector.spatialindex(layerB)
selectionA = vector.features(layerA)
selectionA = vector.features(layerA, context)
total = 100.0 / len(selectionA)
for current, inFeatA in enumerate(selectionA):
geom = inFeatA.geometry()
@@ -86,7 +86,7 @@ def processAlgorithm(self, context, feedback):
vlayerA.crs())

outFeat = QgsFeature()
features = vector.features(vlayerA)
features = vector.features(vlayerA, context)
total = 100.0 / len(features)

if not useField:
@@ -75,7 +75,7 @@ def processAlgorithm(self, context, feedback):
QgsCoordinateReferenceSystem())

request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
features = vector.features(layer, request)
features = vector.features(layer, context, request)
total = 100.0 / len(features)

for current, input_feature in enumerate(features):
@@ -77,7 +77,7 @@ def processAlgorithm(self, context, feedback):
outFeat = QgsFeature()
classes = {}

features = vector.features(vlayer)
features = vector.features(vlayer, context)
total = 100.0 / len(features)
for current, feature in enumerate(features):
feedback.setProgress(int(current * total))
@@ -151,7 +151,7 @@ def processAlgorithm(self, context, feedback):
vLayer.wkbType() if geometry_type != 1 else 1,
vLayer.crs())

features = vector.features(vLayer)
features = vector.features(vLayer, context)
total = 100.0 / len(features)
outFeat = QgsFeature()
for current, inFeat in enumerate(features):
@@ -70,7 +70,7 @@ def processAlgorithm(self, context, feedback):
writer = output.getVectorWriter(fields, QgsWkbTypes.LineString,
vlayer.crs())
outFeat = QgsFeature()
features = vector.features(vlayer)
features = vector.features(vlayer, context)
total = 100.0 / len(features)
for current, feature in enumerate(features):
feedback.setProgress(int(current * total))
@@ -132,7 +132,7 @@ def processAlgorithm(self, context, feedback):
outFeat.initAttributes(len(fields))
outFeat.setFields(fields)

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, f in enumerate(features):
inGeom = f.geometry()
@@ -78,7 +78,7 @@ def processAlgorithm(self, context, feedback):
start_distance = self.getParameterValue(self.START_DISTANCE)
end_distance = self.getParameterValue(self.END_DISTANCE)

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

for current, input_feature in enumerate(features):
@@ -93,7 +93,7 @@ def processAlgorithm(self, context, feedback):
QgsWkbTypes.Polygon, layer.crs())

if byFeature:
self.featureExtent(layer, writer, feedback)
self.featureExtent(layer, context, writer, feedback)
else:
self.layerExtent(layer, writer, feedback)

@@ -132,8 +132,8 @@ def layerExtent(self, layer, writer, feedback):
feat.setAttributes(attrs)
writer.addFeature(feat)

def featureExtent(self, layer, writer, feedback):
features = vector.features(layer)
def featureExtent(self, layer, context, writer, feedback):
features = vector.features(layer, context)
total = 100.0 / len(features)
feat = QgsFeature()
for current, f in enumerate(features):
@@ -101,11 +101,11 @@ def processAlgorithm(self, context, feedback):

if 'disjoint' in predicates:
disjoinSet = []
for feat in vector.features(layer):
for feat in vector.features(layer, context):
disjoinSet.append(feat.id())

selectedSet = []
features = vector.features(selectLayer)
features = vector.features(selectLayer, context)
total = 100.0 / len(features)
for current, f in enumerate(features):
geom = vector.snapToPrecision(f.geometry(), precision)
@@ -133,7 +133,7 @@ def processAlgorithm(self, context, feedback):
if 'disjoint' in predicates:
selectedSet = selectedSet + disjoinSet

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, f in enumerate(features):
if f.id() in selectedSet:
@@ -78,7 +78,7 @@ def processAlgorithm(self, context, feedback):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields, QgsWkbTypes.Point, layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, f in enumerate(features):
input_geometry = f.geometry()
@@ -93,7 +93,7 @@ def processAlgorithm(self, context, feedback):
raise GeoAlgorithmExecutionException(
self.tr('\'{}\' is not a valid node index').format(node))

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

for current, f in enumerate(features):
@@ -144,7 +144,7 @@ def processAlgorithm(self, context, feedback):
self.tr("FieldPyculator code execute error. Field code block can't be executed!\n{0}\n{1}").format(str(sys.exc_info()[0].__name__), str(sys.exc_info()[1])))

# Run
features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
@@ -137,7 +137,7 @@ def processAlgorithm(self, context, feedback):
error = ''
calculationSuccess = True

features = vector.features(layer)
features = vector.features(layer, context)
total = 100.0 / len(features)

rownum = 1
@@ -151,7 +151,7 @@ def processAlgorithm(self, context, feedback):
error_exp = None
inFeat = QgsFeature()
outFeat = QgsFeature()
features = vector.features(layer)
features = vector.features(layer, context)
if len(features):
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
@@ -77,7 +77,7 @@ def processAlgorithm(self, context, feedback):
QgsWkbTypes.multiType(layer.wkbType()),
layer.crs())

features = vector.features(layer)
features = vector.features(layer, context)
if len(features) == 0:
raise GeoAlgorithmExecutionException(self.tr('There are no features in the input layer'))

Loading

0 comments on commit adc7cf0

Please sign in to comment.