Skip to content

Commit

Permalink
Fix use of QgsProcessingUtils.mapLayerFromString
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 2, 2017
1 parent df1ead5 commit 49c688b
Show file tree
Hide file tree
Showing 156 changed files with 209 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.QgsProcessingUtils.mapLayerFromString() method.
vectorLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(inputFilename, context)
# QgsProcessingUtils.mapLayerFromString() method.
vectorLayer = QgsProcessingUtils.mapLayerFromString(inputFilename, context)

# And now we can process

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ClipByMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
mask = self.getParameterValue(self.MASK)
context = dataobjects.createContext()
maskLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.MASK), context)
maskLayer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.MASK), context)
ogrMask = ogrConnectionString(mask)[1:-1]
noData = self.getParameterValue(self.NO_DATA)
opts = self.getParameterValue(self.OPTIONS)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/rasterize_over.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def defineCharacteristics(self):

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

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrRasterLayer = ogrConnectionString(inRasterLayer)[1:-1]
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ def getDefaultCellsize(self):
if isinstance(param.value, QgsRasterLayer):
layer = param.value
else:
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(param.value, context)
layer = 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.QgsProcessingUtils.mapLayerFromString(layername, context)
layer = QgsProcessingUtils.mapLayerFromString(layername, context)
if isinstance(layer, QgsRasterLayer):
cellsize = max(cellsize, (
layer.extent().xMaximum() -
Expand Down Expand Up @@ -514,11 +514,11 @@ def exportVectorLayer(self, orgFilename):
# 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.QgsProcessingUtils.mapLayerFromString(orgFilename, context, False)
layer = QgsProcessingUtils.mapLayerFromString(orgFilename, context, False)
if layer:
filename = dataobjects.exportVectorLayer(layer)
else:
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(orgFilename, context, False)
layer = QgsProcessingUtils.mapLayerFromString(orgFilename, context, False)
if layer:
useSelection = \
ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
Expand Down Expand Up @@ -553,7 +553,7 @@ def setSessionProjectionFromProject(self, commands):
def setSessionProjectionFromLayer(self, layer, commands):
context = dataobjects.createContext()
if not Grass7Utils.projectionSet:
qGisLayer = dataobjects.QgsProcessingUtils.mapLayerFromString(layer, context)
qGisLayer = QgsProcessingUtils.mapLayerFromString(layer, context)
if qGisLayer:
proj4 = str(qGisLayer.crs().toProj4())
command = 'g.proj'
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass7/nviz7.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ def getDefaultCellsize(self):
if isinstance(param.value, QgsRasterLayer):
layer = param.value
else:
layer = dataobjects.QgsProcessingUtils.mapLayerFromString(param.value, context)
layer = 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.QgsProcessingUtils.mapLayerFromString(layername, context)
layer = QgsProcessingUtils.mapLayerFromString(layername, context)
if isinstance(layer, QgsRasterLayer):
cellsize = max(cellsize, (
layer.extent().xMaximum() -
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/AddTableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def processAlgorithm(self, context, feedback):
fieldPrecision = self.getParameterValue(self.FIELD_PRECISION)
output = self.getOutputFromName(self.OUTPUT_LAYER)

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

fields = layer.fields()
fields.append(QgsField(fieldName, self.TYPES[fieldType], '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def defineCharacteristics(self):
def processAlgorithm(self, context, feedback):
output = self.getOutputFromName(self.OUTPUT)
vlayer = \
dataobjects.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
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)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/BarPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def defineCharacteristics(self):
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Bar plot')))

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

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/BasicStatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))

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

outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.MAX_VALUE, self.tr('Maximum string value')))

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

outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Boundary')))

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

input_wkb = layer.wkbType()
if QgsWkbTypes.geometryType(input_wkb) == QgsWkbTypes.LineGeometry:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/BoundingBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +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.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields().toList(), QgsWkbTypes.Polygon, layer.crs(), context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/BoxPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def defineCharacteristics(self):
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Box plot')))

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

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +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.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(layer.fields(), QgsWkbTypes.Point, layer.crs(), context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/CheckValidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def processAlgorithm(self, context, feedback):
settings.setValue(settings_method_key, initial_method_setting)

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

settings = QgsSettings()
method = int(settings.value(settings_method_key, 1))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(Clip.OUTPUT, self.tr('Clipped')))

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

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(source_layer.fields(),
QgsWkbTypes.multiType(source_layer.wkbType()),
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/ConcaveHull.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.QgsProcessingUtils.mapLayerFromString(self.getParameterValue(ConcaveHull.INPUT), context)
layer = 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.QgsProcessingUtils.mapLayerFromString(delone_triangles, context)
delaunay_layer = QgsProcessingUtils.mapLayerFromString(delone_triangles, context)

# Get max edge length from Delaunay triangles
feedback.setProgressText(self.tr('Computing edges max length...'))
Expand Down Expand Up @@ -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.QgsProcessingUtils.mapLayerFromString(dissolved, context)
dissolved_layer = QgsProcessingUtils.mapLayerFromString(dissolved, context)

# Save result
feedback.setProgressText(self.tr('Saving data...'))
Expand Down