mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Port Truncate alg to new API
This commit is contained in:
parent
856125d366
commit
504cc1f390
@ -114,6 +114,7 @@ from .SumLines import SumLines
|
||||
from .SymmetricalDifference import SymmetricalDifference
|
||||
from .TextToFloat import TextToFloat
|
||||
from .Translate import Translate
|
||||
from .TruncateTable import TruncateTable
|
||||
from .Union import Union
|
||||
from .UniqueValues import UniqueValues
|
||||
from .VectorSplit import VectorSplit
|
||||
@ -165,7 +166,6 @@ from .ZonalStatistics import ZonalStatistics
|
||||
# from .TinInterpolation import TinInterpolation
|
||||
# from .ExtractSpecificNodes import ExtractSpecificNodes
|
||||
# from .RasterCalculator import RasterCalculator
|
||||
# from .TruncateTable import TruncateTable
|
||||
# from .Polygonize import Polygonize
|
||||
# from .ExecuteSQL import ExecuteSQL
|
||||
# from .FindProjection import FindProjection
|
||||
@ -202,10 +202,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
# StatisticsByCategories(),
|
||||
# RasterLayerStatistics(), PointsDisplacement(),
|
||||
# PointsFromPolygons(),
|
||||
# PointsFromLines(), RandomPointsExtent(),
|
||||
# RandomPointsLayer(), RandomPointsPolygonsFixed(),
|
||||
# RandomPointsPolygonsVariable(),
|
||||
# RandomPointsAlongLines(), PointsToPaths(),
|
||||
# PointsFromLines(), PointsToPaths(),
|
||||
# SetVectorStyle(), SetRasterStyle(),
|
||||
# HypsometricCurves(),
|
||||
# SplitWithLines(), CreateConstantRaster(),
|
||||
@ -219,9 +216,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
# IdwInterpolation(), TinInterpolation(),
|
||||
# ExtractSpecificNodes(),
|
||||
# RasterCalculator(),
|
||||
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
|
||||
# ShortestPathLayerToPoint(), ServiceAreaFromPoint(),
|
||||
# ServiceAreaFromLayer(), TruncateTable(), Polygonize(),
|
||||
# Polygonize(),
|
||||
# ExecuteSQL(), FindProjection(),
|
||||
# TopoColor(), EliminateSelection()
|
||||
# ]
|
||||
@ -299,6 +294,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
SymmetricalDifference(),
|
||||
TextToFloat(),
|
||||
Translate(),
|
||||
TruncateTable(),
|
||||
Union(),
|
||||
UniqueValues(),
|
||||
VectorSplit(),
|
||||
|
@ -25,13 +25,10 @@ __copyright__ = '(C) 2017, Nyall Dawson'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsFeatureSink,
|
||||
QgsProcessingUtils)
|
||||
from qgis.core import (QgsProcessingParameterVectorLayer,
|
||||
QgsProcessingOutputVectorLayer,
|
||||
QgsProcessingException)
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
from processing.core.outputs import OutputVector
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
|
||||
|
||||
class TruncateTable(QgisAlgorithm):
|
||||
@ -49,10 +46,9 @@ class TruncateTable(QgisAlgorithm):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(ParameterTable(self.INPUT,
|
||||
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
|
||||
self.tr('Input Layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT,
|
||||
self.tr('Truncated layer'), True))
|
||||
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Truncated layer')))
|
||||
|
||||
def name(self):
|
||||
return 'truncatetable'
|
||||
@ -61,12 +57,11 @@ class TruncateTable(QgisAlgorithm):
|
||||
return self.tr('Truncate table')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
file_name = self.getParameterValue(self.INPUT)
|
||||
layer = QgsProcessingUtils.mapLayerFromString(file_name, context)
|
||||
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
|
||||
provider = layer.dataProvider()
|
||||
|
||||
if not provider.truncate():
|
||||
raise GeoAlgorithmExecutionException(
|
||||
raise QgsProcessingException(
|
||||
self.tr('Could not truncate table.'))
|
||||
|
||||
self.setOutputValue(self.OUTPUT, file_name)
|
||||
return {self.OUTPUT: layer.id()}
|
||||
|
@ -256,7 +256,7 @@ class AlgorithmsTest(object):
|
||||
expected_lyr = self.load_layer(id, expected_result)
|
||||
if 'in_place_result' in expected_result:
|
||||
result_lyr = QgsProcessingUtils.mapLayerFromString(self.in_place_layers[id], context)
|
||||
self.assertTrue(result_lyr, self.in_place_layers[id])
|
||||
self.assertTrue(result_lyr.isValid(), self.in_place_layers[id])
|
||||
else:
|
||||
try:
|
||||
results[id]
|
||||
|
@ -2261,18 +2261,18 @@ tests:
|
||||
type: vector
|
||||
in_place_result: true
|
||||
|
||||
# - algorithm: qgis:truncatetable
|
||||
# name: Truncate table
|
||||
# params:
|
||||
# INPUT:
|
||||
# name: custom/points.shp
|
||||
# type: vector
|
||||
# in_place: true
|
||||
# results:
|
||||
# INPUT:
|
||||
# name: expected/truncated.shp
|
||||
# type: vector
|
||||
# in_place_result: true
|
||||
- algorithm: qgis:truncatetable
|
||||
name: Truncate table
|
||||
params:
|
||||
INPUT:
|
||||
name: custom/points.shp
|
||||
type: vector
|
||||
in_place: true
|
||||
results:
|
||||
INPUT:
|
||||
name: expected/truncated.shp
|
||||
type: vector
|
||||
in_place_result: true
|
||||
|
||||
- algorithm: qgis:distancematrix
|
||||
name: Distance matrix (only tests for run, does not check result as rows are in random order)
|
||||
|
Loading…
x
Reference in New Issue
Block a user