Skip to content

Commit

Permalink
[processing] refactor offset curve GDAL algorithm (fix #15478)
Browse files Browse the repository at this point in the history
(cherry picked from commit cac3b2d)
  • Loading branch information
alexbruy committed Sep 14, 2016
1 parent e805f00 commit e2c7991
Showing 1 changed file with 28 additions and 48 deletions.
76 changes: 28 additions & 48 deletions python/plugins/processing/algs/gdal/ogr2ogronesidebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -161,4 +141,4 @@ def getConsoleCommands(self):
return commands

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

0 comments on commit e2c7991

Please sign in to comment.