2015-02-05 22:55:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
ogr2ogrpointsonlines.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.parameters import ParameterBoolean
|
|
|
|
from processing.core.outputs import OutputVector
|
|
|
|
|
|
|
|
from processing.tools.system import isWindows
|
|
|
|
|
|
|
|
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
|
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
|
|
|
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2015-02-05 22:55:44 +00:00
|
|
|
class Ogr2OgrPointsOnLines(OgrAlgorithm):
|
|
|
|
|
|
|
|
OUTPUT_LAYER = 'OUTPUT_LAYER'
|
|
|
|
INPUT_LAYER = 'INPUT_LAYER'
|
|
|
|
DISTANCE = 'DISTANCE'
|
|
|
|
GEOMETRY = 'GEOMETRY'
|
|
|
|
OPTIONS = 'OPTIONS'
|
|
|
|
|
|
|
|
def defineCharacteristics(self):
|
2015-07-26 03:48:27 +02:00
|
|
|
self.name, self.i18n_name = self.trAlgorithm('Create points along lines')
|
|
|
|
self.group, self.i18n_group = self.trAlgorithm('[OGR] Geoprocessing')
|
2015-02-05 22:55:44 +00:00
|
|
|
|
2015-02-24 12:35:00 +02:00
|
|
|
self.addParameter(ParameterVector(self.INPUT_LAYER,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_LINE], False))
|
2015-02-24 12:35:00 +02:00
|
|
|
self.addParameter(ParameterString(self.GEOMETRY,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
|
|
|
|
'geometry', optional=False))
|
2015-02-24 12:35:00 +02:00
|
|
|
self.addParameter(ParameterNumber(self.DISTANCE,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Distance from line start represented as fraction of line length'), 0, 1, 0.5))
|
2015-02-24 12:35:00 +02:00
|
|
|
self.addParameter(ParameterString(self.OPTIONS,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Additional creation options (see ogr2ogr manual)'),
|
|
|
|
'', optional=True))
|
2015-02-24 12:35:00 +02:00
|
|
|
|
2015-05-18 09:29:41 +02:00
|
|
|
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Points along lines')))
|
2015-02-05 22:55:44 +00:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2015-02-05 22:55:44 +00:00
|
|
|
inLayer = self.getParameterValue(self.INPUT_LAYER)
|
|
|
|
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
|
|
|
|
layername = "'" + self.ogrLayerName(inLayer) + "'"
|
|
|
|
distance = unicode(self.getParameterValue(self.DISTANCE))
|
|
|
|
geometry = unicode(self.getParameterValue(self.GEOMETRY))
|
2015-02-24 12:35:00 +02:00
|
|
|
|
2015-02-05 22:55:44 +00:00
|
|
|
output = self.getOutputFromName(self.OUTPUT_LAYER)
|
|
|
|
outFile = output.value
|
|
|
|
|
|
|
|
output = self.ogrConnectionString(outFile)
|
|
|
|
options = unicode(self.getParameterValue(self.OPTIONS))
|
|
|
|
|
|
|
|
arguments = []
|
|
|
|
arguments.append(output)
|
|
|
|
arguments.append(ogrLayer)
|
|
|
|
arguments.append(self.ogrLayerName(inLayer))
|
2015-02-24 12:35:00 +02:00
|
|
|
|
2015-02-05 22:55:44 +00:00
|
|
|
arguments.append('-dialect sqlite -sql "SELECT ST_Line_Interpolate_Point(')
|
|
|
|
arguments.append(geometry)
|
|
|
|
arguments.append(',')
|
|
|
|
arguments.append(distance)
|
|
|
|
arguments.append('),*')
|
|
|
|
arguments.append('FROM')
|
|
|
|
arguments.append(layername)
|
|
|
|
arguments.append('"')
|
2015-02-24 12:35:00 +02:00
|
|
|
|
2015-02-05 22:55:44 +00:00
|
|
|
if len(options) > 0:
|
|
|
|
arguments.append(options)
|
2015-02-24 12:35:00 +02:00
|
|
|
|
2015-02-05 22:55:44 +00:00
|
|
|
commands = []
|
|
|
|
if isWindows():
|
|
|
|
commands = ['cmd.exe', '/C ', 'ogr2ogr.exe',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
|
|
|
else:
|
|
|
|
commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
|
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return commands
|
2015-05-21 15:43:47 +02:00
|
|
|
|
|
|
|
def commandName(self):
|
2015-08-22 14:29:41 +02:00
|
|
|
return "ogr2ogr"
|