Skip to content

Commit 5f26d1b

Browse files
authored
Merge pull request #8143 from mdouchin/patch-1
Processing - Add GeoPackage support in alg qgis:convertformat
2 parents 72a7606 + 1cdac2c commit 5f26d1b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

python/plugins/processing/algs/gdal/ogr2ogr.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'ODS',
6363
'XLSX',
6464
'PDF',
65+
'GPKG'
6566
]
6667

6768
EXTS = [
@@ -87,6 +88,7 @@
8788
'.ods',
8889
'.xlsx',
8990
'.pdf',
91+
'.gpkg'
9092
]
9193

9294

@@ -127,7 +129,7 @@ def getConsoleCommands(self):
127129
output = ogrConnectionString(outFile)
128130
options = unicode(self.getParameterValue(self.OPTIONS))
129131

130-
if outFormat == 'SQLite' and os.path.isfile(output):
132+
if outFormat in ('SQLite', 'GPKG') and os.path.isfile(output):
131133
os.remove(output)
132134

133135
arguments = []

python/plugins/processing/tests/GdalAlgorithmsTest.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727

2828
import AlgorithmsTestBase
2929
from processing.algs.gdal.ogr2ogrtopostgis import Ogr2OgrToPostGis
30+
from processing.algs.gdal.ogr2ogr import Ogr2Ogr
3031

3132
import nose2
3233
import shutil
33-
34+
import os
3435
from qgis.testing import (
3536
start_app,
3637
unittest
3738
)
3839

40+
testDataPath = os.path.join(os.path.dirname(__file__), 'testdata')
41+
3942

4043
class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
4144

@@ -54,6 +57,29 @@ def tearDownClass(cls):
5457
def test_definition_file(self):
5558
return 'gdal_algorithm_tests.yaml'
5659

60+
def testOgr2Ogr(self):
61+
source = os.path.join(testDataPath, 'polys.gml')
62+
63+
alg = Ogr2Ogr()
64+
alg.setParameterValue('INPUT_LAYER', source)
65+
alg.setParameterValue('FORMAT', 0)
66+
alg.setOutputValue('OUTPUT_LAYER', 'd:/temp/check.shp')
67+
self.assertEqual(
68+
alg.getConsoleCommands(),
69+
['ogr2ogr',
70+
'-f "ESRI Shapefile" "d:/temp/check.shp" ' +
71+
source + ' polys2'])
72+
73+
alg = Ogr2Ogr()
74+
alg.setParameterValue('INPUT_LAYER', source)
75+
alg.setParameterValue('FORMAT', 22)
76+
alg.setOutputValue('OUTPUT_LAYER', 'd:/temp/check.gpkg')
77+
self.assertEqual(
78+
alg.getConsoleCommands(),
79+
['ogr2ogr',
80+
'-f GPKG "d:/temp/check.gpkg" ' +
81+
source + ' polys2'])
82+
5783

5884
class TestGdalOgr2OgrToPostgis(unittest.TestCase):
5985

0 commit comments

Comments
 (0)