Skip to content

Commit

Permalink
Port create spatial index algorithm to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 27, 2017
1 parent f7b25a1 commit 856125d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -109,6 +109,7 @@
from .Smooth import Smooth from .Smooth import Smooth
from .SnapGeometries import SnapGeometriesToLayer from .SnapGeometries import SnapGeometriesToLayer
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
from .SpatialIndex import SpatialIndex
from .SumLines import SumLines from .SumLines import SumLines
from .SymmetricalDifference import SymmetricalDifference from .SymmetricalDifference import SymmetricalDifference
from .TextToFloat import TextToFloat from .TextToFloat import TextToFloat
Expand Down Expand Up @@ -155,7 +156,6 @@
# from .FieldsMapper import FieldsMapper # from .FieldsMapper import FieldsMapper
# from .Datasources2Vrt import Datasources2Vrt # from .Datasources2Vrt import Datasources2Vrt
# from .OrientedMinimumBoundingBox import OrientedMinimumBoundingBox # from .OrientedMinimumBoundingBox import OrientedMinimumBoundingBox
# from .SpatialIndex import SpatialIndex
# from .DefineProjection import DefineProjection # from .DefineProjection import DefineProjection
# from .RectanglesOvalsDiamondsVariable import RectanglesOvalsDiamondsVariable # from .RectanglesOvalsDiamondsVariable import RectanglesOvalsDiamondsVariable
# from .RectanglesOvalsDiamondsFixed import RectanglesOvalsDiamondsFixed # from .RectanglesOvalsDiamondsFixed import RectanglesOvalsDiamondsFixed
Expand Down Expand Up @@ -211,7 +211,7 @@ def getAlgs(self):
# SplitWithLines(), CreateConstantRaster(), # SplitWithLines(), CreateConstantRaster(),
# FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(), # FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
# OrientedMinimumBoundingBox(), # OrientedMinimumBoundingBox(),
# SpatialIndex(), DefineProjection(), # DefineProjection(),
# RectanglesOvalsDiamondsVariable(), # RectanglesOvalsDiamondsVariable(),
# RectanglesOvalsDiamondsFixed(), # RectanglesOvalsDiamondsFixed(),
# PointsAlongGeometry(), # PointsAlongGeometry(),
Expand Down Expand Up @@ -294,6 +294,7 @@ def getAlgs(self):
Smooth(), Smooth(),
SnapGeometriesToLayer(), SnapGeometriesToLayer(),
SpatialiteExecuteSQL(), SpatialiteExecuteSQL(),
SpatialIndex(),
SumLines(), SumLines(),
SymmetricalDifference(), SymmetricalDifference(),
TextToFloat(), TextToFloat(),
Expand Down
22 changes: 10 additions & 12 deletions python/plugins/processing/algs/qgis/SpatialIndex.py
Expand Up @@ -27,13 +27,12 @@


import os import os


from qgis.core import (QgsApplication, from qgis.core import (QgsVectorDataProvider,
QgsVectorDataProvider, QgsProcessingParameterVectorLayer,
QgsProcessingUtils) QgsProcessingOutputVectorLayer,
QgsProcessing)


from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm 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] pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]


Expand All @@ -50,10 +49,10 @@ def __init__(self):
super().__init__() super().__init__()


def initAlgorithm(self, config=None): def initAlgorithm(self, config=None):
self.addParameter(ParameterVector(self.INPUT, self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input Layer'))) self.tr('Input Layer'),
self.addOutput(OutputVector(self.OUTPUT, [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine]))
self.tr('Indexed layer'), True)) self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Indexed layer')))


def name(self): def name(self):
return 'createspatialindex' return 'createspatialindex'
Expand All @@ -62,8 +61,7 @@ def displayName(self):
return self.tr('Create spatial index') return self.tr('Create spatial index')


def processAlgorithm(self, parameters, context, feedback): def processAlgorithm(self, parameters, context, feedback):
fileName = self.getParameterValue(self.INPUT) layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
layer = QgsProcessingUtils.mapLayerFromString(fileName, context)
provider = layer.dataProvider() provider = layer.dataProvider()


if provider.capabilities() & QgsVectorDataProvider.CreateSpatialIndex: if provider.capabilities() & QgsVectorDataProvider.CreateSpatialIndex:
Expand All @@ -73,4 +71,4 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.pushInfo(self.tr("Layer's data provider does not support " feedback.pushInfo(self.tr("Layer's data provider does not support "
"spatial indexes")) "spatial indexes"))


self.setOutputValue(self.OUTPUT, fileName) return {self.OUTPUT: layer.id()}
26 changes: 13 additions & 13 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Expand Up @@ -2248,19 +2248,19 @@ tests:
type: vector type: vector
in_place_result: true in_place_result: true


# - algorithm: qgis:createspatialindex - algorithm: qgis:createspatialindex
# name: Create spatial index name: Create spatial index
# params: params:
# INPUT: INPUT:
# name: custom/points.shp name: custom/points.shp
# type: vector type: vector
# in_place: true in_place: true
# results: results:
# INPUT: INPUT:
# name: expected/create_attr_index_points.shp name: expected/create_attr_index_points.shp
# type: vector type: vector
# in_place_result: true in_place_result: true
#
# - algorithm: qgis:truncatetable # - algorithm: qgis:truncatetable
# name: Truncate table # name: Truncate table
# params: # params:
Expand Down

0 comments on commit 856125d

Please sign in to comment.