Skip to content

Commit

Permalink
Merge pull request #8143 from mdouchin/patch-1
Browse files Browse the repository at this point in the history
Processing - Add GeoPackage support in alg qgis:convertformat
  • Loading branch information
rldhont committed Oct 24, 2018
2 parents 72a7606 + 1cdac2c commit 5f26d1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/gdal/ogr2ogr.py
Expand Up @@ -62,6 +62,7 @@
'ODS',
'XLSX',
'PDF',
'GPKG'
]

EXTS = [
Expand All @@ -87,6 +88,7 @@
'.ods',
'.xlsx',
'.pdf',
'.gpkg'
]


Expand Down Expand Up @@ -127,7 +129,7 @@ def getConsoleCommands(self):
output = ogrConnectionString(outFile)
options = unicode(self.getParameterValue(self.OPTIONS))

if outFormat == 'SQLite' and os.path.isfile(output):
if outFormat in ('SQLite', 'GPKG') and os.path.isfile(output):
os.remove(output)

arguments = []
Expand Down
28 changes: 27 additions & 1 deletion python/plugins/processing/tests/GdalAlgorithmsTest.py
Expand Up @@ -27,15 +27,18 @@

import AlgorithmsTestBase
from processing.algs.gdal.ogr2ogrtopostgis import Ogr2OgrToPostGis
from processing.algs.gdal.ogr2ogr import Ogr2Ogr

import nose2
import shutil

import os
from qgis.testing import (
start_app,
unittest
)

testDataPath = os.path.join(os.path.dirname(__file__), 'testdata')


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

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

def testOgr2Ogr(self):
source = os.path.join(testDataPath, 'polys.gml')

alg = Ogr2Ogr()
alg.setParameterValue('INPUT_LAYER', source)
alg.setParameterValue('FORMAT', 0)
alg.setOutputValue('OUTPUT_LAYER', 'd:/temp/check.shp')
self.assertEqual(
alg.getConsoleCommands(),
['ogr2ogr',
'-f "ESRI Shapefile" "d:/temp/check.shp" ' +
source + ' polys2'])

alg = Ogr2Ogr()
alg.setParameterValue('INPUT_LAYER', source)
alg.setParameterValue('FORMAT', 22)
alg.setOutputValue('OUTPUT_LAYER', 'd:/temp/check.gpkg')
self.assertEqual(
alg.getConsoleCommands(),
['ogr2ogr',
'-f GPKG "d:/temp/check.gpkg" ' +
source + ' polys2'])


class TestGdalOgr2OgrToPostgis(unittest.TestCase):

Expand Down

0 comments on commit 5f26d1b

Please sign in to comment.