Skip to content

Commit 9b74d9f

Browse files
committedOct 11, 2017
[processing] restore offset curve algorithm
1 parent 105222e commit 9b74d9f

File tree

5 files changed

+124
-137
lines changed

5 files changed

+124
-137
lines changed
 

‎python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
# from .gdalcalc import gdalcalc
7474
# from .rasterize_over import rasterize_over
7575

76+
from .OffsetCurve import OffsetCurve
7677
from .ogrinfo import ogrinfo
7778
from .OgrToPostGis import OgrToPostGis
7879
from .PointsAlongLines import PointsAlongLines
@@ -84,7 +85,6 @@
8485
# from .ogr2ogrbuffer import Ogr2OgrBuffer
8586
# from .ogr2ogrdissolve import Ogr2OgrDissolve
8687
# from .onesidebuffer import OneSideBuffer
87-
# from .offsetcurve import OffsetCurve
8888
# from .ogr2ogrtabletopostgislist import Ogr2OgrTableToPostGisList
8989
# from .ogrsql import OgrSql
9090

@@ -175,6 +175,7 @@ def loadAlgorithms(self):
175175
# gdalcalc(),
176176
# rasterize_over(),
177177
# ----- OGR tools -----
178+
OffsetCurve(),
178179
ogrinfo(),
179180
OgrToPostGis(),
180181
PointsAlongLines(),
@@ -185,7 +186,6 @@ def loadAlgorithms(self):
185186
# Ogr2OgrBuffer(),
186187
# Ogr2OgrDissolve(),
187188
# OneSideBuffer(),
188-
# OffsetCurve(),
189189
# Ogr2OgrTableToPostGisList(),
190190
# OgrSql(),
191191
]
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
offsetcurve.py
6+
---------------------
7+
Date : Janaury 2015
8+
Copyright : (C) 2015 by Giovanni Manghi
9+
Email : giovanni dot manghi at naturalgis dot pt
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Giovanni Manghi'
21+
__date__ = 'January 2015'
22+
__copyright__ = '(C) 2015, Giovanni Manghi'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from qgis.core import (QgsProcessing,
29+
QgsProcessingParameterFeatureSource,
30+
QgsProcessingParameterString,
31+
QgsProcessingParameterNumber,
32+
QgsProcessingParameterVectorDestination,
33+
QgsProcessingOutputVectorLayer)
34+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
35+
from processing.algs.gdal.GdalUtils import GdalUtils
36+
37+
38+
class OffsetCurve(GdalAlgorithm):
39+
40+
INPUT = 'INPUT'
41+
GEOMETRY = 'GEOMETRY'
42+
DISTANCE = 'DISTANCE'
43+
OPTIONS = 'OPTIONS'
44+
OUTPUT = 'OUTPUT'
45+
46+
def __init__(self):
47+
super().__init__()
48+
49+
def initAlgorithm(self, config=None):
50+
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
51+
self.tr('Input layer'),
52+
[QgsProcessing.TypeVectorLine]))
53+
self.addParameter(QgsProcessingParameterString(self.GEOMETRY,
54+
self.tr('Geometry column name'),
55+
defaultValue='geometry'))
56+
self.addParameter(QgsProcessingParameterNumber(self.DISTANCE,
57+
self.tr('Offset distance (left-sided: positive, right-sided: negative)'),
58+
type=QgsProcessingParameterNumber.Double,
59+
defaultValue=10))
60+
self.addParameter(QgsProcessingParameterString(self.OPTIONS,
61+
self.tr('Additional creation options'),
62+
defaultValue='',
63+
optional=True))
64+
65+
self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT,
66+
self.tr('Offset curve'),
67+
QgsProcessing.TypeVectorLine))
68+
69+
def name(self):
70+
return 'offsetcurve'
71+
72+
def displayName(self):
73+
return self.tr('Offset curve')
74+
75+
def group(self):
76+
return self.tr('Vector geoprocessing')
77+
78+
def commandName(self):
79+
return 'ogr2ogr'
80+
81+
def getConsoleCommands(self, parameters, context, feedback):
82+
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
83+
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
84+
distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
85+
options = self.parameterAsString(parameters, self.OPTIONS, context)
86+
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
87+
88+
output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
89+
90+
arguments = []
91+
arguments.append(output)
92+
arguments.append(ogrLayer)
93+
arguments.append('-dialect')
94+
arguments.append('sqlite')
95+
arguments.append('-sql')
96+
97+
sql = "SELECT ST_OffsetCurve({}, {}), * FROM '{}'".format(geometry, distance, layerName)
98+
arguments.append(sql)
99+
100+
if options:
101+
arguments.append(options)
102+
103+
return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

‎python/plugins/processing/algs/gdal/offsetcurve.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

‎python/plugins/processing/algs/gdal/ogrinfo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__revision__ = '$Format:%H$'
2727

2828

29-
from qgis.core import (QgsProcessingParameterVectorLayer,
29+
from qgis.core import (QgsProcessingParameterFeatureSource,
3030
QgsProcessingParameterBoolean,
3131
QgsProcessingParameterFileDestination,
3232
QgsProcessingOutputHtml)
@@ -45,8 +45,8 @@ def __init__(self):
4545
super().__init__()
4646

4747
def initAlgorithm(self, config=None):
48-
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
49-
self.tr('Input layer')))
48+
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
49+
self.tr('Input layer')))
5050
self.addParameter(QgsProcessingParameterBoolean(self.SUMMARY_ONLY,
5151
self.tr('Summary output only'),
5252
defaultValue=True))

‎python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,22 +338,22 @@ tests:
338338
compare:
339339
ignore_crs_check: true
340340

341-
# - algorithm: gdal:offsetlinesforlines
342-
# name: Offset lines for lines (right-handed)
343-
# params:
344-
# GEOMETRY: geometry
345-
# INPUT_LAYER:
346-
# name: lines.gml
347-
# type: vector
348-
# RADIUS: -0.5
349-
# results:
350-
# OUTPUT_LAYER:
351-
# name: expected/gdal/offset_lines.gml
352-
# type: vector
353-
# compare:
354-
# geometry:
355-
# precision: 7
356-
#
341+
- algorithm: gdal:offsetcurve
342+
name: Offset curve (right-handed)
343+
params:
344+
GEOMETRY: geometry
345+
INPUT_LAYER:
346+
name: lines.gml
347+
type: vector
348+
RADIUS: -0.5
349+
results:
350+
OUTPUT_LAYER:
351+
name: expected/gdal/offset_lines.gml
352+
type: vector
353+
compare:
354+
geometry:
355+
precision: 7
356+
357357
# - algorithm: gdal:singlesidedbufferforlines
358358
# name: One-side buffer for lines (left-handed)
359359
# params:
@@ -429,4 +429,3 @@ tests:
429429
# geometry:
430430
# precision: 7
431431
#
432-

0 commit comments

Comments
 (0)
Please sign in to comment.