本文整理匯總了Python中qgis.analysis.QgsIDWInterpolator類的典型用法代碼示例。如果您正苦於以下問題:Python QgsIDWInterpolator類的具體用法?Python QgsIDWInterpolator怎麽用?Python QgsIDWInterpolator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QgsIDWInterpolator類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: processAlgorithm
def processAlgorithm(self, feedback):
interpolationData = self.getParameterValue(self.INTERPOLATION_DATA)
coefficient = self.getParameterValue(self.DISTANCE_COEFFICIENT)
columns = self.getParameterValue(self.COLUMNS)
rows = self.getParameterValue(self.ROWS)
cellsizeX = self.getParameterValue(self.CELLSIZE_X)
cellsizeY = self.getParameterValue(self.CELLSIZE_Y)
extent = self.getParameterValue(self.EXTENT).split(',')
output = self.getOutputValue(self.OUTPUT_LAYER)
if interpolationData is None:
raise GeoAlgorithmExecutionException(
self.tr('You need to specify at least one input layer.'))
xMin = float(extent[0])
xMax = float(extent[1])
yMin = float(extent[2])
yMax = float(extent[3])
bbox = QgsRectangle(xMin, yMin, xMax, yMax)
layerData = []
layers = []
for row in interpolationData.split(';'):
v = row.split(',')
data = QgsInterpolator.LayerData()
# need to keep a reference until interpolation is complete
layer = dataobjects.getLayerFromString(v[0])
data.vectorLayer = layer
layers.append(layer)
data.zCoordInterpolation = bool(v[1])
data.interpolationAttribute = int(v[2])
if v[3] == '0':
data.mInputType = QgsInterpolator.POINTS
elif v[3] == '1':
data.mInputType = QgsInterpolator.STRUCTURE_LINES
else:
data.mInputType = QgsInterpolator.BREAK_LINES
layerData.append(data)
interpolator = QgsIDWInterpolator(layerData)
interpolator.setDistanceCoefficient(coefficient)
writer = QgsGridFileWriter(interpolator,
output,
bbox,
columns,
rows,
cellsizeX,
cellsizeY)
writer.writeFile()
示例2: processAlgorithm
def processAlgorithm(self, parameters, context, feedback):
interpolationData = ParameterInterpolationData.parseValue(parameters[self.INTERPOLATION_DATA])
coefficient = self.parameterAsDouble(parameters, self.DISTANCE_COEFFICIENT, context)
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
pixel_size = self.parameterAsDouble(parameters, self.PIXEL_SIZE, context)
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
rows = self.parameterAsInt(parameters, self.ROWS, context)
if columns == 0:
columns = max(round(bbox.width() / pixel_size) + 1, 1)
if rows == 0:
rows = max(round(bbox.height() / pixel_size) + 1, 1)
if interpolationData is None:
raise QgsProcessingException(
self.tr('You need to specify at least one input layer.'))
layerData = []
layers = []
for row in interpolationData.split('::|::'):
v = row.split('::~::')
data = QgsInterpolator.LayerData()
# need to keep a reference until interpolation is complete
layer = QgsProcessingUtils.variantToSource(v[0], context)
data.source = layer
layers.append(layer)
data.valueSource = int(v[1])
data.interpolationAttribute = int(v[2])
if v[3] == '0':
data.sourceType = QgsInterpolator.SourcePoints
elif v[3] == '1':
data.sourceType = QgsInterpolator.SourceStructureLines
else:
data.sourceType = QgsInterpolator.SourceBreakLines
layerData.append(data)
interpolator = QgsIDWInterpolator(layerData)
interpolator.setDistanceCoefficient(coefficient)
writer = QgsGridFileWriter(interpolator,
output,
bbox,
columns,
rows)
writer.writeFile(feedback)
return {self.OUTPUT: output}
示例3: processAlgorithm
def processAlgorithm(self, parameters, context, feedback):
interpolationData = ParameterInterpolationData.parseValue(parameters[self.INTERPOLATION_DATA])
coefficient = self.parameterAsDouble(parameters, self.DISTANCE_COEFFICIENT, context)
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
rows = self.parameterAsInt(parameters, self.ROWS, context)
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
if interpolationData is None:
raise QgsProcessingException(
self.tr('You need to specify at least one input layer.'))
layerData = []
layers = []
for row in interpolationData.split(';'):
v = row.split(',')
data = QgsInterpolator.LayerData()
# need to keep a reference until interpolation is complete
layer = QgsProcessingUtils.mapLayerFromString(v[0], context)
data.vectorLayer = layer
layers.append(layer)
data.zCoordInterpolation = bool(v[1])
data.interpolationAttribute = int(v[2])
if v[3] == '0':
data.mInputType = QgsInterpolator.POINTS
elif v[3] == '1':
data.mInputType = QgsInterpolator.STRUCTURE_LINES
else:
data.mInputType = QgsInterpolator.BREAK_LINES
layerData.append(data)
interpolator = QgsIDWInterpolator(layerData)
interpolator.setDistanceCoefficient(coefficient)
writer = QgsGridFileWriter(interpolator,
output,
bbox,
columns,
rows,
cellsizeX,
cellsizeY)
writer.writeFile(feedback)
return {self.OUTPUT: output}
示例4: processAlgorithm
def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT_LAYER))
fieldName = self.getParameterValue(self.ATTRIBUTE)
layerType = self.getParameterValue(self.LAYER_TYPE)
coefficient = self.getParameterValue(self.DISTANCE_COEFFICIENT)
columns = self.getParameterValue(self.COLUMNS)
rows = self.getParameterValue(self.ROWS)
cellsizeX = self.getParameterValue(self.CELLSIZE_X)
cellsizeY = self.getParameterValue(self.CELLSIZE_Y)
extent = self.getParameterValue(self.EXTENT).split(',')
output = self.getOutputValue(self.OUTPUT_LAYER)
xMin = float(extent[0])
xMax = float(extent[1])
yMin = float(extent[2])
yMax = float(extent[3])
bbox = QgsRectangle(xMin, yMin, xMax, yMax)
layerData = QgsInterpolator.LayerData()
layerData.vectorLayer = layer
layerData.zCoordInterpolation = False
layerData.interpolationAttribute = layer.dataProvider().fieldNameIndex(fieldName)
if layerType == 0:
layerData.mInputType = QgsInterpolator.POINTS
elif layerType == 1:
layerData.mInputType = QgsInterpolator.STRUCTURE_LINES
else:
layerData.mInputType = QgsInterpolator.BREAK_LINES
interpolator = QgsIDWInterpolator([layerData])
interpolator.setDistanceCoefficient(coefficient)
writer = QgsGridFileWriter(interpolator,
output,
bbox,
columns,
rows,
cellsizeX,
cellsizeY)
writer.writeFile()