mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge pull request #8776 from alexbruy/gdal_tests
[processing] cover more GDAL algorithms with unittests
This commit is contained in:
commit
2f1efd8927
@ -111,7 +111,9 @@ class polygonize(GdalAlgorithm):
|
||||
if outFormat:
|
||||
arguments.append('-f {}'.format(outFormat))
|
||||
|
||||
arguments.append(GdalUtils.ogrLayerName(output))
|
||||
layerName = GdalUtils.ogrLayerName(output)
|
||||
if layerName:
|
||||
arguments.append(layerName)
|
||||
arguments.append(self.parameterAsString(parameters, self.FIELD, context))
|
||||
|
||||
commands = []
|
||||
|
@ -61,6 +61,8 @@ from processing.algs.gdal.fillnodata import fillnodata
|
||||
from processing.algs.gdal.rearrange_bands import rearrange_bands
|
||||
from processing.algs.gdal.gdaladdo import gdaladdo
|
||||
from processing.algs.gdal.sieve import sieve
|
||||
from processing.algs.gdal.gdal2xyz import gdal2xyz
|
||||
from processing.algs.gdal.polygonize import polygonize
|
||||
|
||||
from processing.tools.system import isWindows
|
||||
|
||||
@ -2514,6 +2516,88 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
source + ' ' +
|
||||
outsource])
|
||||
|
||||
def testGdal2Xyz(self):
|
||||
context = QgsProcessingContext()
|
||||
feedback = QgsProcessingFeedback()
|
||||
source = os.path.join(testDataPath, 'dem.tif')
|
||||
|
||||
with tempfile.TemporaryDirectory() as outdir:
|
||||
outsource = outdir + '/check.csv'
|
||||
alg = gdal2xyz()
|
||||
alg.initAlgorithm()
|
||||
|
||||
# defaults
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'CSV': False,
|
||||
'OUTPUT': outsource}, context, feedback),
|
||||
['gdal2xyz.py',
|
||||
'-band 1 ' +
|
||||
source + ' ' +
|
||||
outsource])
|
||||
|
||||
# csv output
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'CSV': True,
|
||||
'OUTPUT': outsource}, context, feedback),
|
||||
['gdal2xyz.py',
|
||||
'-band 1 -csv ' +
|
||||
source + ' ' +
|
||||
outsource])
|
||||
|
||||
def testGdalPolygonize(self):
|
||||
context = QgsProcessingContext()
|
||||
feedback = QgsProcessingFeedback()
|
||||
source = os.path.join(testDataPath, 'dem.tif')
|
||||
|
||||
with tempfile.TemporaryDirectory() as outdir:
|
||||
outsource = outdir + '/check.shp'
|
||||
alg = polygonize()
|
||||
alg.initAlgorithm()
|
||||
|
||||
# defaults
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'FIELD': 'DN',
|
||||
'EIGHT_CONNECTEDNESS': False,
|
||||
'OUTPUT': outsource}, context, feedback),
|
||||
['gdal_polygonize.py',
|
||||
source + ' ' +
|
||||
outsource + ' ' +
|
||||
'-b 1 -f "ESRI Shapefile" DN'
|
||||
])
|
||||
|
||||
# 8 connectedness
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'FIELD': 'DN',
|
||||
'EIGHT_CONNECTEDNESS': True,
|
||||
'OUTPUT': outsource}, context, feedback),
|
||||
['gdal_polygonize.py',
|
||||
source + ' ' +
|
||||
outsource + ' ' +
|
||||
'-8 -b 1 -f "ESRI Shapefile" DN'
|
||||
])
|
||||
|
||||
# custom output format
|
||||
outsource = outdir + '/check.gpkg'
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'FIELD': 'DN',
|
||||
'EIGHT_CONNECTEDNESS': False,
|
||||
'OUTPUT': outsource}, context, feedback),
|
||||
['gdal_polygonize.py',
|
||||
source + ' ' +
|
||||
outsource + ' ' +
|
||||
'-b 1 -f "GPKG" DN'
|
||||
])
|
||||
|
||||
|
||||
class TestGdalOgrToPostGis(unittest.TestCase):
|
||||
|
||||
|
@ -168,20 +168,6 @@ tests:
|
||||
- 'Band 1 Block=373x5 Type=Float32, ColorInterp=Gray'
|
||||
- ' NoData Value=-99999'
|
||||
|
||||
# Disabled as gdal2xyz.py is not available on Travis
|
||||
# - algorithm: gdal:gdal2xyz
|
||||
# name: gdal2xyz
|
||||
# params:
|
||||
# BAND: 1
|
||||
# CSV: false
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# name: expected/gdal/xyz.csv
|
||||
# type: file
|
||||
|
||||
- algorithm: gdal:tileindex
|
||||
name: Tile index (gdaltindex)
|
||||
params:
|
||||
@ -349,41 +335,6 @@ tests:
|
||||
hash: fff4a08498e93494f3f2cf1a9074451e6fd68341849aedc9e2c45e6a
|
||||
type: rasterhash
|
||||
|
||||
# Disabled as gdal_poligonize.py is not available on Travis
|
||||
# - algorithm: gdal:polygonize
|
||||
# name: Polygonize
|
||||
# params:
|
||||
# BAND: 1
|
||||
# EIGHT_CONNECTEDNESS: false
|
||||
# FIELD: DN
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# name: expected/gdal/polygonize.gml
|
||||
# type: vector
|
||||
|
||||
# Disabled as gdal_proximity.py is not available on Travis
|
||||
# - algorithm: gdal:proximity
|
||||
# name: Proximity
|
||||
# params:
|
||||
# BAND: 1
|
||||
# DATA_TYPE: 5
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# MAX_DISTANCE: 0.0
|
||||
# NODATA: 0.0
|
||||
# OPTIONS: ''
|
||||
# REPLACE: 0.0
|
||||
# UNITS: 1
|
||||
# VALUES: '90'
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# hash: 32802271d1ce083ca14078bfefaef6300ae8809af11f6a4270583d0c
|
||||
# type: rasterhash
|
||||
|
||||
- algorithm: gdal:rasterize
|
||||
name: Test (gdal:rasterize)
|
||||
params:
|
||||
|
Loading…
x
Reference in New Issue
Block a user