Skip to content
Permalink
Browse files

Fix OGR algs always export shapefiles, regardless of output file exte…

…nsion
  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent e33647d commit 0a365b2d22bd826d6f79310a08e9af47904a69fc
@@ -229,20 +229,31 @@ def gdalHelpPath():

@staticmethod
def ogrConnectionString(uri, context):
"""Generates OGR connection sting from layer source
"""Generates OGR connection string from layer source
"""
return GdalUtils.ogrConnectionStringAndFormat(uri, context)[0]

@staticmethod
def ogrConnectionStringAndFormat(uri, context):
"""Generates OGR connection string and format string from layer source
Returned values are a tuple of the connection string and format string
"""
ogrstr = None
format = None

layer = QgsProcessingUtils.mapLayerFromString(uri, context, False)
if layer is None:
return '"' + uri + '"'
path, ext = os.path.splitext(uri)
format = QgsVectorFileWriter.driverForExtension(ext)
return '"' + uri + '"', format

provider = layer.dataProvider().name()
if provider == 'spatialite':
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=
regex = re.compile("dbname='(.+)'")
r = regex.search(str(layer.source()))
ogrstr = r.groups()[0]
format = 'SQLite'
elif provider == 'postgres':
# dbname='ktryjh_iuuqef' host=spacialdb.com port=9999
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
@@ -270,6 +281,7 @@ def ogrConnectionString(uri, context):
QgsCredentials.instance().put(conninfo, user, passwd)

ogrstr = "PG:%s" % dsUri.connectionInfo()
format = 'PostgreSQL'
elif provider == "oracle":
# OCI:user/password@host:port/service:table
dsUri = QgsDataSourceUri(layer.dataProvider().dataSourceUri())
@@ -299,10 +311,13 @@ def ogrConnectionString(uri, context):
ogrstr += dsUri.schema() + "."

ogrstr += dsUri.table()
format = 'OCI'
else:
ogrstr = str(layer.source()).split("|")[0]
path, ext = os.path.splitext(ogrstr)
format = QgsVectorFileWriter.driverForExtension(ext)

return '"' + ogrstr + '"'
return '"' + ogrstr + '"', format

@staticmethod
def ogrLayerName(uri):
@@ -81,10 +81,12 @@ def getConsoleCommands(self, parameters, context, feedback):

outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

output = GdalUtils.ogrConnectionString(outFile, context)
output, format = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)

arguments = []
if format:
arguments.append('-f {}'.format(format))
arguments.append(output)
arguments.append(ogrLayer)

0 comments on commit 0a365b2

Please sign in to comment.
You can’t perform that action at this time.