Skip to content
Permalink
Browse files
[processing] Always require real QgsFields objects in getVectorWriter,
don't allow arrays of fields as inputs
  • Loading branch information
nyalldawson committed May 2, 2017
1 parent 43a8680 commit 15de36ab265e9272bab5ff72028e0969fed05aab
Showing with 131 additions and 95 deletions.
  1. +1 −1 python/plugins/processing/algs/qgis/BoundingBox.py
  2. +13 −9 python/plugins/processing/algs/qgis/CheckValidity.py
  3. +1 −1 python/plugins/processing/algs/qgis/ConcaveHull.py
  4. +11 −6 python/plugins/processing/algs/qgis/ConvexHull.py
  5. +12 −4 python/plugins/processing/algs/qgis/Delaunay.py
  6. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometries.py
  7. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  8. +1 −1 python/plugins/processing/algs/qgis/Dissolve.py
  9. +1 −1 python/plugins/processing/algs/qgis/ExecuteSQL.py
  10. +1 −1 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  11. +18 −13 python/plugins/processing/algs/qgis/ExtentFromLayer.py
  12. +6 −5 python/plugins/processing/algs/qgis/FieldsMapper.py
  13. +1 −1 python/plugins/processing/algs/qgis/FixedDistanceBuffer.py
  14. +9 −8 python/plugins/processing/algs/qgis/GridLine.py
  15. +14 −7 python/plugins/processing/algs/qgis/GridPolygon.py
  16. +2 −1 python/plugins/processing/algs/qgis/LinesIntersection.py
  17. +1 −1 python/plugins/processing/algs/qgis/LinesToPolygons.py
  18. +4 −3 python/plugins/processing/algs/qgis/MeanCoords.py
  19. +1 −1 python/plugins/processing/algs/qgis/Merge.py
  20. +1 −1 python/plugins/processing/algs/qgis/MergeLines.py
  21. +1 −1 python/plugins/processing/algs/qgis/MultipartToSingleparts.py
  22. +1 −1 python/plugins/processing/algs/qgis/OffsetLine.py
  23. +1 −1 python/plugins/processing/algs/qgis/PointOnSurface.py
  24. +1 −1 python/plugins/processing/algs/qgis/PointsFromLines.py
  25. +1 −1 python/plugins/processing/algs/qgis/PointsFromPolygons.py
  26. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygon.py
  27. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygonUnique.py
  28. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygonWeighted.py
  29. +1 −1 python/plugins/processing/algs/qgis/PolygonsToLines.py
  30. +1 −1 python/plugins/processing/algs/qgis/RandomExtract.py
  31. +1 −1 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  32. +1 −1 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  33. +1 −1 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  34. +1 −1 python/plugins/processing/algs/qgis/ReprojectLayer.py
  35. +1 −1 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  36. +1 −1 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  37. +1 −1 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  38. +1 −1 python/plugins/processing/algs/qgis/ShortestPathPointToPoint.py
  39. +1 −1 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  40. +1 −1 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  41. +1 −1 python/plugins/processing/algs/qgis/SingleSidedBuffer.py
  42. +1 −1 python/plugins/processing/algs/qgis/Smooth.py
  43. +1 −1 python/plugins/processing/algs/qgis/SumLines.py
  44. +1 −1 python/plugins/processing/algs/qgis/Translate.py
  45. +1 −1 python/plugins/processing/algs/qgis/VariableDistanceBuffer.py
  46. +1 −1 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  47. +1 −1 python/plugins/processing/algs/qgis/ZonalStatistics.py
  48. +4 −1 python/plugins/processing/tools/vector.py
@@ -66,7 +66,7 @@ def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields().toList(), QgsWkbTypes.Polygon, layer.crs(), context)
self.OUTPUT_LAYER).getVectorWriter(layer.fields(), QgsWkbTypes.Polygon, layer.crs(), context)

features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
@@ -30,7 +30,13 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsSettings, QgsGeometry, QgsFeature, QgsField, QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsSettings,
QgsGeometry,
QgsFeature,
QgsField,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterSelection
@@ -110,18 +116,16 @@ def doCheck(self, context, feedback):
valid_count = 0

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

error_output = self.getOutputFromName(self.ERROR_OUTPUT)
error_fields = [
QgsField(name='message',
type=QVariant.String,
len=255)]
error_fields = QgsFields()
error_fields.append(QgsField('message', QVariant.String, 255))
error_writer = error_output.getVectorWriter(error_fields, QgsWkbTypes.Point, layer.crs(), context)
error_count = 0

@@ -136,7 +136,7 @@ def processAlgorithm(self, context, feedback):
feedback.setProgressText(self.tr('Saving data...'))
feat = QgsFeature()
QgsProcessingUtils.getFeatures(dissolved_layer, context).nextFeature(feat)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.fields().toList(), QgsWkbTypes.Polygon,
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.fields(), QgsWkbTypes.Polygon,
layer.crs(), context)
geom = feat.geometry()
if no_multigeom and geom.isMultipart():
@@ -31,7 +31,12 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsField,
QgsFeature,
QgsGeometry,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -96,11 +101,11 @@ def processAlgorithm(self, context, feedback):
f.setType(QVariant.String)
f.setLength(255)

fields = [QgsField('id', QVariant.Int, '', 20),
f,
QgsField('area', QVariant.Double, '', 20, 6),
QgsField('perim', QVariant.Double, '', 20, 6)
]
fields = QgsFields()
fields.append(QgsField('id', QVariant.Int, '', 20))
fields.append(f)
fields.append(QgsField('area', QVariant.Double, '', 20, 6))
fields.append(QgsField('perim', QVariant.Double, '', 20, 6))

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

@@ -31,7 +31,14 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsField, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsField,
QgsFeatureRequest,
QgsFeature,
QgsGeometry,
QgsPoint,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -72,9 +79,10 @@ def defineCharacteristics(self):
def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)

fields = [QgsField('POINTA', QVariant.Double, '', 24, 15),
QgsField('POINTB', QVariant.Double, '', 24, 15),
QgsField('POINTC', QVariant.Double, '', 24, 15)]
fields = QgsFields()
fields.append(QgsField('POINTA', QVariant.Double, '', 24, 15))
fields.append(QgsField('POINTB', QVariant.Double, '', 24, 15))
fields.append(QgsField('POINTC', QVariant.Double, '', 24, 15))

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

@@ -82,7 +82,7 @@ def processAlgorithm(self, context, feedback):
isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry

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

features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
@@ -77,7 +77,7 @@ def processAlgorithm(self, context, feedback):
isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry

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

features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
@@ -81,7 +81,7 @@ def processAlgorithm(self, context, feedback):
vlayerA = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(Dissolve.INPUT), context)

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

outFeat = QgsFeature()
features = QgsProcessingUtils.getFeatures(vlayerA, context)
@@ -145,7 +145,7 @@ def processAlgorithm(self, context, feedback):
if not vLayer.isValid():
raise GeoAlgorithmExecutionException(vLayer.dataProvider().error().message())

writer = self.getOutputFromName(self.OUTPUT_LAYER).getVectorWriter(vLayer.fields().toList(),
writer = self.getOutputFromName(self.OUTPUT_LAYER).getVectorWriter(vLayer.fields(),
vLayer.wkbType() if geometry_type != 1 else 1,
vLayer.crs(), context)

@@ -106,7 +106,7 @@ def processAlgorithm(self, context, feedback):
zName = vector.createUniqueFieldName('mvalue', fields)
fields.append(QgsField(zName, QVariant.Double))

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

ellips = None
@@ -30,7 +30,13 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsField, QgsPoint, QgsGeometry, QgsFeature, QgsWkbTypes, QgsProcessingUtils
from qgis.core import (QgsField,
QgsPoint,
QgsGeometry,
QgsFeature,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
@@ -75,18 +81,17 @@ def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
byFeature = self.getParameterValue(self.BY_FEATURE)

fields = [
QgsField('MINX', QVariant.Double),
QgsField('MINY', QVariant.Double),
QgsField('MAXX', QVariant.Double),
QgsField('MAXY', QVariant.Double),
QgsField('CNTX', QVariant.Double),
QgsField('CNTY', QVariant.Double),
QgsField('AREA', QVariant.Double),
QgsField('PERIM', QVariant.Double),
QgsField('HEIGHT', QVariant.Double),
QgsField('WIDTH', QVariant.Double),
]
fields = QgsFields()
fields.append(QgsField('MINX', QVariant.Double))
fields.append(QgsField('MINY', QVariant.Double))
fields.append(QgsField('MAXX', QVariant.Double))
fields.append(QgsField('MAXY', QVariant.Double))
fields.append(QgsField('CNTX', QVariant.Double))
fields.append(QgsField('CNTY', QVariant.Double))
fields.append(QgsField('AREA', QVariant.Double))
fields.append(QgsField('PERIM', QVariant.Double))
fields.append(QgsField('HEIGHT', QVariant.Double))
fields.append(QgsField('WIDTH', QVariant.Double))

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

@@ -29,6 +29,7 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsField,
QgsFields,
QgsExpression,
QgsDistanceArea,
QgsProject,
@@ -115,7 +116,7 @@ def processAlgorithm(self, context, feedback):
output = self.getOutputFromName(self.OUTPUT_LAYER)

layer = QgsProcessingUtils.mapLayerFromString(layer, context)
fields = []
fields = QgsFields()
expressions = []

da = QgsDistanceArea()
@@ -125,10 +126,10 @@ def processAlgorithm(self, context, feedback):
exp_context = layer.createExpressionContext()

for field_def in mapping:
fields.append(QgsField(name=field_def['name'],
type=field_def['type'],
len=field_def['length'],
prec=field_def['precision']))
fields.append(QgsField(field_def['name'],
field_def['type'],
field_def['length'],
field_def['precision']))

expression = QgsExpression(field_def['expression'])
expression.setGeomCalculator(da)
@@ -106,7 +106,7 @@ def processAlgorithm(self, context, feedback):
miter_limit = self.getParameterValue(self.MITRE_LIMIT)

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

buff.buffering(feedback, context, writer, distance, None, False, layer, dissolve, segments, end_cap_style,
join_style, miter_limit)
@@ -37,7 +37,8 @@
QgsGeometry,
QgsPointV2,
QgsLineString,
QgsWkbTypes)
QgsWkbTypes,
QgsFields)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterExtent
@@ -118,13 +119,13 @@ def processAlgorithm(self, context, feedback):
raise GeoAlgorithmExecutionException(
self.tr('Vertical spacing is too small for the covered area'))

fields = [QgsField('left', QVariant.Double, '', 24, 16),
QgsField('top', QVariant.Double, '', 24, 16),
QgsField('right', QVariant.Double, '', 24, 16),
QgsField('bottom', QVariant.Double, '', 24, 16),
QgsField('id', QVariant.Int, '', 10, 0),
QgsField('coord', QVariant.Double, '', 24, 15)
]
fields = QgsFields()
fields.append(QgsField('left', QVariant.Double, '', 24, 16))
fields.append(QgsField('top', QVariant.Double, '', 24, 16))
fields.append(QgsField('right', QVariant.Double, '', 24, 16))
fields.append(QgsField('bottom', QVariant.Double, '', 24, 16))
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
fields.append(QgsField('coord', QVariant.Double, '', 24, 15))

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

@@ -30,7 +30,14 @@

from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant
from qgis.core import QgsRectangle, QgsCoordinateReferenceSystem, QgsField, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
from qgis.core import (QgsRectangle,
QgsCoordinateReferenceSystem,
QgsField,
QgsFeature,
QgsGeometry,
QgsPoint,
QgsWkbTypes,
QgsFields)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -123,12 +130,12 @@ def processAlgorithm(self, context, feedback):
raise GeoAlgorithmExecutionException(
self.tr('Vertical spacing is too small for the covered area'))

fields = [QgsField('left', QVariant.Double, '', 24, 16),
QgsField('top', QVariant.Double, '', 24, 16),
QgsField('right', QVariant.Double, '', 24, 16),
QgsField('bottom', QVariant.Double, '', 24, 16),
QgsField('id', QVariant.Int, '', 10, 0)
]
fields = QgsFields()
fields.append(QgsField('left', QVariant.Double, '', 24, 16))
fields.append(QgsField('top', QVariant.Double, '', 24, 16))
fields.append(QgsField('right', QVariant.Double, '', 24, 16))
fields.append(QgsField('bottom', QVariant.Double, '', 24, 16))
fields.append(QgsField('id', QVariant.Int, '', 10, 0))

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

@@ -103,7 +103,8 @@ def processAlgorithm(self, context, feedback):
fieldListB = layerB.fields()

fieldListB = vector.testForUniqueness(fieldListA, fieldListB)
fieldListA.extend(fieldListB)
for b in fieldListB:
fieldListA.append(b)

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldListA, QgsWkbTypes.Point, layerA.crs(),
context)
@@ -68,7 +68,7 @@ def defineCharacteristics(self):
def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)

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

outFeat = QgsFeature()
@@ -93,9 +93,10 @@ def processAlgorithm(self, context, feedback):
else:
uniqueIndex = layer.fields().lookupField(uniqueField)

fieldList = [QgsField('MEAN_X', QVariant.Double, '', 24, 15),
QgsField('MEAN_Y', QVariant.Double, '', 24, 15),
QgsField('UID', QVariant.String, '', 255)]
fieldList = QgsFields()
fieldList.append(QgsField('MEAN_X', QVariant.Double, '', 24, 15))
fieldList.append(QgsField('MEAN_Y', QVariant.Double, '', 24, 15))
fieldList.append(QgsField('UID', QVariant.String, '', 255))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList, QgsWkbTypes.Point, layer.crs(), context)

@@ -95,7 +95,7 @@ def processAlgorithm(self, context, feedback):
fields.append(sfield)

total = 100.0 / totalFeatureCount
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields.toList(), layers[0].wkbType(),
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, layers[0].wkbType(),
layers[0].crs(), context)

featureCount = 0
@@ -69,7 +69,7 @@ def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields().toList(), layer.wkbType(), layer.crs(), context)
self.OUTPUT_LAYER).getVectorWriter(layer.fields(), layer.wkbType(), layer.crs(), context)

features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
@@ -63,7 +63,7 @@ def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
geomType = QgsWkbTypes.singleType(layer.wkbType())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.fields().toList(), geomType, layer.crs(),
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.fields(), geomType, layer.crs(),
context)

features = QgsProcessingUtils.getFeatures(layer, context)
@@ -87,7 +87,7 @@ def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields().toList(), QgsWkbTypes.LineString, layer.crs(), context)
self.OUTPUT_LAYER).getVectorWriter(layer.fields(), QgsWkbTypes.LineString, layer.crs(), context)

distance = self.getParameterValue(self.DISTANCE)
segments = int(self.getParameterValue(self.SEGMENTS))
@@ -66,7 +66,7 @@ def processAlgorithm(self, context, feedback):
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

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

features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

0 comments on commit 15de36a

Please sign in to comment.