Skip to content

Commit 744d350

Browse files
authoredJan 2, 2019
Merge pull request #8784 from alexbruy/backport-tests
[processing] backport GDAL unittests to LTR branch
2 parents e39fdd5 + 7dd30a5 commit 744d350

File tree

3 files changed

+87
-50
lines changed

3 files changed

+87
-50
lines changed
 

‎python/plugins/processing/algs/gdal/polygonize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
111111
if outFormat:
112112
arguments.append('-f {}'.format(outFormat))
113113

114-
arguments.append(GdalUtils.ogrLayerName(output))
114+
layerName = GdalUtils.ogrLayerName(output)
115+
if layerName:
116+
arguments.append(layerName)
115117
arguments.append(self.parameterAsString(parameters, self.FIELD, context))
116118

117119
commands = []

‎python/plugins/processing/tests/GdalAlgorithmsTest.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
from processing.algs.gdal.rearrange_bands import rearrange_bands
6262
from processing.algs.gdal.gdaladdo import gdaladdo
6363
from processing.algs.gdal.sieve import sieve
64+
from processing.algs.gdal.gdal2xyz import gdal2xyz
65+
from processing.algs.gdal.polygonize import polygonize
6466

6567
from processing.tools.system import isWindows
6668

@@ -2514,6 +2516,88 @@ def testSieve(self):
25142516
source + ' ' +
25152517
outsource])
25162518

2519+
def testGdal2Xyz(self):
2520+
context = QgsProcessingContext()
2521+
feedback = QgsProcessingFeedback()
2522+
source = os.path.join(testDataPath, 'dem.tif')
2523+
2524+
with tempfile.TemporaryDirectory() as outdir:
2525+
outsource = outdir + '/check.csv'
2526+
alg = gdal2xyz()
2527+
alg.initAlgorithm()
2528+
2529+
# defaults
2530+
self.assertEqual(
2531+
alg.getConsoleCommands({'INPUT': source,
2532+
'BAND': 1,
2533+
'CSV': False,
2534+
'OUTPUT': outsource}, context, feedback),
2535+
['gdal2xyz.py',
2536+
'-band 1 ' +
2537+
source + ' ' +
2538+
outsource])
2539+
2540+
# csv output
2541+
self.assertEqual(
2542+
alg.getConsoleCommands({'INPUT': source,
2543+
'BAND': 1,
2544+
'CSV': True,
2545+
'OUTPUT': outsource}, context, feedback),
2546+
['gdal2xyz.py',
2547+
'-band 1 -csv ' +
2548+
source + ' ' +
2549+
outsource])
2550+
2551+
def testGdalPolygonize(self):
2552+
context = QgsProcessingContext()
2553+
feedback = QgsProcessingFeedback()
2554+
source = os.path.join(testDataPath, 'dem.tif')
2555+
2556+
with tempfile.TemporaryDirectory() as outdir:
2557+
outsource = outdir + '/check.shp'
2558+
alg = polygonize()
2559+
alg.initAlgorithm()
2560+
2561+
# defaults
2562+
self.assertEqual(
2563+
alg.getConsoleCommands({'INPUT': source,
2564+
'BAND': 1,
2565+
'FIELD': 'DN',
2566+
'EIGHT_CONNECTEDNESS': False,
2567+
'OUTPUT': outsource}, context, feedback),
2568+
['gdal_polygonize.py',
2569+
source + ' ' +
2570+
outsource + ' ' +
2571+
'-b 1 -f "ESRI Shapefile" DN'
2572+
])
2573+
2574+
# 8 connectedness
2575+
self.assertEqual(
2576+
alg.getConsoleCommands({'INPUT': source,
2577+
'BAND': 1,
2578+
'FIELD': 'DN',
2579+
'EIGHT_CONNECTEDNESS': True,
2580+
'OUTPUT': outsource}, context, feedback),
2581+
['gdal_polygonize.py',
2582+
source + ' ' +
2583+
outsource + ' ' +
2584+
'-8 -b 1 -f "ESRI Shapefile" DN'
2585+
])
2586+
2587+
# custom output format
2588+
outsource = outdir + '/check.gpkg'
2589+
self.assertEqual(
2590+
alg.getConsoleCommands({'INPUT': source,
2591+
'BAND': 1,
2592+
'FIELD': 'DN',
2593+
'EIGHT_CONNECTEDNESS': False,
2594+
'OUTPUT': outsource}, context, feedback),
2595+
['gdal_polygonize.py',
2596+
source + ' ' +
2597+
outsource + ' ' +
2598+
'-b 1 -f "GPKG" DN'
2599+
])
2600+
25172601

25182602
class TestGdalOgrToPostGis(unittest.TestCase):
25192603

‎python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,6 @@ tests:
167167
- 'Band 1 Block=373x5 Type=Float32, ColorInterp=Gray'
168168
- ' NoData Value=-99999'
169169

170-
# Disabled as gdal2xyz.py is not available on Travis
171-
# - algorithm: gdal:gdal2xyz
172-
# name: gdal2xyz
173-
# params:
174-
# BAND: 1
175-
# CSV: false
176-
# INPUT:
177-
# name: dem.tif
178-
# type: raster
179-
# results:
180-
# OUTPUT:
181-
# name: expected/gdal/xyz.csv
182-
# type: file
183-
184170
- algorithm: gdal:tileindex
185171
name: Tile index (gdaltindex)
186172
params:
@@ -348,41 +334,6 @@ tests:
348334
hash: fff4a08498e93494f3f2cf1a9074451e6fd68341849aedc9e2c45e6a
349335
type: rasterhash
350336

351-
# Disabled as gdal_poligonize.py is not available on Travis
352-
# - algorithm: gdal:polygonize
353-
# name: Polygonize
354-
# params:
355-
# BAND: 1
356-
# EIGHT_CONNECTEDNESS: false
357-
# FIELD: DN
358-
# INPUT:
359-
# name: dem.tif
360-
# type: raster
361-
# results:
362-
# OUTPUT:
363-
# name: expected/gdal/polygonize.gml
364-
# type: vector
365-
366-
# Disabled as gdal_proximity.py is not available on Travis
367-
# - algorithm: gdal:proximity
368-
# name: Proximity
369-
# params:
370-
# BAND: 1
371-
# DATA_TYPE: 5
372-
# INPUT:
373-
# name: dem.tif
374-
# type: raster
375-
# MAX_DISTANCE: 0.0
376-
# NODATA: 0.0
377-
# OPTIONS: ''
378-
# REPLACE: 0.0
379-
# UNITS: 1
380-
# VALUES: '90'
381-
# results:
382-
# OUTPUT:
383-
# hash: 32802271d1ce083ca14078bfefaef6300ae8809af11f6a4270583d0c
384-
# type: rasterhash
385-
386337
- algorithm: gdal:rasterize
387338
name: Test (gdal:rasterize)
388339
params:

0 commit comments

Comments
 (0)
Please sign in to comment.