Skip to content
Permalink
Browse files

ogrConnectionString reuses existing context

  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent ce8e18d commit ab079f9d92b0e5374a01e34c767747cfc0c38261
@@ -109,7 +109,7 @@ def getConsoleCommands(self, parameters, context, feedback):
mask = self.getParameterValue(self.MASK)
context = dataobjects.createContext()
maskLayer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.MASK), context)
ogrMask = ogrConnectionString(mask)[1:-1]
ogrMask = ogrConnectionString(mask, context)[1:-1]
noData = self.getParameterValue(self.NO_DATA)
opts = self.getParameterValue(self.OPTIONS)

@@ -80,12 +80,12 @@ def getConsoleCommands(self, parameters, context, feedback):
distance = self.getParameterValue(self.RADIUS)
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value
output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)

layername = ogrLayerName(inLayer)

@@ -124,7 +124,7 @@ def group(self):

def getConsoleCommands(self, parameters, context, feedback):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value
@@ -136,7 +136,7 @@ def getConsoleCommands(self, parameters, context, feedback):
outFile += ext
output.value = outFile

output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)
options = str(self.getParameterValue(self.OPTIONS))

if outFormat == 'SQLite' and os.path.isfile(output):
@@ -94,13 +94,13 @@ def getConsoleCommands(self, parameters, context, feedback):
multi = self.getParameterValue(self.MULTI)
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
layername = ogrLayerName(inLayer)

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)

arguments = []
arguments.append(output)
@@ -69,14 +69,14 @@ def group(self):

def getConsoleCommands(self, parameters, context, feedback):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
clipLayer = self.getParameterValue(self.CLIP_LAYER)
ogrClipLayer = ogrConnectionString(clipLayer)[1:-1]
ogrClipLayer = ogrConnectionString(clipLayer, context)[1:-1]

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)
options = str(self.getParameterValue(self.OPTIONS))

arguments = []
@@ -69,15 +69,15 @@ def group(self):

def getConsoleCommands(self, parameters, context, feedback):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
clipExtent = self.getParameterValue(self.CLIP_EXTENT)
if not clipExtent:
clipExtent = QgsProcessingUtils.combineLayerExtents([inLayer])

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)
options = str(self.getParameterValue(self.OPTIONS))

arguments = []
@@ -103,13 +103,13 @@ def getConsoleCommands(self, parameters, context, feedback):
statsatt = self.getParameterValue(self.STATSATT)
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
layername = ogrLayerName(inLayer)

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)

arguments = []
arguments.append(output)
@@ -141,7 +141,7 @@ def getConsoleCommands(self, parameters, context, feedback):
uri = GeoDB(uri=uri).uri

inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
shapeEncoding = self.getParameterValue(self.SHAPE_ENCODING)
schema = str(self.getParameterValue(self.SCHEMA))
table = str(self.getParameterValue(self.TABLE))
@@ -188,7 +188,7 @@ def getConnectionString(self, parameters):

def getConsoleCommands(self, parameters, context, feedback):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
shapeEncoding = self.getParameterValue(self.SHAPE_ENCODING)
ssrs = str(self.getParameterValue(self.S_SRS))
tsrs = str(self.getParameterValue(self.T_SRS))
@@ -193,7 +193,7 @@ def getConsoleCommands(self, parameters, context, feedback):
uri = GeoDB(uri=uri).uri

inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
shapeEncoding = self.getParameterValue(self.SHAPE_ENCODING)
ssrs = self.getParameterValue(self.S_SRS)
tsrs = self.getParameterValue(self.T_SRS)
@@ -69,7 +69,7 @@ def getConsoleCommands(self, parameters, context, feedback):
if self.getParameterValue(self.SUMMARY_ONLY):
arguments.append('-so')
layer = self.getParameterValue(self.INPUT)
conn = ogrConnectionString(layer)
conn = ogrConnectionString(layer, context)
arguments.append(conn)
return arguments

@@ -93,7 +93,7 @@ def getConsoleCommands(self, parameters, context, feedback):
arguments.append(outFile)

layer = self.getParameterValue(self.INPUT)
conn = ogrConnectionString(layer)[1:-1]
conn = ogrConnectionString(layer, context)[1:-1]
arguments.append(conn)

return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
@@ -100,12 +100,12 @@ def getConsoleCommands(self, parameters, context, feedback):
multi = self.getParameterValue(self.MULTI)
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
layername = ogrLayerName(inLayer)

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value
output = ogrConnectionString(outFile)
output = ogrConnectionString(outFile, context)

layername = ogrLayerName(inLayer)

@@ -113,7 +113,7 @@ def getConsoleCommands(self, parameters, context, feedback):
opts = self.getParameterValue(self.OPTIONS)
out = self.getOutputValue(self.OUTPUT)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]

if noData is not None:
noData = str(noData)
@@ -78,8 +78,8 @@ def getConsoleCommands(self, parameters, context, feedback):
inLayer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
inRasterLayer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_RASTER), context)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
ogrRasterLayer = ogrConnectionString(inRasterLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer, context)[1:-1]
ogrRasterLayer = ogrConnectionString(inRasterLayer, context)[1:-1]

arguments = []
arguments.append('-a')
@@ -247,15 +247,15 @@ def snapToPrecision(geom, precision):
return QgsPointXY(snapped.x(), snapped.y())


def ogrConnectionString(uri):
def ogrConnectionString(uri, context):
"""Generates OGR connection sting from layer source
"""
ogrstr = None

context = dataobjects.createContext()
layer = QgsProcessingUtils.mapLayerFromString(uri, context, False)
if layer is None:
return '"' + uri + '"'

provider = layer.dataProvider().name()
if provider == 'spatialite':
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=

0 comments on commit ab079f9

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