Skip to content

Commit

Permalink
Use sample instead of identify in raster sampling alg
Browse files Browse the repository at this point in the history
About 25x faster on large layers
  • Loading branch information
nyalldawson committed Jul 19, 2018
1 parent 0f41ca9 commit 8b2d5d0
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions python/plugins/processing/algs/qgis/RasterSampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8b2d5d0

Please sign in to comment.