Skip to content
Permalink
Browse files

Use sample instead of identify in raster sampling alg

About 25x faster on large layers
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 0f41ca9 commit 8b2d5d0374337c702fea8d7a19ffb5bd757db9f4
Showing with 8 additions and 15 deletions.
  1. +8 −15 python/plugins/processing/algs/qgis/RasterSampling.py
@@ -31,7 +31,8 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import (QgsApplication,
from qgis.core import (NULL,
QgsApplication,
QgsField,
QgsFeatureSink,
QgsRaster,
@@ -179,20 +180,12 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.reportError(self.tr('Could not reproject feature {} to raster CRS').format(i.id()))
continue

if sampled_raster.bandCount() > 1:

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

attrs.append(
sampled_raster.dataProvider().identify(
point,
QgsRaster.IdentifyFormatValue).results()[1]
)
for b in range(sampled_raster.bandCount()):
value, ok = sampled_raster.dataProvider().sample(point, b + 1)
if ok:
attrs.append(value)
else:
attrs.append(NULL)

i.setAttributes(attrs)

0 comments on commit 8b2d5d0

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