Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make column prefix as advanced parameter
  • Loading branch information
ghtmtt committed Jul 12, 2018
1 parent 4dbfe36 commit efa2365
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions python/plugins/processing/algs/qgis/RasterSampling.py
Expand Up @@ -38,6 +38,7 @@
QgsProcessing,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterString,
QgsProcessingParameterDefinition,
QgsFields,
QgsProcessingUtils,
QgsProcessingException,
Expand Down Expand Up @@ -85,12 +86,12 @@ def initAlgorithm(self, config=None):
)
)

self.addParameter(
QgsProcessingParameterString(
self.COLUMN_PREFIX,
self.tr('Output column prefix'), 'rvalue'
)
columnPrefix = QgsProcessingParameterString(
self.COLUMN_PREFIX,
self.tr('Output column prefix'), 'rvalue'
)
columnPrefix.setFlags(columnPrefix.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(columnPrefix)

self.addParameter(
QgsProcessingParameterFeatureSink(
Expand All @@ -107,7 +108,7 @@ def processAlgorithm(self, parameters, context, feedback):
context
)

sampled_rasters = self.parameterAsRasterLayer(
sampled_raster = self.parameterAsRasterLayer(
parameters,
self.RASTERCOPY,
context
Expand All @@ -125,8 +126,8 @@ def processAlgorithm(self, parameters, context, feedback):
source_fields = source.fields()
raster_fields = QgsFields()

# append field to vector as rasterName_bandCount
for b in range(sampled_rasters.bandCount()):
# append field to vector as columnPrefix_bandCount
for b in range(sampled_raster.bandCount()):
raster_fields.append(QgsField(
columnPrefix + str('_{}'.format(b + 1)), QVariant.Double
)
Expand Down Expand Up @@ -155,20 +156,20 @@ def processAlgorithm(self, parameters, context, feedback):
if i.geometry().isMultipart():
raise QgsProcessingException(self.tr('''Impossible to sample data
of a Multipart layer. Please use the Multipart to single part
algoithm to transform the layer.'''))
algorithm to transform the layer.'''))

attrs = i.attributes()

if sampled_rasters.bandCount() > 1:
if sampled_raster.bandCount() > 1:

for b in range(sampled_rasters.bandCount()):
for b in range(sampled_raster.bandCount()):
attrs.append(
sampled_rasters.dataProvider().identify(i.geometry().asPoint(),
sampled_raster.dataProvider().identify(i.geometry().asPoint(),
QgsRaster.IdentifyFormatValue).results()[b + 1]
)

attrs.append(
sampled_rasters.dataProvider().identify(i.geometry().asPoint(),
sampled_raster.dataProvider().identify(i.geometry().asPoint(),
QgsRaster.IdentifyFormatValue).results()[1]
)

Expand Down

0 comments on commit efa2365

Please sign in to comment.