Skip to content

Commit e19e1de

Browse files
committedJul 28, 2018
[processing] be more flexible with multipoint layers, allow sampling for single part point
1 parent 3e31a65 commit e19e1de

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎python/plugins/processing/algs/qgis/RasterSampling.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
QgsField,
3737
QgsFeatureSink,
3838
QgsRaster,
39+
QgsPointXY,
3940
QgsProcessing,
4041
QgsProcessingParameterRasterLayer,
4142
QgsProcessingParameterString,
@@ -160,13 +161,18 @@ def processAlgorithm(self, parameters, context, feedback):
160161

161162
attrs = i.attributes()
162163

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

168170
# get the feature geometry as point
169-
point = i.geometry().asPoint()
171+
point = QgsPointXY()
172+
if i.geometry().isMultipart():
173+
point = i.geometry().asMultiPoint()[0]
174+
else:
175+
point = i.geometry().asPoint()
170176

171177
# reproject to raster crs
172178
try:

0 commit comments

Comments
 (0)
Please sign in to comment.