Skip to content

Commit

Permalink
Fix OGR algs always export shapefiles, regardless of output file exte…
Browse files Browse the repository at this point in the history
…nsion
  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent e33647d commit 0a365b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 18 additions & 3 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/gdal/ogr2ogrpointsonlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0a365b2

Please sign in to comment.