Skip to content
Permalink
Browse files
Add method QgsProcessingUtils::mapLayerFromString
Algorithms and other processing code should use this method
(instead of dataobjects.getLayerFromString) to
retrieve layers from a string, as it considers the processing
context and allows resolving strings to temporarily stored layers.

This permits processing models to function correctly when
intermediate results are stored as memory layers. Subsequent
model algorithms can then access these temporary layers as inputs.
All temporary layers will be removed when the context object
is destroyed after the model algorithm is run.
  • Loading branch information
nyalldawson committed May 2, 2017
1 parent 1711a41 commit f84d70323408b19125f3a8f6d67ed207efb281fd
Showing with 271 additions and 320 deletions.
  1. +5 −0 python/core/processing/qgsprocessingutils.sip
  2. +2 −2 python/plugins/processing/algs/exampleprovider/ExampleAlgorithm.py
  3. +2 −2 python/plugins/processing/algs/gdal/ClipByMask.py
  4. +3 −2 python/plugins/processing/algs/gdal/rasterize_over.py
  5. +8 −5 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  6. +3 −2 python/plugins/processing/algs/grass7/nviz7.py
  7. +1 −2 python/plugins/processing/algs/qgis/AddTableField.py
  8. +1 −1 python/plugins/processing/algs/qgis/AutoincrementalField.py
  9. +1 −2 python/plugins/processing/algs/qgis/BarPlot.py
  10. +1 −2 python/plugins/processing/algs/qgis/BasicStatistics.py
  11. +1 −2 python/plugins/processing/algs/qgis/BasicStatisticsNumbers.py
  12. +1 −2 python/plugins/processing/algs/qgis/BasicStatisticsStrings.py
  13. +1 −2 python/plugins/processing/algs/qgis/Boundary.py
  14. +1 −2 python/plugins/processing/algs/qgis/BoundingBox.py
  15. +1 −2 python/plugins/processing/algs/qgis/BoxPlot.py
  16. +1 −2 python/plugins/processing/algs/qgis/Centroids.py
  17. +1 −2 python/plugins/processing/algs/qgis/CheckValidity.py
  18. +2 −4 python/plugins/processing/algs/qgis/Clip.py
  19. +3 −3 python/plugins/processing/algs/qgis/ConcaveHull.py
  20. +1 −2 python/plugins/processing/algs/qgis/ConvexHull.py
  21. +1 −1 python/plugins/processing/algs/qgis/CreateAttributeIndex.py
  22. +1 −2 python/plugins/processing/algs/qgis/CreateConstantRaster.py
  23. +1 −1 python/plugins/processing/algs/qgis/DefineProjection.py
  24. +1 −2 python/plugins/processing/algs/qgis/Delaunay.py
  25. +1 −1 python/plugins/processing/algs/qgis/DeleteColumn.py
  26. +1 −2 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
  27. +1 −2 python/plugins/processing/algs/qgis/DeleteHoles.py
  28. +1 −2 python/plugins/processing/algs/qgis/DensifyGeometries.py
  29. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  30. +2 −4 python/plugins/processing/algs/qgis/Difference.py
  31. +1 −2 python/plugins/processing/algs/qgis/Dissolve.py
  32. +1 −2 python/plugins/processing/algs/qgis/DropGeometry.py
  33. +1 −1 python/plugins/processing/algs/qgis/EliminateSelection.py
  34. +1 −2 python/plugins/processing/algs/qgis/EquivalentNumField.py
  35. +1 −1 python/plugins/processing/algs/qgis/ExecuteSQL.py
  36. +1 −2 python/plugins/processing/algs/qgis/Explode.py
  37. +1 −2 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  38. +1 −2 python/plugins/processing/algs/qgis/ExtendLines.py
  39. +1 −2 python/plugins/processing/algs/qgis/ExtentFromLayer.py
  40. +1 −1 python/plugins/processing/algs/qgis/ExtractByAttribute.py
  41. +1 −1 python/plugins/processing/algs/qgis/ExtractByExpression.py
  42. +2 −2 python/plugins/processing/algs/qgis/ExtractByLocation.py
  43. +1 −2 python/plugins/processing/algs/qgis/ExtractNodes.py
  44. +1 −2 python/plugins/processing/algs/qgis/ExtractSpecificNodes.py
  45. +1 −2 python/plugins/processing/algs/qgis/FieldPyculator.py
  46. +1 −1 python/plugins/processing/algs/qgis/FieldsCalculator.py
  47. +1 −1 python/plugins/processing/algs/qgis/FieldsMapper.py
  48. +1 −2 python/plugins/processing/algs/qgis/FindProjection.py
  49. +1 −2 python/plugins/processing/algs/qgis/FixGeometry.py
  50. +1 −1 python/plugins/processing/algs/qgis/FixedDistanceBuffer.py
  51. +1 −2 python/plugins/processing/algs/qgis/GeometryByExpression.py
  52. +1 −2 python/plugins/processing/algs/qgis/GeometryConvert.py
  53. +1 −1 python/plugins/processing/algs/qgis/Gridify.py
  54. +1 −2 python/plugins/processing/algs/qgis/Heatmap.py
  55. +2 −4 python/plugins/processing/algs/qgis/HubDistanceLines.py
  56. +2 −4 python/plugins/processing/algs/qgis/HubDistancePoints.py
  57. +2 −4 python/plugins/processing/algs/qgis/HubLines.py
  58. +1 −2 python/plugins/processing/algs/qgis/HypsometricCurves.py
  59. +1 −1 python/plugins/processing/algs/qgis/IdwInterpolation.py
  60. +1 −1 python/plugins/processing/algs/qgis/ImportIntoPostGIS.py
  61. +1 −1 python/plugins/processing/algs/qgis/ImportIntoSpatialite.py
  62. +2 −4 python/plugins/processing/algs/qgis/Intersection.py
  63. +2 −2 python/plugins/processing/algs/qgis/JoinAttributes.py
  64. +2 −2 python/plugins/processing/algs/qgis/LinesIntersection.py
  65. +1 −1 python/plugins/processing/algs/qgis/LinesToPolygons.py
  66. +1 −2 python/plugins/processing/algs/qgis/MeanAndStdDevPlot.py
  67. +1 −1 python/plugins/processing/algs/qgis/MeanCoords.py
  68. +1 −1 python/plugins/processing/algs/qgis/Merge.py
  69. +1 −2 python/plugins/processing/algs/qgis/MergeLines.py
  70. +1 −1 python/plugins/processing/algs/qgis/MultipartToSingleparts.py
  71. +1 −1 python/plugins/processing/algs/qgis/NearestNeighbourAnalysis.py
  72. +1 −2 python/plugins/processing/algs/qgis/OffsetLine.py
  73. +1 −2 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  74. +1 −2 python/plugins/processing/algs/qgis/Orthogonalize.py
  75. +2 −4 python/plugins/processing/algs/qgis/PointDistance.py
  76. +1 −2 python/plugins/processing/algs/qgis/PointOnSurface.py
  77. +1 −2 python/plugins/processing/algs/qgis/PointsAlongGeometry.py
  78. +1 −1 python/plugins/processing/algs/qgis/PointsDisplacement.py
  79. +1 −1 python/plugins/processing/algs/qgis/PointsFromLines.py
  80. +1 −1 python/plugins/processing/algs/qgis/PointsFromPolygons.py
  81. +2 −2 python/plugins/processing/algs/qgis/PointsInPolygon.py
  82. +2 −2 python/plugins/processing/algs/qgis/PointsInPolygonUnique.py
  83. +2 −2 python/plugins/processing/algs/qgis/PointsInPolygonWeighted.py
  84. +1 −1 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  85. +1 −2 python/plugins/processing/algs/qgis/PointsToPaths.py
  86. +1 −2 python/plugins/processing/algs/qgis/PolarPlot.py
  87. +1 −2 python/plugins/processing/algs/qgis/PoleOfInaccessibility.py
  88. +1 −2 python/plugins/processing/algs/qgis/PolygonCentroids.py
  89. +1 −1 python/plugins/processing/algs/qgis/Polygonize.py
  90. +1 −1 python/plugins/processing/algs/qgis/PolygonsToLines.py
  91. +1 −1 python/plugins/processing/algs/qgis/RandomExtract.py
  92. +1 −1 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  93. +1 −2 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  94. +1 −2 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  95. +1 −2 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  96. +1 −2 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  97. +1 −1 python/plugins/processing/algs/qgis/RandomSelection.py
  98. +1 −1 python/plugins/processing/algs/qgis/RandomSelectionWithinSubsets.py
  99. +1 −1 python/plugins/processing/algs/qgis/RasterCalculator.py
  100. +1 −2 python/plugins/processing/algs/qgis/RasterLayerHistogram.py
  101. +1 −1 python/plugins/processing/algs/qgis/RasterLayerStatistics.py
  102. +1 −2 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  103. +1 −2 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  104. +1 −2 python/plugins/processing/algs/qgis/RemoveNullGeometry.py
  105. +1 −1 python/plugins/processing/algs/qgis/ReprojectLayer.py
  106. +1 −2 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  107. +1 −1 python/plugins/processing/algs/qgis/SaveSelectedFeatures.py
  108. +1 −1 python/plugins/processing/algs/qgis/SelectByAttribute.py
  109. +1 −1 python/plugins/processing/algs/qgis/SelectByAttributeSum.py
  110. +1 −1 python/plugins/processing/algs/qgis/SelectByExpression.py
  111. +2 −2 python/plugins/processing/algs/qgis/SelectByLocation.py
  112. +2 −4 python/plugins/processing/algs/qgis/ServiceAreaFromLayer.py
  113. +1 −2 python/plugins/processing/algs/qgis/ServiceAreaFromPoint.py
  114. +1 −1 python/plugins/processing/algs/qgis/SetRasterStyle.py
  115. +1 −1 python/plugins/processing/algs/qgis/SetVectorStyle.py
  116. +2 −4 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  117. +2 −4 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  118. +1 −2 python/plugins/processing/algs/qgis/ShortestPathPointToPoint.py
  119. +1 −1 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  120. +1 −1 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  121. +1 −2 python/plugins/processing/algs/qgis/SingleSidedBuffer.py
  122. +1 −2 python/plugins/processing/algs/qgis/Smooth.py
  123. +2 −2 python/plugins/processing/algs/qgis/SnapGeometries.py
  124. +1 −1 python/plugins/processing/algs/qgis/SpatialIndex.py
  125. +2 −4 python/plugins/processing/algs/qgis/SpatialJoin.py
  126. +2 −2 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  127. +2 −2 python/plugins/processing/algs/qgis/SplitWithLines.py
  128. +1 −1 python/plugins/processing/algs/qgis/StatisticsByCategories.py
  129. +2 −2 python/plugins/processing/algs/qgis/SumLines.py
  130. +2 −4 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  131. +1 −1 python/plugins/processing/algs/qgis/TextToFloat.py
  132. +1 −1 python/plugins/processing/algs/qgis/TinInterpolation.py
  133. +1 −2 python/plugins/processing/algs/qgis/TopoColors.py
  134. +1 −2 python/plugins/processing/algs/qgis/Translate.py
  135. +1 −1 python/plugins/processing/algs/qgis/TruncateTable.py
  136. +2 −2 python/plugins/processing/algs/qgis/Union.py
  137. +1 −1 python/plugins/processing/algs/qgis/UniqueValues.py
  138. +1 −1 python/plugins/processing/algs/qgis/VariableDistanceBuffer.py
  139. +1 −2 python/plugins/processing/algs/qgis/VectorLayerHistogram.py
  140. +1 −2 python/plugins/processing/algs/qgis/VectorLayerScatterplot.py
  141. +1 −2 python/plugins/processing/algs/qgis/VectorLayerScatterplot3D.py
  142. +1 −2 python/plugins/processing/algs/qgis/VectorSplit.py
  143. +1 −1 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  144. +1 −1 python/plugins/processing/algs/qgis/ZonalStatistics.py
  145. +2 −2 python/plugins/processing/algs/qgis/ZonalStatisticsQgis.py
  146. +1 −1 python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
  147. +1 −1 python/plugins/processing/algs/qgis/scripts/Keep_n_biggest_parts.py
  148. +1 −1 python/plugins/processing/algs/qgis/scripts/Number_of_unique_values_in_classes.py
  149. +2 −1 python/plugins/processing/algs/qgis/ui/HeatmapWidgets.py
  150. +7 −5 python/plugins/processing/algs/saga/SagaAlgorithm.py
  151. +9 −6 python/plugins/processing/core/GeoAlgorithm.py
  152. +18 −12 python/plugins/processing/core/parameters.py
  153. +2 −1 python/plugins/processing/gui/AlgorithmDialog.py
  154. +1 −1 python/plugins/processing/gui/AlgorithmExecutor.py
  155. +4 −2 python/plugins/processing/gui/wrappers.py
  156. +1 −1 python/plugins/processing/tests/testdata/scripts/centroids.py
  157. +2 −22 python/plugins/processing/tools/dataobjects.py
  158. +2 −1 python/plugins/processing/tools/vector.py
  159. +29 −0 src/core/processing/qgsprocessingutils.cpp
  160. +2 −0 src/core/processing/qgsprocessingutils.h
@@ -90,6 +90,11 @@ class QgsProcessingUtils
:rtype: QgsMapLayer
%End

static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true );
%Docstring
:rtype: QgsMapLayer
%End

static QString normalizeLayerSource( const QString &source );
%Docstring
Normalizes a layer ``source`` string for safe comparison across different
@@ -92,8 +92,8 @@ def processAlgorithm(self, context, feedback):
# Input layers vales are always a string with its location.
# That string can be converted into a QGIS layer (a
# QgsVectorLayer in this case) using the
# dataobjects.getLayerFromString() method.
vectorLayer = dataobjects.getLayerFromString(inputFilename)
# dataobjects.QgsProcessingUtils.mapLayerFromString() method.
vectorLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(inputFilename, context)

# And now we can process

@@ -103,8 +103,8 @@ def defineCharacteristics(self):
def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
mask = self.getParameterValue(self.MASK)
maskLayer = dataobjects.getLayerFromString(
self.getParameterValue(self.MASK))
context = dataobjects.createContext()
maskLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.MASK), context)
ogrMask = ogrConnectionString(mask)[1:-1]
noData = self.getParameterValue(self.NO_DATA)
opts = self.getParameterValue(self.OPTIONS)
@@ -69,8 +69,9 @@ def defineCharacteristics(self):
self.tr('Existing raster layer'), False))

def getConsoleCommands(self):
inLayer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
inRasterLayer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_RASTER))
context = dataobjects.createContext()
inLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
inRasterLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_RASTER), context)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrRasterLayer = ogrConnectionString(inRasterLayer)[1:-1]
@@ -219,22 +219,23 @@ def defineCharacteristicsFromFile(self):
self.addParameter(param)

def getDefaultCellsize(self):
context = dataobjects.createContext()
cellsize = 0
for param in self.parameters:
if param.value:
if isinstance(param, ParameterRaster):
if isinstance(param.value, QgsRasterLayer):
layer = param.value
else:
layer = dataobjects.getLayerFromString(param.value)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(param.value, context)
cellsize = max(cellsize, (layer.extent().xMaximum() -
layer.extent().xMinimum()) /
layer.width())
elif isinstance(param, ParameterMultipleInput):

layers = param.value.split(';')
for layername in layers:
layer = dataobjects.getLayerFromString(layername)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(layername, context)
if isinstance(layer, QgsRasterLayer):
cellsize = max(cellsize, (
layer.extent().xMaximum() -
@@ -507,16 +508,17 @@ def processOutputs(self):
self.outputCommands.append(command)

def exportVectorLayer(self, orgFilename):
context = dataobjects.createContext()

# TODO: improve this. We are now exporting if it is not a shapefile,
# but the functionality of v.in.ogr could be used for this.
# We also export if there is a selection
if not os.path.exists(orgFilename) or not orgFilename.endswith('shp'):
layer = dataobjects.getLayerFromString(orgFilename, False)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(orgFilename, context, False)
if layer:
filename = dataobjects.exportVectorLayer(layer)
else:
layer = dataobjects.getLayerFromString(orgFilename, False)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(orgFilename, context, False)
if layer:
useSelection = \
ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
@@ -549,8 +551,9 @@ def setSessionProjectionFromProject(self, commands):
Grass7Utils.projectionSet = True

def setSessionProjectionFromLayer(self, layer, commands):
context = dataobjects.createContext()
if not Grass7Utils.projectionSet:
qGisLayer = dataobjects.getLayerFromString(layer)
qGisLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(layer, context)
if qGisLayer:
proj4 = str(qGisLayer.crs().toProj4())
command = 'g.proj'
@@ -167,21 +167,22 @@ def exportRasterLayer(self, layer):

def getDefaultCellsize(self):
cellsize = 0
context = dataobjects.createContext()
for param in self.parameters:
if param.value:
if isinstance(param, ParameterRaster):
if isinstance(param.value, QgsRasterLayer):
layer = param.value
else:
layer = dataobjects.getLayerFromString(param.value)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(param.value, context)
cellsize = max(cellsize, (layer.extent().xMaximum() -
layer.extent().xMinimum()) /
layer.width())
elif isinstance(param, ParameterMultipleInput):

layers = param.value.split(';')
for layername in layers:
layer = dataobjects.getLayerFromString(layername)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(layername, context)
if isinstance(layer, QgsRasterLayer):
cellsize = max(cellsize, (
layer.extent().xMaximum() -
@@ -91,8 +91,7 @@ def processAlgorithm(self, context, feedback):
fieldPrecision = self.getParameterValue(self.FIELD_PRECISION)
output = self.getOutputFromName(self.OUTPUT_LAYER)

layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

fields = layer.fields()
fields.append(QgsField(fieldName, self.TYPES[fieldType], '',
@@ -64,7 +64,7 @@ def defineCharacteristics(self):
def processAlgorithm(self, context, feedback):
output = self.getOutputFromName(self.OUTPUT)
vlayer = \
dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
fields = vlayer.fields()
fields.append(QgsField('AUTO', QVariant.Int))
writer = output.getVectorWriter(fields, vlayer.wkbType(), vlayer.crs(), context)
@@ -74,8 +74,7 @@ def defineCharacteristics(self):
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Bar plot')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
namefieldname = self.getParameterValue(self.NAME_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)

@@ -122,8 +122,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
field_name = self.getParameterValue(self.FIELD_NAME)
field = layer.fields().at(layer.fields().lookupField(field_name))

@@ -116,8 +116,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
fieldName = self.getParameterValue(self.FIELD_NAME)

outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
@@ -102,8 +102,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.MAX_VALUE, self.tr('Maximum string value')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
fieldName = self.getParameterValue(self.FIELD_NAME)

outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
@@ -64,8 +64,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Boundary')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

input_wkb = layer.wkbType()
if QgsWkbTypes.geometryType(input_wkb) == QgsWkbTypes.LineGeometry:
@@ -63,8 +63,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Bounds'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields().toList(), QgsWkbTypes.Polygon, layer.crs(), context)
@@ -83,8 +83,7 @@ def defineCharacteristics(self):
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Box plot')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
namefieldname = self.getParameterValue(self.NAME_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)

@@ -65,8 +65,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Centroids'), datatype=[dataobjects.TYPE_VECTOR_POINT]))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT_LAYER))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields(), QgsWkbTypes.Point, layer.crs(), context)
@@ -100,8 +100,7 @@ def processAlgorithm(self, context, feedback):
settings.setValue(settings_method_key, initial_method_setting)

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

settings = QgsSettings()
method = int(settings.value(settings_method_key, 1))
@@ -70,10 +70,8 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(Clip.OUTPUT, self.tr('Clipped')))

def processAlgorithm(self, context, feedback):
source_layer = dataobjects.getLayerFromString(
self.getParameterValue(Clip.INPUT))
mask_layer = dataobjects.getLayerFromString(
self.getParameterValue(Clip.OVERLAY))
source_layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(Clip.INPUT), context)
mask_layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(Clip.OVERLAY), context)

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(source_layer.fields(),
QgsWkbTypes.multiType(source_layer.wkbType()),
@@ -79,15 +79,15 @@ def defineCharacteristics(self):
OutputVector(ConcaveHull.OUTPUT, self.tr('Concave hull'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(self.getParameterValue(ConcaveHull.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(ConcaveHull.INPUT), context)
alpha = self.getParameterValue(self.ALPHA)
holes = self.getParameterValue(self.HOLES)
no_multigeom = self.getParameterValue(self.NO_MULTIGEOMETRY)

# Delaunay triangulation from input point layer
feedback.setProgressText(self.tr('Creating Delaunay triangles...'))
delone_triangles = processing.run("qgis:delaunaytriangulation", layer, None)['OUTPUT']
delaunay_layer = dataobjects.getLayerFromString(delone_triangles)
delaunay_layer = dataobjects.QgsProcessingUtils.mapLayerFromString(delone_triangles, context)

# Get max edge length from Delaunay triangles
feedback.setProgressText(self.tr('Computing edges max length...'))
@@ -127,7 +127,7 @@ def processAlgorithm(self, context, feedback):
feedback.setProgressText(self.tr('Dissolving Delaunay triangles...'))
dissolved = processing.run("qgis:dissolve", delaunay_layer,
True, None, None)['OUTPUT']
dissolved_layer = dataobjects.getLayerFromString(dissolved)
dissolved_layer = dataobjects.QgsProcessingUtils.mapLayerFromString(dissolved, context)

# Save result
feedback.setProgressText(self.tr('Saving data...'))
@@ -77,8 +77,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT, self.tr('Convex hull'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
useField = self.getParameterValue(self.METHOD) == 1
fieldName = self.getParameterValue(self.FIELD)

@@ -68,7 +68,7 @@ def defineCharacteristics(self):

def processAlgorithm(self, context, feedback):
file_name = self.getParameterValue(self.INPUT)
layer = dataobjects.getLayerFromString(file_name)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(file_name, context)
field = self.getParameterValue(self.FIELD)
provider = layer.dataProvider()

@@ -68,8 +68,7 @@ def defineCharacteristics(self):
self.tr('Constant')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
value = self.getParameterValue(self.NUMBER)

output = self.getOutputFromName(self.OUTPUT)
@@ -75,7 +75,7 @@ def defineCharacteristics(self):

def processAlgorithm(self, context, feedback):
fileName = self.getParameterValue(self.INPUT)
layer = dataobjects.getLayerFromString(fileName)
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(fileName, context)
crs = QgsCoordinateReferenceSystem(self.getParameterValue(self.CRS))

provider = layer.dataProvider()
@@ -70,8 +70,7 @@ def defineCharacteristics(self):
datatype=[dataobjects.TYPE_VECTOR_POLYGON]))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)

fields = [QgsField('POINTA', QVariant.Double, '', 24, 15),
QgsField('POINTB', QVariant.Double, '', 24, 15),
@@ -66,7 +66,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT, self.tr('Output layer')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)

fields_to_delete = self.getParameterValue(self.COLUMNS).split(';')
fields = layer.fields()
@@ -60,8 +60,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT, self.tr('Cleaned')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)

fields = layer.fields()

@@ -66,8 +66,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT, self.tr('Cleaned'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
min_area = self.getParameterValue(self.MIN_AREA)
if min_area is not None:
try:
@@ -78,8 +78,7 @@ def defineCharacteristics(self):
self.tr('Densified')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
vertices = self.getParameterValue(self.VERTICES)

isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry
@@ -73,7 +73,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT, self.tr('Densified')))

def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
interval = self.getParameterValue(self.INTERVAL)

isPolygon = layer.geometryType() == QgsWkbTypes.PolygonGeometry

0 comments on commit f84d703

Please sign in to comment.