Skip to content
Permalink
Browse files

Port Truncate alg to new API

  • Loading branch information
nyalldawson committed Jul 27, 2017
1 parent 856125d commit 504cc1f390b1ae8b2365d14a658aa3ed17791d7e
@@ -114,6 +114,7 @@
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 .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 @@ def getAlgs(self):
# StatisticsByCategories(),
# RasterLayerStatistics(), PointsDisplacement(),
# PointsFromPolygons(),
# PointsFromLines(), RandomPointsExtent(),
# RandomPointsLayer(), RandomPointsPolygonsFixed(),
# RandomPointsPolygonsVariable(),
# RandomPointsAlongLines(), PointsToPaths(),
# PointsFromLines(), PointsToPaths(),
# SetVectorStyle(), SetRasterStyle(),
# HypsometricCurves(),
# SplitWithLines(), CreateConstantRaster(),
@@ -219,9 +216,7 @@ def getAlgs(self):
# IdwInterpolation(), TinInterpolation(),
# ExtractSpecificNodes(),
# RasterCalculator(),
# ShortestPathPointToPoint(), ShortestPathPointToLayer(),
# ShortestPathLayerToPoint(), ServiceAreaFromPoint(),
# ServiceAreaFromLayer(), TruncateTable(), Polygonize(),
# Polygonize(),
# ExecuteSQL(), FindProjection(),
# TopoColor(), EliminateSelection()
# ]
@@ -299,6 +294,7 @@ def getAlgs(self):
SymmetricalDifference(),
TextToFloat(),
Translate(),
TruncateTable(),
Union(),
UniqueValues(),
VectorSplit(),
@@ -25,13 +25,10 @@

__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 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterTable(self.INPUT,
self.tr('Input Layer')))
self.addOutput(OutputVector(self.OUTPUT,
self.tr('Truncated layer'), True))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input Layer')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Truncated layer')))

def name(self):
return 'truncatetable'
@@ -61,12 +57,11 @@ def displayName(self):
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 @@ def check_results(self, results, context, params, expected):
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)

0 comments on commit 504cc1f

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