Skip to content
Permalink
Browse files

Merge pull request #3725 from arnaud-morvan/processing_geometry_predi…

…cate

[processing] Remove parameter geometry predicate
  • Loading branch information
volaya committed Dec 13, 2016
2 parents 9f26574 + 322a565 commit 0035c97f5be74f579c16733ef0efb8bc64ab96f7
@@ -426,7 +426,7 @@ def processCommand(self):
command += ' ' + param.name
elif isinstance(param, ParameterSelection):
idx = int(param.value)
command += ' ' + param.name + '=' + str(param.options[idx])
command += ' ' + param.name + '=' + str(param.options[idx][1])
elif isinstance(param, ParameterString):
command += ' ' + param.name + '="' + str(param.value) + '"'
elif isinstance(param, ParameterPoint):
@@ -276,7 +276,7 @@ def processAlgorithm(self, progress):
elif isinstance(param, ParameterSelection):
commands.append(param.name)
idx = int(param.value)
commands.append(str(param.options[idx]))
commands.append(str(param.options[idx][1]))
elif isinstance(param, ParameterBoolean):
if param.value:
commands.append(param.name)
@@ -29,7 +29,7 @@
from qgis.core import QgsFeatureRequest
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterGeometryPredicate
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
@@ -48,13 +48,24 @@ def defineCharacteristics(self):
self.group, self.i18n_group = self.trAlgorithm('Vector selection tools')
self.tags = self.tr('extract,filter,location,intersects,contains,within')

self.predicates = (
('intersects', self.tr('intersects')),
('contains', self.tr('contains')),
('disjoint', self.tr('disjoint')),
('equals', self.tr('equals')),
('touches', self.tr('touches')),
('overlaps', self.tr('overlaps')),
('within', self.tr('within')),
('crosses', self.tr('crosses')))

self.addParameter(ParameterVector(self.INPUT,
self.tr('Layer to select from')))
self.addParameter(ParameterVector(self.INTERSECT,
self.tr('Additional layer (intersection layer)')))
self.addParameter(ParameterGeometryPredicate(self.PREDICATE,
self.tr('Geometric predicate'),
left=self.INPUT, right=self.INTERSECT))
self.addParameter(ParameterSelection(self.PREDICATE,
self.tr('Geometric predicate'),
self.predicates,
multiple=True))
self.addParameter(ParameterNumber(self.PRECISION,
self.tr('Precision'),
0.0, None, 0.0))
@@ -98,20 +109,7 @@ def processAlgorithm(self, progress):
except:
pass # already removed
else:
if predicate == 'intersects':
res = tmpGeom.intersects(geom)
elif predicate == 'contains':
res = tmpGeom.contains(geom)
elif predicate == 'equals':
res = tmpGeom.equals(geom)
elif predicate == 'touches':
res = tmpGeom.touches(geom)
elif predicate == 'overlaps':
res = tmpGeom.overlaps(geom)
elif predicate == 'within':
res = tmpGeom.within(geom)
elif predicate == 'crosses':
res = tmpGeom.crosses(geom)
res = getattr(tmpGeom, predicate)(geom)
if res:
selectedSet.append(feat.id())
break
@@ -35,7 +35,6 @@
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterGeometryPredicate
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
@@ -59,6 +58,16 @@ def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Select by location')
self.group, self.i18n_group = self.trAlgorithm('Vector selection tools')

self.predicates = (
('intersects', self.tr('intersects')),
('contains', self.tr('contains')),
('disjoint', self.tr('disjoint')),
('equals', self.tr('equals')),
('touches', self.tr('touches')),
('overlaps', self.tr('overlaps')),
('within', self.tr('within')),
('crosses', self.tr('crosses')))

self.methods = [self.tr('creating new selection'),
self.tr('adding to current selection'),
self.tr('removing from current selection')]
@@ -67,9 +76,10 @@ def defineCharacteristics(self):
self.tr('Layer to select from')))
self.addParameter(ParameterVector(self.INTERSECT,
self.tr('Additional layer (intersection layer)')))
self.addParameter(ParameterGeometryPredicate(self.PREDICATE,
self.tr('Geometric predicate'),
left=self.INPUT, right=self.INTERSECT))
self.addParameter(ParameterSelection(self.PREDICATE,
self.tr('Geometric predicate'),
self.predicates,
multiple=True))
self.addParameter(ParameterNumber(self.PRECISION,
self.tr('Precision'),
0.0, None, 0.0))
@@ -118,20 +128,7 @@ def processAlgorithm(self, progress):
except:
pass # already removed
else:
if predicate == 'intersects':
res = tmpGeom.intersects(geom)
elif predicate == 'contains':
res = tmpGeom.contains(geom)
elif predicate == 'equals':
res = tmpGeom.equals(geom)
elif predicate == 'touches':
res = tmpGeom.touches(geom)
elif predicate == 'overlaps':
res = tmpGeom.overlaps(geom)
elif predicate == 'within':
res = tmpGeom.within(geom)
elif predicate == 'crosses':
res = tmpGeom.crosses(geom)
res = getattr(tmpGeom, predicate)(geom)
if res:
selectedSet.append(feat.id())
break
@@ -37,7 +37,6 @@

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterGeometryPredicate
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterString
@@ -64,6 +63,15 @@ def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Join attributes by location')
self.group, self.i18n_group = self.trAlgorithm('Vector general tools')

self.predicates = (
('intersects', self.tr('intersects')),
('contains', self.tr('contains')),
('equals', self.tr('equals')),
('touches', self.tr('touches')),
('overlaps', self.tr('overlaps')),
('within', self.tr('within')),
('crosses', self.tr('crosses')))

self.summarys = [
self.tr('Take attributes of the first located feature'),
self.tr('Take summary of intersecting features')
@@ -78,12 +86,10 @@ def defineCharacteristics(self):
self.tr('Target vector layer')))
self.addParameter(ParameterVector(self.JOIN,
self.tr('Join vector layer')))
predicates = list(ParameterGeometryPredicate.predicates)
predicates.remove('disjoint')
self.addParameter(ParameterGeometryPredicate(self.PREDICATE,
self.tr('Geometric predicate'),
left=self.TARGET, right=self.JOIN,
enabledPredicates=predicates))
self.addParameter(ParameterSelection(self.PREDICATE,
self.tr('Geometric predicate'),
self.predicates,
multiple=True))
self.addParameter(ParameterNumber(self.PRECISION,
self.tr('Precision'),
0.0, None, 0.0))
@@ -174,20 +180,7 @@ def processAlgorithm(self, progress):

res = False
for predicate in predicates:
if predicate == 'intersects':
res = inGeom.intersects(inGeomB)
elif predicate == 'contains':
res = inGeom.contains(inGeomB)
elif predicate == 'equals':
res = inGeom.equals(inGeomB)
elif predicate == 'touches':
res = inGeom.touches(inGeomB)
elif predicate == 'overlaps':
res = inGeom.overlaps(inGeomB)
elif predicate == 'within':
res = inGeom.within(inGeomB)
elif predicate == 'crosses':
res = inGeom.crosses(inGeomB)
res= getattr(inGeom, predicate)(inGeomB)
if res:
break

@@ -1063,41 +1063,58 @@ def __init__(self, name='', description='', options=[], default=None, isSource=F
elif isinstance(self.options, str):
self.options = self.options.split(";")

# compute options as (value, text)
options = []
for i, option in enumerate(self.options):
if option is None or isinstance(option, basestring):
options.append((i, option))
else:
options.append((option[0], option[1]))
self.options = options
self.values = [option[0] for option in options]

self.value = None
if default is not None:
try:
self.default = int(default)
except:
self.default = 0
self.value = self.default
self.setValue(self.default)

def setValue(self, value):
if value is None:
if not self.optional:
return False
self.value = 0
self.value = None
return True

if isinstance(value, list):
if not self.multiple:
return False
values = []
for v in value:
if v in self.values:
values.append(v)
continue
try:
n = int(v)
values.append(n)
v = int(v)
except:
pass
if not v in self.values:
return False
values.append(v)
if not self.optional and len(values) == 0:
return False
self.value = values
return True
else:
try:
n = int(value)
self.value = n
if value in self.values:
self.value = value
return True
try:
value = int(value)
except:
pass
if not value in self.values:
return False
self.value = value
return True

@classmethod
def fromScriptCode(self, line):
@@ -1510,46 +1527,6 @@ def fromScriptCode(self, line):
[dataobjects.TYPE_VECTOR_POLYGON], isOptional)


class ParameterGeometryPredicate(Parameter):

predicates = ('intersects',
'contains',
'disjoint',
'equals',
'touches',
'overlaps',
'within',
'crosses')

def __init__(self, name='', description='', left=None, right=None,
optional=False, enabledPredicates=None):
Parameter.__init__(self, name, description, None, optional)
self.left = left
self.right = right
self.value = None
self.enabledPredicates = enabledPredicates
if self.enabledPredicates is None:
self.enabledPredicates = self.predicates

def getValueAsCommandLineParameter(self):
return str(self.value)

def setValue(self, value):
if value is None:
if not self.optional:
return False
self.value = None
return True
elif len(value) == 0 and not self.optional:
return False

if isinstance(value, str):
self.value = value.split(';') # relates to ModelerAlgorithm.resolveValue
else:
self.value = value
return True


paramClasses = [c for c in list(sys.modules[__name__].__dict__.values()) if isclass(c) and issubclass(c, Parameter)]


@@ -38,7 +38,6 @@
from qgis.gui import QgsMessageBar

from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from processing.gui.GeometryPredicateSelectionPanel import GeometryPredicateSelectionPanel

from processing.core.parameters import ParameterFile
from processing.core.parameters import ParameterRaster
@@ -50,7 +49,6 @@
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterFixedTable
from processing.core.parameters import ParameterMultipleInput
from processing.core.parameters import ParameterGeometryPredicate

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(

0 comments on commit 0035c97

Please sign in to comment.
You can’t perform that action at this time.