Skip to content

Commit ee8e1ce

Browse files
committedOct 16, 2018
[processing][gdal] More unit tests
1 parent bef8d6e commit ee8e1ce

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
 

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from processing.algs.gdal.OgrToPostGis import OgrToPostGis
3030
from processing.algs.gdal.GdalUtils import GdalUtils
3131
from processing.algs.gdal.AssignProjection import AssignProjection
32+
from processing.algs.gdal.Buffer import Buffer
3233
from processing.algs.gdal.ClipRasterByExtent import ClipRasterByExtent
3334
from processing.algs.gdal.ClipRasterByMask import ClipRasterByMask
3435
from processing.algs.gdal.Dissolve import Dissolve
@@ -47,7 +48,10 @@
4748
from processing.algs.gdal.hillshade import hillshade
4849
from processing.algs.gdal.ogr2ogr import ogr2ogr
4950
from processing.algs.gdal.ogrinfo import ogrinfo
51+
from processing.algs.gdal.OffsetCurve import OffsetCurve
5052
from processing.algs.gdal.OgrToPostGis import OgrToPostGis
53+
from processing.algs.gdal.OneSideBuffer import OneSideBuffer
54+
from processing.algs.gdal.PointsAlongLines import PointsAlongLines
5155
from processing.algs.gdal.proximity import proximity
5256
from processing.algs.gdal.rasterize import rasterize
5357
from processing.algs.gdal.retile import retile
@@ -358,6 +362,47 @@ def testAssignProjection(self):
358362
'-a_srs EPSG:3111 ' +
359363
source])
360364

365+
def testBuffer(self):
366+
context = QgsProcessingContext()
367+
feedback = QgsProcessingFeedback()
368+
source = os.path.join(testDataPath, 'polys.gml')
369+
source_with_space = os.path.join(testDataPath, 'filename with spaces.gml')
370+
alg = Buffer()
371+
alg.initAlgorithm()
372+
373+
with tempfile.TemporaryDirectory() as outdir:
374+
self.assertEqual(
375+
alg.getConsoleCommands({'INPUT': source,
376+
'DISTANCE': 5,
377+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
378+
['ogr2ogr',
379+
outdir + '/check.shp ' +
380+
source + ' ' +
381+
'-dialect sqlite -sql "SELECT ST_Buffer(geometry, 5.0) AS geometry,* FROM \'polys2\'" ' +
382+
'-f "ESRI Shapefile"'])
383+
384+
self.assertEqual(
385+
alg.getConsoleCommands({'INPUT': source,
386+
'DISTANCE': 5,
387+
'DISSOLVE': True,
388+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
389+
['ogr2ogr',
390+
outdir + '/check.shp ' +
391+
source + ' ' +
392+
'-dialect sqlite -sql "SELECT ST_Union(ST_Buffer(geometry, 5.0)) AS geometry,* FROM \'polys2\'" ' +
393+
'-f "ESRI Shapefile"'])
394+
395+
self.assertEqual(
396+
alg.getConsoleCommands({'INPUT': source,
397+
'DISTANCE': 5,
398+
'EXPLODE_COLLECTIONS': True,
399+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
400+
['ogr2ogr',
401+
outdir + '/check.shp ' +
402+
source + ' ' +
403+
'-dialect sqlite -sql "SELECT ST_Buffer(geometry, 5.0) AS geometry,* FROM \'polys2\'" ' +
404+
'-explodecollections -f "ESRI Shapefile"'])
405+
361406
def testGdalTranslate(self):
362407
context = QgsProcessingContext()
363408
feedback = QgsProcessingFeedback()
@@ -2238,6 +2283,85 @@ def testFillnodata(self):
22382283
source + ' ' +
22392284
outsource])
22402285

2286+
def testOffsetCurve(self):
2287+
context = QgsProcessingContext()
2288+
feedback = QgsProcessingFeedback()
2289+
source = os.path.join(testDataPath, 'polys.gml')
2290+
source_with_space = os.path.join(testDataPath, 'filename with spaces.gml')
2291+
alg = OffsetCurve()
2292+
alg.initAlgorithm()
2293+
2294+
with tempfile.TemporaryDirectory() as outdir:
2295+
self.assertEqual(
2296+
alg.getConsoleCommands({'INPUT': source,
2297+
'DISTANCE': 5,
2298+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
2299+
['ogr2ogr',
2300+
outdir + '/check.shp ' +
2301+
source + ' ' +
2302+
'-dialect sqlite -sql "SELECT ST_OffsetCurve(geometry, 5.0) AS geometry,* FROM \'polys2\'" ' +
2303+
'-f "ESRI Shapefile"'])
2304+
2305+
def testOneSidedBuffer(self):
2306+
context = QgsProcessingContext()
2307+
feedback = QgsProcessingFeedback()
2308+
source = os.path.join(testDataPath, 'polys.gml')
2309+
source_with_space = os.path.join(testDataPath, 'filename with spaces.gml')
2310+
alg = OneSideBuffer()
2311+
alg.initAlgorithm()
2312+
2313+
with tempfile.TemporaryDirectory() as outdir:
2314+
self.assertEqual(
2315+
alg.getConsoleCommands({'INPUT': source,
2316+
'DISTANCE': 5,
2317+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
2318+
['ogr2ogr',
2319+
outdir + '/check.shp ' +
2320+
source + ' ' +
2321+
'-dialect sqlite -sql "SELECT ST_SingleSidedBuffer(geometry, 5.0, 0) AS geometry,* FROM \'polys2\'" ' +
2322+
'-f "ESRI Shapefile"'])
2323+
2324+
self.assertEqual(
2325+
alg.getConsoleCommands({'INPUT': source,
2326+
'DISTANCE': 5,
2327+
'DISSOLVE': True,
2328+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
2329+
['ogr2ogr',
2330+
outdir + '/check.shp ' +
2331+
source + ' ' +
2332+
'-dialect sqlite -sql "SELECT ST_Union(ST_SingleSidedBuffer(geometry, 5.0, 0)) AS geometry,* FROM \'polys2\'" ' +
2333+
'-f "ESRI Shapefile"'])
2334+
2335+
self.assertEqual(
2336+
alg.getConsoleCommands({'INPUT': source,
2337+
'DISTANCE': 5,
2338+
'EXPLODE_COLLECTIONS': True,
2339+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
2340+
['ogr2ogr',
2341+
outdir + '/check.shp ' +
2342+
source + ' ' +
2343+
'-dialect sqlite -sql "SELECT ST_SingleSidedBuffer(geometry, 5.0, 0) AS geometry,* FROM \'polys2\'" ' +
2344+
'-explodecollections -f "ESRI Shapefile"'])
2345+
2346+
def testPointsAlongLines(self):
2347+
context = QgsProcessingContext()
2348+
feedback = QgsProcessingFeedback()
2349+
source = os.path.join(testDataPath, 'polys.gml')
2350+
source_with_space = os.path.join(testDataPath, 'filename with spaces.gml')
2351+
alg = PointsAlongLines()
2352+
alg.initAlgorithm()
2353+
2354+
with tempfile.TemporaryDirectory() as outdir:
2355+
self.assertEqual(
2356+
alg.getConsoleCommands({'INPUT': source,
2357+
'DISTANCE': 0.2,
2358+
'OUTPUT': outdir + '/check.shp'}, context, feedback),
2359+
['ogr2ogr',
2360+
outdir + '/check.shp ' +
2361+
source + ' ' +
2362+
'-dialect sqlite -sql "SELECT ST_Line_Interpolate_Point(geometry, 0.2) AS geometry,* FROM \'polys2\'" ' +
2363+
'-f "ESRI Shapefile"'])
2364+
22412365

22422366
class TestGdalOgrToPostGis(unittest.TestCase):
22432367

0 commit comments

Comments
 (0)
Please sign in to comment.