Skip to content
Permalink
Browse files

single raster instead of multi

  • Loading branch information
ghtmtt committed Jul 12, 2018
1 parent eca6691 commit a4c0c2e5606fb6c7878678b0296217f77111fe62
Showing with 19 additions and 22 deletions.
  1. +19 −22 python/plugins/processing/algs/qgis/RasterSampling.py
@@ -36,7 +36,7 @@
QgsFeatureSink,
QgsRaster,
QgsProcessing,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterRasterLayer,
QgsFields,
QgsProcessingUtils,
QgsProcessingException,
@@ -77,10 +77,9 @@ def initAlgorithm(self, config=None):
)

self.addParameter(
QgsProcessingParameterMultipleLayers(
QgsProcessingParameterRasterLayer(
self.RASTERCOPY,
self.tr('Raster Layer to sample'),
QgsProcessing.TypeRaster
)
)

@@ -99,7 +98,7 @@ def processAlgorithm(self, parameters, context, feedback):
context
)

sampled_rasters = self.parameterAsLayerList(
sampled_rasters = self.parameterAsRasterLayer(
parameters,
self.RASTERCOPY,
context
@@ -112,11 +111,11 @@ def processAlgorithm(self, parameters, context, feedback):
raster_fields = QgsFields()

# append field to vector as rasterName_bandCount
for i in sampled_rasters:
for b in range(i.bandCount()):
raster_fields.append(QgsField(
os.path.splitext(os.path.basename(i.source()))[0] + str('_{}'.format(b + 1)), QVariant.Double)
for b in range(sampled_rasters.bandCount()):
raster_fields.append(QgsField(
'rvalue_' + str('{}'.format(b + 1)), QVariant.Double
)
)

# combine all the vector fields
out_fields = QgsProcessingUtils.combineFields(source_fields, raster_fields)
@@ -138,24 +137,22 @@ def processAlgorithm(self, parameters, context, feedback):

for n, i in enumerate(source.getFeatures()):

for rr in sampled_rasters:

attrs = i.attributes()
attrs = i.attributes()

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

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

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

i.setAttributes(attrs)
i.setAttributes(attrs)

sink.addFeature(i, QgsFeatureSink.FastInsert)
feedback.setProgress(int(n * total))

0 comments on commit a4c0c2e

Please sign in to comment.
You can’t perform that action at this time.