Skip to content
Permalink
Browse files

Merge pull request #3353 from nyalldawson/processing

[Processing] QGIS alg cleanups
  • Loading branch information
alexbruy committed Aug 5, 2016
2 parents 4c39bd1 + c1649eb commit 45c8a0943977ea097200ae70515c34e4ac1bf95e
Showing with 136 additions and 169 deletions.
  1. +2 −3 python/plugins/processing/algs/qgis/AddTableField.py
  2. +2 −3 python/plugins/processing/algs/qgis/AutoincrementalField.py
  3. +1 −1 python/plugins/processing/algs/qgis/Centroids.py
  4. +4 −5 python/plugins/processing/algs/qgis/CheckValidity.py
  5. +1 −1 python/plugins/processing/algs/qgis/ConcaveHull.py
  6. +2 −2 python/plugins/processing/algs/qgis/ConvexHull.py
  7. +1 −1 python/plugins/processing/algs/qgis/DeleteColumn.py
  8. +1 −1 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
  9. +1 −1 python/plugins/processing/algs/qgis/DeleteHoles.py
  10. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometries.py
  11. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  12. +3 −3 python/plugins/processing/algs/qgis/Difference.py
  13. +1 −2 python/plugins/processing/algs/qgis/Dissolve.py
  14. +2 −3 python/plugins/processing/algs/qgis/Eliminate.py
  15. +2 −3 python/plugins/processing/algs/qgis/EquivalentNumField.py
  16. +1 −1 python/plugins/processing/algs/qgis/ExecuteSQL.py
  17. +1 −2 python/plugins/processing/algs/qgis/Explode.py
  18. +2 −2 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  19. +1 −1 python/plugins/processing/algs/qgis/ExtractByAttribute.py
  20. +2 −2 python/plugins/processing/algs/qgis/ExtractByLocation.py
  21. +1 −1 python/plugins/processing/algs/qgis/ExtractNodes.py
  22. +3 −4 python/plugins/processing/algs/qgis/FieldPyculator.py
  23. +2 −3 python/plugins/processing/algs/qgis/FieldsCalculator.py
  24. +1 −2 python/plugins/processing/algs/qgis/FieldsMapper.py
  25. +1 −1 python/plugins/processing/algs/qgis/FixedDistanceBuffer.py
  26. +1 −1 python/plugins/processing/algs/qgis/GeometryConvert.py
  27. +1 −1 python/plugins/processing/algs/qgis/Gridify.py
  28. +1 −1 python/plugins/processing/algs/qgis/HubDistance.py
  29. +1 −1 python/plugins/processing/algs/qgis/HubLines.py
  30. +2 −3 python/plugins/processing/algs/qgis/Intersection.py
  31. +1 −2 python/plugins/processing/algs/qgis/JoinAttributes.py
  32. +3 −3 python/plugins/processing/algs/qgis/LinesIntersection.py
  33. +1 −1 python/plugins/processing/algs/qgis/LinesToPolygons.py
  34. +5 −5 python/plugins/processing/algs/qgis/Merge.py
  35. +1 −2 python/plugins/processing/algs/qgis/MergeLines.py
  36. +18 −18 python/plugins/processing/algs/qgis/MultipartToSingleparts.py
  37. +2 −3 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  38. +2 −3 python/plugins/processing/algs/qgis/PointsDisplacement.py
  39. +3 −4 python/plugins/processing/algs/qgis/PointsInPolygon.py
  40. +3 −4 python/plugins/processing/algs/qgis/PointsInPolygonUnique.py
  41. +3 −4 python/plugins/processing/algs/qgis/PointsInPolygonWeighted.py
  42. +1 −2 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  43. +1 −1 python/plugins/processing/algs/qgis/PointsToPaths.py
  44. +1 −2 python/plugins/processing/algs/qgis/Polygonize.py
  45. +1 −1 python/plugins/processing/algs/qgis/PolygonsToLines.py
  46. +1 −1 python/plugins/processing/algs/qgis/RandomExtract.py
  47. +1 −1 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  48. +1 −1 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  49. +1 −1 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  50. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  51. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  52. +2 −2 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  53. +3 −3 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  54. +1 −1 python/plugins/processing/algs/qgis/ReprojectLayer.py
  55. +1 −2 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  56. +2 −3 python/plugins/processing/algs/qgis/SaveSelectedFeatures.py
  57. +1 −1 python/plugins/processing/algs/qgis/SelectByAttribute.py
  58. +1 −1 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  59. +2 −2 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  60. +1 −2 python/plugins/processing/algs/qgis/Smooth.py
  61. +3 −6 python/plugins/processing/algs/qgis/SpatialJoin.py
  62. +2 −2 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  63. +2 −4 python/plugins/processing/algs/qgis/SumLines.py
  64. +5 −8 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  65. +1 −1 python/plugins/processing/algs/qgis/TextToFloat.py
  66. +3 −5 python/plugins/processing/algs/qgis/Union.py
  67. +1 −1 python/plugins/processing/algs/qgis/VariableDistanceBuffer.py
  68. +2 −2 python/plugins/processing/algs/qgis/VectorSplit.py
  69. +1 −1 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  70. +2 −2 python/plugins/processing/algs/qgis/ZonalStatistics.py
  71. +1 −1 python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
  72. +1 −1 python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
@@ -78,11 +78,10 @@ def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT_LAYER))

provider = layer.dataProvider()
fields = provider.fields()
fields = layer.fields()
fields.append(QgsField(fieldName, self.TYPES[fieldType], '',
fieldLength, fieldPrecision))
writer = output.getVectorWriter(fields, provider.wkbType(),
writer = output.getVectorWriter(fields, layer.wkbType(),
layer.crs())
outFeat = QgsFeature()
features = vector.features(layer)
@@ -49,10 +49,9 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT)
vlayer = \
dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
fields = vlayer.fields()
fields.append(QgsField('AUTO', QVariant.Int))
writer = output.getVectorWriter(fields, vprovider.wkbType(),
writer = output.getVectorWriter(fields, vlayer.wkbType(),
vlayer.crs())
outFeat = QgsFeature()
features = vector.features(vlayer)
@@ -63,7 +63,7 @@ def processAlgorithm(self, progress):

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(
layer.pendingFields().toList(),
layer.fields(),
QgsWkbTypes.Point,
layer.crs())

@@ -97,27 +97,26 @@ def processAlgorithm(self, progress):
def doCheck(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT_LAYER))
provider = layer.dataProvider()

settings = QSettings()
method = int(settings.value(settings_method_key, 1))

valid_ouput = self.getOutputFromName(self.VALID_OUTPUT)
valid_fields = layer.pendingFields().toList()
valid_fields = layer.fields()
valid_writer = valid_ouput.getVectorWriter(
valid_fields,
provider.wkbType(),
layer.wkbType(),
layer.crs())
valid_count = 0

invalid_ouput = self.getOutputFromName(self.INVALID_OUTPUT)
invalid_fields = layer.pendingFields().toList() + [
invalid_fields = layer.fields().toList() + [
QgsField(name='_errors',
type=QVariant.String,
len=255)]
invalid_writer = invalid_ouput.getVectorWriter(
invalid_fields,
provider.wkbType(),
layer.wkbType(),
layer.crs())
invalid_count = 0

@@ -111,7 +111,7 @@ def processAlgorithm(self, progress):
feat = QgsFeature()
dissolved_layer.getFeatures(QgsFeatureRequest().setFilterFid(0)).nextFeature(feat)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.pendingFields().toList(), QgsWkbTypes.Polygon, layer.crs())
layer.fields().toList(), QgsWkbTypes.Polygon, layer.crs())
geom = feat.geometry()
if no_multigeom and geom.isMultipart():
# Only singlepart geometries are allowed
@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
f = QgsField('value', QVariant.String, '', 255)
if useField:
index = layer.fieldNameIndex(fieldName)
fType = layer.pendingFields()[index].type()
fType = layer.fields()[index].type()
if fType in [QVariant.Int, QVariant.UInt, QVariant.LongLong, QVariant.ULongLong]:
f.setType(fType)
f.setLength(20)
@@ -97,7 +97,7 @@ def processAlgorithm(self, progress):
]

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields, QgsWkbTypes.Polygon, layer.dataProvider().crs())
fields, QgsWkbTypes.Polygon, layer.crs())

outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -54,7 +54,7 @@ def processAlgorithm(self, progress):
self.getParameterValue(self.INPUT))
idx = layer.fieldNameIndex(self.getParameterValue(self.COLUMN))

fields = layer.pendingFields()
fields = layer.fields()
fields.remove(idx)

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
@@ -49,7 +49,7 @@ def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))

fields = layer.pendingFields()
fields = layer.fields()

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())
@@ -49,7 +49,7 @@ def processAlgorithm(self, progress):
self.getParameterValue(self.INPUT))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.pendingFields(),
layer.fields(),
layer.wkbType(),
layer.crs())

@@ -65,7 +65,7 @@ def processAlgorithm(self, progress):
isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry

writer = self.getOutputFromName(
self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
self.OUTPUT).getVectorWriter(layer.fields().toList(),
layer.wkbType(), layer.crs())

features = vector.features(layer)
@@ -62,7 +62,7 @@ def processAlgorithm(self, progress):
isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry

writer = self.getOutputFromName(
self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
self.OUTPUT).getVectorWriter(layer.fields().toList(),
layer.wkbType(), layer.crs())

features = vector.features(layer)
@@ -68,11 +68,11 @@ def processAlgorithm(self, progress):
self.getParameterValue(Difference.OVERLAY))
ignoreInvalid = self.getParameterValue(Difference.IGNORE_INVALID)

geomType = layerA.dataProvider().wkbType()
geomType = layerA.wkbType()
writer = self.getOutputFromName(
Difference.OUTPUT).getVectorWriter(layerA.pendingFields(),
Difference.OUTPUT).getVectorWriter(layerA.fields(),
geomType,
layerA.dataProvider().crs())
layerA.crs())

outFeat = QgsFeature()
index = vector.spatialindex(layerB)
@@ -71,12 +71,11 @@ def processAlgorithm(self, progress):
field_names = self.getParameterValue(Dissolve.FIELD)
vlayerA = dataobjects.getObjectFromUri(
self.getParameterValue(Dissolve.INPUT))
vproviderA = vlayerA.dataProvider()

writer = self.getOutputFromName(
Dissolve.OUTPUT).getVectorWriter(
vlayerA.fields().toList(),
vproviderA.wkbType(),
vlayerA.wkbType(),
vlayerA.crs())

outFeat = QgsFeature()
@@ -315,10 +315,9 @@ def processAlgorithm(self, progress):
# End while

# Create output
provider = processLayer.dataProvider()
output = self.getOutputFromName(self.OUTPUT)
writer = output.getVectorWriter(provider.fields(),
provider.wkbType(), processLayer.crs())
writer = output.getVectorWriter(processLayer.fields(),
processLayer.wkbType(), processLayer.crs())

# Write all features that are left over to output layer
iterator = processLayer.getFeatures()
@@ -54,11 +54,10 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT)
vlayer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
fieldindex = vlayer.fieldNameIndex(fieldname)
fields = vprovider.fields()
fields = vlayer.fields()
fields.append(QgsField('NUM_FIELD', QVariant.Int))
writer = output.getVectorWriter(fields, vprovider.wkbType(),
writer = output.getVectorWriter(fields, vlayer.wkbType(),
vlayer.crs())
outFeat = QgsFeature()
classes = {}
@@ -131,7 +131,7 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException(vLayer.dataProvider().error().message())

writer = self.getOutputFromName(self.OUTPUT_LAYER).getVectorWriter(
vLayer.pendingFields().toList(),
vLayer.fields().toList(),
# Create a point layer (without any points) if 'no geometry' is chosen
vLayer.wkbType() if geometry_type != 1 else 1,
vLayer.crs())
@@ -48,8 +48,7 @@ def processAlgorithm(self, progress):
vlayer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))
output = self.getOutputFromName(self.OUTPUT)
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
fields = vlayer.fields()
writer = output.getVectorWriter(fields, QgsWkbTypes.LineString,
vlayer.crs())
outFeat = QgsFeature()
@@ -72,7 +72,7 @@ def processAlgorithm(self, progress):
method = self.getParameterValue(self.METHOD)

geometryType = layer.geometryType()
fields = layer.pendingFields()
fields = layer.fields()

if geometryType == QgsWkbTypes.PolygonGeometry:
areaName = vector.createUniqueFieldName('area', fields)
@@ -89,7 +89,7 @@ def processAlgorithm(self, progress):
fields.append(QgsField(yName, QVariant.Double))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields.toList(), layer.dataProvider().wkbType(), layer.crs())
fields.toList(), layer.wkbType(), layer.crs())

ellips = None
crs = None
@@ -83,7 +83,7 @@ def processAlgorithm(self, progress):
operator = self.OPERATORS[self.getParameterValue(self.OPERATOR)]
value = self.getParameterValue(self.VALUE)

fields = layer.pendingFields()
fields = layer.fields()
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())

@@ -70,8 +70,8 @@ def processAlgorithm(self, progress):
index = vector.spatialindex(layer)

output = self.getOutputFromName(self.OUTPUT)
writer = output.getVectorWriter(layer.pendingFields(),
layer.dataProvider().wkbType(), layer.crs())
writer = output.getVectorWriter(layer.fields(),
layer.wkbType(), layer.crs())

if 'disjoint' in predicates:
disjoinSet = []
@@ -62,7 +62,7 @@ def processAlgorithm(self, progress):
self.getParameterValue(self.INPUT))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.pendingFields().toList(), QgsWkbTypes.Point, layer.crs())
layer.fields().toList(), QgsWkbTypes.Point, layer.crs())

outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -88,11 +88,10 @@ def processAlgorithm(self, progress):

layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT_LAYER))
provider = layer.dataProvider()
fields = provider.fields()
fields = layer.fields()
fields.append(QgsField(fieldName, self.TYPES[fieldType], '',
fieldLength, fieldPrecision))
writer = output.getVectorWriter(fields, provider.wkbType(),
writer = output.getVectorWriter(fields, layer.wkbType(),
layer.crs())
outFeat = QgsFeature()
new_ns = {}
@@ -107,7 +106,7 @@ def processAlgorithm(self, progress):
self.tr("FieldPyculator code execute error.Global code block can't be executed!\n%s\n%s") % (unicode(sys.exc_info()[0].__name__), unicode(sys.exc_info()[1])))

# Replace all fields tags
fields = provider.fields()
fields = layer.fields()
num = 0
for field in fields:
field_name = unicode(field.name())
@@ -94,12 +94,11 @@ def processAlgorithm(self, progress):
output.value = system.getTempFilenameInTempFolder(
output.name + '.' + ext)

provider = layer.dataProvider()
fields = layer.pendingFields()
fields = layer.fields()
if newField:
fields.append(QgsField(fieldName, fieldType, '', width, precision))

writer = output.getVectorWriter(fields, provider.wkbType(),
writer = output.getVectorWriter(fields, layer.wkbType(),
layer.crs())

exp = QgsExpression(formula)
@@ -68,7 +68,6 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT_LAYER)

layer = dataobjects.getObjectFromUri(layer)
provider = layer.dataProvider()
fields = []
expressions = []

@@ -109,7 +108,7 @@ def processAlgorithm(self, progress):
expressions.append(expression)

writer = output.getVectorWriter(fields,
provider.wkbType(),
layer.wkbType(),
layer.crs())

# Create output vector layer with new attributes
@@ -75,7 +75,7 @@ def processAlgorithm(self, progress):
segments = int(self.getParameterValue(self.SEGMENTS))

writer = self.getOutputFromName(
self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
self.OUTPUT).getVectorWriter(layer.fields().toList(),
QgsWkbTypes.Polygon, layer.crs())

buff.buffering(progress, writer, distance, None, False, layer,
@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
newType = QgsWkbTypes.Point

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.pendingFields(), newType, layer.crs())
layer.fields(), newType, layer.crs())

features = vector.features(layer)
total = 100.0 / len(features)
@@ -65,7 +65,7 @@ def processAlgorithm(self, progress):
self.tr('Invalid grid spacing: %s/%s' % (hSpacing, vSpacing)))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.pendingFields(), layer.wkbType(), layer.crs())
layer.fields(), layer.wkbType(), layer.crs())

features = vector.features(layer)
total = 100.0 / len(features)
@@ -99,7 +99,7 @@ def processAlgorithm(self, progress):
if addLines:
geomType = QgsWkbTypes.LineString

fields = layerPoints.pendingFields()
fields = layerPoints.fields()
fields.append(QgsField('HubName', QVariant.String))
fields.append(QgsField('HubDist', QVariant.Double))

@@ -71,7 +71,7 @@ def processAlgorithm(self, progress):
self.tr('Same layer given for both hubs and spokes'))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layerSpoke.pendingFields(), QgsWkbTypes.LineString, layerSpoke.crs())
layerSpoke.fields(), QgsWkbTypes.LineString, layerSpoke.crs())

spokes = vector.features(layerSpoke)
hubs = vector.features(layerHub)
@@ -73,12 +73,11 @@ def processAlgorithm(self, progress):
self.getParameterValue(self.INPUT))
vlayerB = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT2))
vproviderA = vlayerA.dataProvider()

geomType = vproviderA.wkbType()
geomType = vlayerA.wkbType()
fields = vector.combineVectorFields(vlayerA, vlayerB)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
geomType, vproviderA.crs())
geomType, vlayerA.crs())
outFeat = QgsFeature()
index = vector.spatialindex(vlayerB)
selectionA = vector.features(vlayerA)
@@ -69,14 +69,13 @@ def processAlgorithm(self, progress):
field2 = self.getParameterValue(self.TABLE_FIELD_2)

layer = dataobjects.getObjectFromUri(input)
provider = layer.dataProvider()
joinField1Index = layer.fieldNameIndex(field)

layer2 = dataobjects.getObjectFromUri(input2)
joinField2Index = layer2.fieldNameIndex(field2)

outFields = vector.combineVectorFields(layer, layer2)
writer = output.getVectorWriter(outFields, provider.wkbType(),
writer = output.getVectorWriter(outFields, layer.wkbType(),
layer.crs())

# Cache attributes of Layer 2

0 comments on commit 45c8a09

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