Skip to content
Permalink
Browse files

Port create spatial index algorithm to new API

  • Loading branch information
nyalldawson committed Jul 27, 2017
1 parent f7b25a1 commit 856125d366826400dd9e584eaaa11c89c30e33b7
@@ -109,6 +109,7 @@
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 .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 @@ def getAlgs(self):
# SplitWithLines(), CreateConstantRaster(),
# FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
# OrientedMinimumBoundingBox(),
# SpatialIndex(), DefineProjection(),
# DefineProjection(),
# RectanglesOvalsDiamondsVariable(),
# RectanglesOvalsDiamondsFixed(),
# PointsAlongGeometry(),
@@ -294,6 +294,7 @@ def getAlgs(self):
Smooth(),
SnapGeometriesToLayer(),
SpatialiteExecuteSQL(),
SpatialIndex(),
SumLines(),
SymmetricalDifference(),
TextToFloat(),
@@ -27,13 +27,12 @@

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 @@ def __init__(self):
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 @@ def displayName(self):
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 @@ def processAlgorithm(self, parameters, context, feedback):
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:

0 comments on commit 856125d

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