mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[processing] restore offset curve algorithm
This commit is contained in:
parent
105222ea8c
commit
9b74d9f2df
@ -73,6 +73,7 @@ from .warp import warp
|
||||
# from .gdalcalc import gdalcalc
|
||||
# from .rasterize_over import rasterize_over
|
||||
|
||||
from .OffsetCurve import OffsetCurve
|
||||
from .ogrinfo import ogrinfo
|
||||
from .OgrToPostGis import OgrToPostGis
|
||||
from .PointsAlongLines import PointsAlongLines
|
||||
@ -84,7 +85,6 @@ from .PointsAlongLines import PointsAlongLines
|
||||
# from .ogr2ogrbuffer import Ogr2OgrBuffer
|
||||
# from .ogr2ogrdissolve import Ogr2OgrDissolve
|
||||
# from .onesidebuffer import OneSideBuffer
|
||||
# from .offsetcurve import OffsetCurve
|
||||
# from .ogr2ogrtabletopostgislist import Ogr2OgrTableToPostGisList
|
||||
# from .ogrsql import OgrSql
|
||||
|
||||
@ -175,6 +175,7 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
# gdalcalc(),
|
||||
# rasterize_over(),
|
||||
# ----- OGR tools -----
|
||||
OffsetCurve(),
|
||||
ogrinfo(),
|
||||
OgrToPostGis(),
|
||||
PointsAlongLines(),
|
||||
@ -185,7 +186,6 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
# Ogr2OgrBuffer(),
|
||||
# Ogr2OgrDissolve(),
|
||||
# OneSideBuffer(),
|
||||
# OffsetCurve(),
|
||||
# Ogr2OgrTableToPostGisList(),
|
||||
# OgrSql(),
|
||||
]
|
||||
|
103
python/plugins/processing/algs/gdal/OffsetCurve.py
Normal file
103
python/plugins/processing/algs/gdal/OffsetCurve.py
Normal file
@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
offsetcurve.py
|
||||
---------------------
|
||||
Date : Janaury 2015
|
||||
Copyright : (C) 2015 by Giovanni Manghi
|
||||
Email : giovanni dot manghi at naturalgis dot pt
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Giovanni Manghi'
|
||||
__date__ = 'January 2015'
|
||||
__copyright__ = '(C) 2015, Giovanni Manghi'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsProcessing,
|
||||
QgsProcessingParameterFeatureSource,
|
||||
QgsProcessingParameterString,
|
||||
QgsProcessingParameterNumber,
|
||||
QgsProcessingParameterVectorDestination,
|
||||
QgsProcessingOutputVectorLayer)
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
|
||||
|
||||
class OffsetCurve(GdalAlgorithm):
|
||||
|
||||
INPUT = 'INPUT'
|
||||
GEOMETRY = 'GEOMETRY'
|
||||
DISTANCE = 'DISTANCE'
|
||||
OPTIONS = 'OPTIONS'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
|
||||
self.tr('Input layer'),
|
||||
[QgsProcessing.TypeVectorLine]))
|
||||
self.addParameter(QgsProcessingParameterString(self.GEOMETRY,
|
||||
self.tr('Geometry column name'),
|
||||
defaultValue='geometry'))
|
||||
self.addParameter(QgsProcessingParameterNumber(self.DISTANCE,
|
||||
self.tr('Offset distance (left-sided: positive, right-sided: negative)'),
|
||||
type=QgsProcessingParameterNumber.Double,
|
||||
defaultValue=10))
|
||||
self.addParameter(QgsProcessingParameterString(self.OPTIONS,
|
||||
self.tr('Additional creation options'),
|
||||
defaultValue='',
|
||||
optional=True))
|
||||
|
||||
self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT,
|
||||
self.tr('Offset curve'),
|
||||
QgsProcessing.TypeVectorLine))
|
||||
|
||||
def name(self):
|
||||
return 'offsetcurve'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Offset curve')
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector geoprocessing')
|
||||
|
||||
def commandName(self):
|
||||
return 'ogr2ogr'
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback):
|
||||
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
|
||||
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
|
||||
distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
|
||||
options = self.parameterAsString(parameters, self.OPTIONS, context)
|
||||
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
||||
|
||||
output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
|
||||
|
||||
arguments = []
|
||||
arguments.append(output)
|
||||
arguments.append(ogrLayer)
|
||||
arguments.append('-dialect')
|
||||
arguments.append('sqlite')
|
||||
arguments.append('-sql')
|
||||
|
||||
sql = "SELECT ST_OffsetCurve({}, {}), * FROM '{}'".format(geometry, distance, layerName)
|
||||
arguments.append(sql)
|
||||
|
||||
if options:
|
||||
arguments.append(options)
|
||||
|
||||
return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
|
@ -1,115 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
offsetcurve.py
|
||||
---------------------
|
||||
Date : Janaury 2015
|
||||
Copyright : (C) 2015 by Giovanni Manghi
|
||||
Email : giovanni dot manghi at naturalgis dot pt
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Giovanni Manghi'
|
||||
__date__ = 'January 2015'
|
||||
__copyright__ = '(C) 2015, Giovanni Manghi'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterString
|
||||
from processing.core.parameters import ParameterNumber
|
||||
from processing.core.outputs import OutputVector
|
||||
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
|
||||
from processing.tools import dataobjects
|
||||
from processing.tools.system import isWindows
|
||||
|
||||
|
||||
class OffsetCurve(GdalAlgorithm):
|
||||
|
||||
OUTPUT_LAYER = 'OUTPUT_LAYER'
|
||||
INPUT_LAYER = 'INPUT_LAYER'
|
||||
GEOMETRY = 'GEOMETRY'
|
||||
RADIUS = 'RADIUS'
|
||||
OPTIONS = 'OPTIONS'
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(ParameterVector(self.INPUT_LAYER,
|
||||
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE], False))
|
||||
self.addParameter(ParameterString(self.GEOMETRY,
|
||||
self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
|
||||
'geometry', optional=False))
|
||||
self.addParameter(ParameterNumber(self.RADIUS,
|
||||
self.tr('Offset distance (positive value for left-sided and negative - for right-sided)'),
|
||||
-99999999.999999, 99999999.999999, 1000.0,
|
||||
optional=False))
|
||||
self.addParameter(ParameterString(self.OPTIONS,
|
||||
self.tr('Additional creation options (see ogr2ogr manual)'),
|
||||
'', optional=True))
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Offset line')))
|
||||
|
||||
def name(self):
|
||||
return 'offsetlinesforlines'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Offset lines for lines')
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector geoprocessing')
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback):
|
||||
inLayer = self.getParameterValue(self.INPUT_LAYER)
|
||||
geometry = self.getParameterValue(self.GEOMETRY)
|
||||
distance = self.getParameterValue(self.RADIUS)
|
||||
options = self.getParameterValue(self.OPTIONS)
|
||||
|
||||
ogrLayer = GdalUtils.ogrConnectionString(inLayer, context)[1:-1]
|
||||
layername = "'" + GdalUtils.ogrLayerName(inLayer) + "'"
|
||||
|
||||
output = self.getOutputFromName(self.OUTPUT_LAYER)
|
||||
outFile = output.value
|
||||
output = GdalUtils.ogrConnectionString(outFile, context)
|
||||
|
||||
layername = GdalUtils.ogrLayerName(inLayer)
|
||||
|
||||
arguments = []
|
||||
arguments.append(output)
|
||||
arguments.append(ogrLayer)
|
||||
arguments.append('-dialect')
|
||||
arguments.append('sqlite')
|
||||
arguments.append('-sql')
|
||||
|
||||
sql = "SELECT ST_OffsetCurve({}, {}), * FROM '{}'".format(geometry, distance, layername)
|
||||
|
||||
arguments.append(sql)
|
||||
|
||||
if options is not None and len(options.strip()) > 0:
|
||||
arguments.append(options)
|
||||
|
||||
commands = []
|
||||
if isWindows():
|
||||
commands = ['cmd.exe', '/C ', 'ogr2ogr.exe',
|
||||
GdalUtils.escapeAndJoin(arguments)]
|
||||
else:
|
||||
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
|
||||
|
||||
return commands
|
||||
|
||||
def commandName(self):
|
||||
return 'ogr2ogr'
|
@ -26,7 +26,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
|
||||
from qgis.core import (QgsProcessingParameterVectorLayer,
|
||||
from qgis.core import (QgsProcessingParameterFeatureSource,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterFileDestination,
|
||||
QgsProcessingOutputHtml)
|
||||
@ -45,8 +45,8 @@ class ogrinfo(GdalAlgorithm):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
|
||||
self.tr('Input layer')))
|
||||
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
|
||||
self.tr('Input layer')))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.SUMMARY_ONLY,
|
||||
self.tr('Summary output only'),
|
||||
defaultValue=True))
|
||||
|
@ -338,22 +338,22 @@ tests:
|
||||
compare:
|
||||
ignore_crs_check: true
|
||||
|
||||
# - algorithm: gdal:offsetlinesforlines
|
||||
# name: Offset lines for lines (right-handed)
|
||||
# params:
|
||||
# GEOMETRY: geometry
|
||||
# INPUT_LAYER:
|
||||
# name: lines.gml
|
||||
# type: vector
|
||||
# RADIUS: -0.5
|
||||
# results:
|
||||
# OUTPUT_LAYER:
|
||||
# name: expected/gdal/offset_lines.gml
|
||||
# type: vector
|
||||
# compare:
|
||||
# geometry:
|
||||
# precision: 7
|
||||
#
|
||||
- algorithm: gdal:offsetcurve
|
||||
name: Offset curve (right-handed)
|
||||
params:
|
||||
GEOMETRY: geometry
|
||||
INPUT_LAYER:
|
||||
name: lines.gml
|
||||
type: vector
|
||||
RADIUS: -0.5
|
||||
results:
|
||||
OUTPUT_LAYER:
|
||||
name: expected/gdal/offset_lines.gml
|
||||
type: vector
|
||||
compare:
|
||||
geometry:
|
||||
precision: 7
|
||||
|
||||
# - algorithm: gdal:singlesidedbufferforlines
|
||||
# name: One-side buffer for lines (left-handed)
|
||||
# params:
|
||||
@ -429,4 +429,3 @@ tests:
|
||||
# geometry:
|
||||
# precision: 7
|
||||
#
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user