Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] be more flexible with multipoint layers, allow sampling …
…for single part point
  • Loading branch information
nirvn committed Jul 28, 2018
1 parent 3e31a65 commit e19e1de
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions python/plugins/processing/algs/qgis/RasterSampling.py
Expand Up @@ -36,6 +36,7 @@
QgsField,
QgsFeatureSink,
QgsRaster,
QgsPointXY,
QgsProcessing,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterString,
Expand Down Expand Up @@ -160,13 +161,18 @@ def processAlgorithm(self, parameters, context, feedback):

attrs = i.attributes()

if i.geometry().isMultipart():
raise QgsProcessingException(self.tr('''Impossible to sample data
of a Multipart layer. Please use the Multipart to single part
algorithm to transform the layer.'''))
if i.geometry().isMultipart() and i.geometry().constGet().partCount() > 1:
sink.addFeature(i, QgsFeatureSink.FastInsert)
feedback.setProgress(int(n * total))
feedback.reportError(self.tr('Impossible to sample data of multipart feature {}.').format(i.id()))
continue

# get the feature geometry as point
point = i.geometry().asPoint()
point = QgsPointXY()
if i.geometry().isMultipart():
point = i.geometry().asMultiPoint()[0]
else:
point = i.geometry().asPoint()

# reproject to raster crs
try:
Expand Down

0 comments on commit e19e1de

Please sign in to comment.