Skip to content
Permalink
Browse files

[processing] refactor offset curve GDAL algorithm (fix #15478)

(cherry picked from commit cac3b2d)
  • Loading branch information
alexbruy committed Sep 14, 2016
1 parent 5719fec commit acc108a284b09e8d12bf36e94bb3a9d3c2895dca
Showing with 28 additions and 48 deletions.
  1. +28 −48 python/plugins/processing/algs/gdal/ogr2ogronesidebuffer.py
@@ -83,69 +83,49 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"
operation = self.getParameterValue(self.OPERATION)
geometry = unicode(self.getParameterValue(self.GEOMETRY))
distance = unicode(self.getParameterValue(self.RADIUS))
leftright = self.LEFTRIGHTLIST[self.getParameterValue(self.LEFTRIGHT)]
geometry = self.getParameterValue(self.GEOMETRY)
distance = self.getParameterValue(self.RADIUS)
leftright = self.getParameterValue(self.LEFTRIGHT)
dissolveall = self.getParameterValue(self.DISSOLVEALL)
field = unicode(self.getParameterValue(self.FIELD))
field = self.getParameterValue(self.FIELD)
multi = self.getParameterValue(self.MULTI)
options = self.getParameterValue(self.OPTIONS)

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

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

output = ogrConnectionString(outFile)
options = unicode(self.getParameterValue(self.OPTIONS))

layername = ogrLayerName(inLayer)

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(ogrLayerName(inLayer))
if dissolveall or field != 'None':
arguments.append(layername)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

if dissolveall or field is not None:
if operation == 0:
arguments.append('-dialect sqlite -sql "SELECT ST_Union(ST_SingleSidedBuffer(')
sql = "SELECT ST_Union(ST_SingleSidedBuffer({}, {}, {})), * FROM '{}'".format(geometry, distance, leftright, layername)
else:
arguments.append('-dialect sqlite -sql "SELECT ST_Union(ST_OffsetCurve(')
sql = "SELECT ST_Union(ST_OffsetCurve({}, {}, {})) * FROM '{}'".format(geometry, distance, leftright, layername)
else:
if operation == 0:
arguments.append('-dialect sqlite -sql "SELECT ST_SingleSidedBuffer(')
else:
arguments.append('-dialect sqlite -sql "SELECT ST_OffsetCurve(')
arguments.append(geometry)
arguments.append(',')
arguments.append(distance)
if dissolveall or field != 'None':
if leftright == 'Left':
if operation == 0:
arguments.append(',0)),*')
else:
arguments.append(')),*')
else:
if operation == 0:
arguments.append(',1)),*')
else:
arguments.append(')),*')
else:
if leftright == 'Left':
if operation == 0:
arguments.append(',0),*')
else:
arguments.append('),*')
sql = "SELECT ST_SingleSidedBuffer({},{},{}), * FROM '{}'".format(geometry, distance, leftright, layername)
else:
if operation == 0:
arguments.append(',1),*')
else:
arguments.append('),*')
arguments.append('FROM')
arguments.append(layername)
if field != 'None':
arguments.append('GROUP')
arguments.append('BY')
arguments.append(field)
arguments.append('"')
if field != 'None' and multi:
sql = "SELECT ST_OffsetCurve({}, {}, {}), * FROM '{}'".format(geometry, distance, leftright, layername)

if field is not None:
sql = '"{} GROUP BY {}"'.format(sql, field)

arguments.append(sql)

if field is not None and multi:
arguments.append('-explodecollections')

if len(options) > 0:
@@ -161,4 +141,4 @@ def getConsoleCommands(self):
return commands

def commandName(self):
return "ogr2ogr"
return 'ogr2ogr'

0 comments on commit acc108a

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