-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] restore clip vector by mask algorithm
- Loading branch information
Showing
4 changed files
with
103 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
python/plugins/processing/algs/gdal/ClipVectorByMask.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
ClipVectorByMask.py | ||
--------------------- | ||
Date : November 2012 | ||
Copyright : (C) 2012 by Victor Olaya | ||
Email : volayaf at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* 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__ = 'Victor Olaya' | ||
__date__ = 'November 2012' | ||
__copyright__ = '(C) 2012, Victor Olaya' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
from qgis.core import (QgsProcessing, | ||
QgsProcessingParameterDefinition, | ||
QgsProcessingParameterString, | ||
QgsProcessingParameterFeatureSource, | ||
QgsProcessingParameterVectorDestination) | ||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm | ||
from processing.algs.gdal.GdalUtils import GdalUtils | ||
|
||
|
||
class ClipVectorByMask(GdalAlgorithm): | ||
|
||
INPUT = 'INPUT' | ||
MASK = 'MASK' | ||
OPTIONS = 'OPTIONS' | ||
OUTPUT = 'OUTPUT' | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def initAlgorithm(self, config=None): | ||
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, | ||
self.tr('Input layer'))) | ||
self.addParameter(QgsProcessingParameterFeatureSource(self.MASK, | ||
self.tr('Mask layer'), | ||
[QgsProcessing.TypeVectorPolygon])) | ||
|
||
options_param = QgsProcessingParameterString(self.OPTIONS, | ||
self.tr('Additional creation options'), | ||
defaultValue='', | ||
optional=True) | ||
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) | ||
self.addParameter(options_param) | ||
|
||
self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT, | ||
self.tr('Clipped (mask)'))) | ||
|
||
def name(self): | ||
return 'clipvectorbypolygon' | ||
|
||
def displayName(self): | ||
return self.tr('Clip vector by mask layer') | ||
|
||
def group(self): | ||
return self.tr('Vector geoprocessing') | ||
|
||
def commandName(self): | ||
return 'ogr2ogr' | ||
|
||
def getConsoleCommands(self, parameters, context, feedback): | ||
inLayer, inLayerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback) | ||
maskLayer, maskLayerName = self.getOgrCompatibleSource(self.MASK, parameters, context, feedback) | ||
options = self.parameterAsString(parameters, self.OPTIONS, context) | ||
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) | ||
|
||
output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context) | ||
|
||
arguments = [] | ||
arguments.append('-clipsrc') | ||
arguments.append(maskLayer) | ||
arguments.append('-clipsrclayer') | ||
arguments.append(maskLayerName) | ||
|
||
arguments.append(output) | ||
arguments.append(inLayer) | ||
arguments.append(inLayerName) | ||
|
||
if options: | ||
arguments.append(options) | ||
|
||
if outputFormat: | ||
arguments.append('-f {}'.format(outputFormat)) | ||
|
||
return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.