Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] restore clip vector by mask algorithm
  • Loading branch information
alexbruy committed Oct 11, 2017
1 parent 679cc2c commit 6c7a292
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 108 deletions.
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/gdal/ClipVectorByExtent.py
Expand Up @@ -59,8 +59,7 @@ def initAlgorithm(self, config=None):
self.addParameter(options_param)

self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT,
self.tr('Clipped (extent)'),
QgsProcessing.TypeVectorPolygon))
self.tr('Clipped (extent)')))

def name(self):
return 'clipvectorbyextent'
Expand Down
100 changes: 100 additions & 0 deletions python/plugins/processing/algs/gdal/ClipVectorByMask.py
@@ -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)]
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
Expand Up @@ -75,14 +75,14 @@

from .Buffer import Buffer
from .ClipVectorByExtent import ClipVectorByExtent
from .ClipVectorByMask import ClipVectorByMask
from .OffsetCurve import OffsetCurve
from .ogrinfo import ogrinfo
from .OgrToPostGis import OgrToPostGis
from .OneSideBuffer import OneSideBuffer
from .PointsAlongLines import PointsAlongLines

# from .ogr2ogr import Ogr2Ogr
# from .ogr2ogrclip import Ogr2OgrClip
# from .ogr2ogrtopostgislist import Ogr2OgrToPostGisList
# from .ogr2ogrdissolve import Ogr2OgrDissolve
# from .ogr2ogrtabletopostgislist import Ogr2OgrTableToPostGisList
Expand Down Expand Up @@ -177,13 +177,13 @@ def loadAlgorithms(self):
# ----- OGR tools -----
Buffer(),
ClipVectorByExtent(),
ClipVectorByMask(),
OffsetCurve(),
ogrinfo(),
OgrToPostGis(),
OneSideBuffer(),
PointsAlongLines(),
# Ogr2Ogr(),
# Ogr2OgrClip(),
# Ogr2OgrToPostGisList(),
# Ogr2OgrDissolve(),
# Ogr2OgrTableToPostGisList(),
Expand Down
104 changes: 0 additions & 104 deletions python/plugins/processing/algs/gdal/ogr2ogrclip.py

This file was deleted.

0 comments on commit 6c7a292

Please sign in to comment.