mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Use sample instead of identify in raster sampling alg
About 25x faster on large layers
This commit is contained in:
parent
0f41ca9e13
commit
8b2d5d0374
@ -31,7 +31,8 @@ import os
|
||||
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 @@ class RasterSampling(QgisAlgorithm):
|
||||
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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user