mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Port create spatial index algorithm to new API
This commit is contained in:
parent
f7b25a17b1
commit
856125d366
@ -109,6 +109,7 @@ from .Slope import Slope
|
||||
from .Smooth import Smooth
|
||||
from .SnapGeometries import SnapGeometriesToLayer
|
||||
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
|
||||
from .SpatialIndex import SpatialIndex
|
||||
from .SumLines import SumLines
|
||||
from .SymmetricalDifference import SymmetricalDifference
|
||||
from .TextToFloat import TextToFloat
|
||||
@ -155,7 +156,6 @@ from .ZonalStatistics import ZonalStatistics
|
||||
# from .FieldsMapper import FieldsMapper
|
||||
# from .Datasources2Vrt import Datasources2Vrt
|
||||
# from .OrientedMinimumBoundingBox import OrientedMinimumBoundingBox
|
||||
# from .SpatialIndex import SpatialIndex
|
||||
# from .DefineProjection import DefineProjection
|
||||
# from .RectanglesOvalsDiamondsVariable import RectanglesOvalsDiamondsVariable
|
||||
# from .RectanglesOvalsDiamondsFixed import RectanglesOvalsDiamondsFixed
|
||||
@ -211,7 +211,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
# SplitWithLines(), CreateConstantRaster(),
|
||||
# FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
|
||||
# OrientedMinimumBoundingBox(),
|
||||
# SpatialIndex(), DefineProjection(),
|
||||
# DefineProjection(),
|
||||
# RectanglesOvalsDiamondsVariable(),
|
||||
# RectanglesOvalsDiamondsFixed(),
|
||||
# PointsAlongGeometry(),
|
||||
@ -294,6 +294,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
Smooth(),
|
||||
SnapGeometriesToLayer(),
|
||||
SpatialiteExecuteSQL(),
|
||||
SpatialIndex(),
|
||||
SumLines(),
|
||||
SymmetricalDifference(),
|
||||
TextToFloat(),
|
||||
|
@ -27,13 +27,12 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsVectorDataProvider,
|
||||
QgsProcessingUtils)
|
||||
from qgis.core import (QgsVectorDataProvider,
|
||||
QgsProcessingParameterVectorLayer,
|
||||
QgsProcessingOutputVectorLayer,
|
||||
QgsProcessing)
|
||||
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.outputs import OutputVector
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
|
||||
@ -50,10 +49,10 @@ class SpatialIndex(QgisAlgorithm):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(ParameterVector(self.INPUT,
|
||||
self.tr('Input Layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT,
|
||||
self.tr('Indexed layer'), True))
|
||||
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
|
||||
self.tr('Input Layer'),
|
||||
[QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine]))
|
||||
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))
|
||||
|
||||
def name(self):
|
||||
return 'createspatialindex'
|
||||
@ -62,8 +61,7 @@ class SpatialIndex(QgisAlgorithm):
|
||||
return self.tr('Create spatial index')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
fileName = self.getParameterValue(self.INPUT)
|
||||
layer = QgsProcessingUtils.mapLayerFromString(fileName, context)
|
||||
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
|
||||
provider = layer.dataProvider()
|
||||
|
||||
if provider.capabilities() & QgsVectorDataProvider.CreateSpatialIndex:
|
||||
@ -73,4 +71,4 @@ class SpatialIndex(QgisAlgorithm):
|
||||
feedback.pushInfo(self.tr("Layer's data provider does not support "
|
||||
"spatial indexes"))
|
||||
|
||||
self.setOutputValue(self.OUTPUT, fileName)
|
||||
return {self.OUTPUT: layer.id()}
|
||||
|
@ -2248,19 +2248,19 @@ tests:
|
||||
type: vector
|
||||
in_place_result: true
|
||||
|
||||
# - algorithm: qgis:createspatialindex
|
||||
# name: Create spatial index
|
||||
# params:
|
||||
# INPUT:
|
||||
# name: custom/points.shp
|
||||
# type: vector
|
||||
# in_place: true
|
||||
# results:
|
||||
# INPUT:
|
||||
# name: expected/create_attr_index_points.shp
|
||||
# type: vector
|
||||
# in_place_result: true
|
||||
#
|
||||
- algorithm: qgis:createspatialindex
|
||||
name: Create spatial index
|
||||
params:
|
||||
INPUT:
|
||||
name: custom/points.shp
|
||||
type: vector
|
||||
in_place: true
|
||||
results:
|
||||
INPUT:
|
||||
name: expected/create_attr_index_points.shp
|
||||
type: vector
|
||||
in_place_result: true
|
||||
|
||||
# - algorithm: qgis:truncatetable
|
||||
# name: Truncate table
|
||||
# params:
|
||||
|
Loading…
x
Reference in New Issue
Block a user