Showing with 509 additions and 190 deletions.
  1. +10 −2 python/plugins/processing/algs/QGISAlgorithmProvider.py
  2. +6 −7 python/plugins/processing/algs/SaveSelectedFeatures.py
  3. +0 −2 python/plugins/processing/algs/ftools/CMakeLists.txt
  4. +84 −0 python/plugins/processing/algs/ftools/ExtractByLocation.py
  5. +96 −0 python/plugins/processing/algs/ftools/RandomExtract.py
  6. +134 −0 python/plugins/processing/algs/ftools/RandomExtractWithinSubsets.py
  7. +0 −6 python/plugins/processing/algs/ftools/RandomSelectionWithinSubsets.py
  8. +2 −7 python/plugins/processing/algs/ftools/SelectByLocation.py
  9. BIN python/plugins/processing/algs/ftools/icons/analysis.png
  10. BIN python/plugins/processing/algs/ftools/icons/basic_statistics.png
  11. BIN python/plugins/processing/algs/ftools/icons/buffer.png
  12. BIN python/plugins/processing/algs/ftools/icons/centroids.png
  13. BIN python/plugins/processing/algs/ftools/icons/check_geometry.png
  14. BIN python/plugins/processing/algs/ftools/icons/clip.png
  15. BIN python/plugins/processing/algs/ftools/icons/convex_hull.png
  16. BIN python/plugins/processing/algs/ftools/icons/define_projection.png
  17. BIN python/plugins/processing/algs/ftools/icons/delaunay.png
  18. BIN python/plugins/processing/algs/ftools/icons/difference.png
  19. BIN python/plugins/processing/algs/ftools/icons/dissolve.png
  20. BIN python/plugins/processing/algs/ftools/icons/export_geometry.png
  21. BIN python/plugins/processing/algs/ftools/icons/export_projection.png
  22. BIN python/plugins/processing/algs/ftools/icons/extract_nodes.png
  23. BIN python/plugins/processing/algs/ftools/icons/ftools_logo.png
  24. BIN python/plugins/processing/algs/ftools/icons/geometry.png
  25. BIN python/plugins/processing/algs/ftools/icons/geoprocessing.png
  26. BIN python/plugins/processing/algs/ftools/icons/help.png
  27. BIN python/plugins/processing/algs/ftools/icons/intersect.png
  28. BIN python/plugins/processing/algs/ftools/icons/intersections.png
  29. BIN python/plugins/processing/algs/ftools/icons/join_attributes.png
  30. BIN python/plugins/processing/algs/ftools/icons/join_location.png
  31. BIN python/plugins/processing/algs/ftools/icons/layer_extent.png
  32. BIN python/plugins/processing/algs/ftools/icons/management.png
  33. BIN python/plugins/processing/algs/ftools/icons/matrix.png
  34. BIN python/plugins/processing/algs/ftools/icons/mean.png
  35. BIN python/plugins/processing/algs/ftools/icons/merge_shapes.png
  36. BIN python/plugins/processing/algs/ftools/icons/multi_to_single.png
  37. BIN python/plugins/processing/algs/ftools/icons/neighbour.png
  38. BIN python/plugins/processing/algs/ftools/icons/random_points.png
  39. BIN python/plugins/processing/algs/ftools/icons/random_selection.png
  40. BIN python/plugins/processing/algs/ftools/icons/regular_points.png
  41. BIN python/plugins/processing/algs/ftools/icons/reproject.png
  42. BIN python/plugins/processing/algs/ftools/icons/sampling.png
  43. BIN python/plugins/processing/algs/ftools/icons/select_location.png
  44. BIN python/plugins/processing/algs/ftools/icons/simplify.png
  45. BIN python/plugins/processing/algs/ftools/icons/single_to_multi.png
  46. BIN python/plugins/processing/algs/ftools/icons/split_layer.png
  47. BIN python/plugins/processing/algs/ftools/icons/sub_selection.png
  48. BIN python/plugins/processing/algs/ftools/icons/sum_lines.png
  49. BIN python/plugins/processing/algs/ftools/icons/sum_points.png
  50. BIN python/plugins/processing/algs/ftools/icons/sym_difference.png
  51. BIN python/plugins/processing/algs/ftools/icons/to_lines.png
  52. BIN python/plugins/processing/algs/ftools/icons/union.png
  53. BIN python/plugins/processing/algs/ftools/icons/unique.png
  54. BIN python/plugins/processing/algs/ftools/icons/vector_grid.png
  55. BIN python/plugins/processing/algs/ftools/icons/voronoi.png
  56. +1 −2 python/plugins/processing/algs/mmqgisx/CMakeLists.txt
  57. +162 −160 python/plugins/processing/algs/mmqgisx/MMQGISXAlgorithms.py
  58. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis.png
  59. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_animate_columns.png
  60. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_animate_rows.png
  61. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_attribute_export.png
  62. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_attribute_join.png
  63. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_color_map.png
  64. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_float_to_text.png
  65. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_geocode_google.png
  66. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_geocode_street_layer.png
  67. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_grid.png
  68. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_gridify.png
  69. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_hub_distance.png
  70. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_label.png
  71. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_merge.png
  72. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_select.png
  73. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_simplify.png
  74. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_sort.png
  75. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_text_to_float.png
  76. BIN python/plugins/processing/algs/mmqgisx/icons/mmqgis_voronoi.png
  77. +3 −0 python/plugins/processing/core/SilentProgress.py
  78. +7 −0 python/plugins/processing/gui/MessageBarProgress.py
  79. +1 −1 python/plugins/processing/gui/ProcessingToolbox.py
  80. +1 −1 python/plugins/processing/gui/UnthreadedAlgorithmExecutor.py
  81. +2 −2 python/plugins/processing/modeler/ModelerAlgorithm.py
12 changes: 10 additions & 2 deletions python/plugins/processing/algs/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
__revision__ = '$Format:%H$'

from PyQt4.QtGui import *
from processing.algs.ftools.RandomExtract import RandomExtract
from processing.algs.ftools.RandomExtractWithinSubsets import \
RandomExtractWithinSubsets
from processing.algs.ftools.ExtractByLocation import ExtractByLocation

from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.algs.ftools.PointsInPolygon import PointsInPolygon
from processing.algs.ftools.PointsInPolygonUnique import PointsInPolygonUnique
Expand Down Expand Up @@ -80,7 +85,8 @@
mmqgisx_geometry_convert_algorithm, mmqgisx_grid_algorithm, \
mmqgisx_gridify_algorithm, mmqgisx_hub_distance_algorithm, \
mmqgisx_hub_lines_algorithm, mmqgisx_merge_algorithm, \
mmqgisx_select_algorithm, mmqgisx_text_to_float_algorithm
mmqgisx_select_algorithm, mmqgisx_text_to_float_algorithm,\
mmqgisx_extract_algorithm

from processing.algs.Polygonize import Polygonize
from processing.algs.RasterLayerStatistics import RasterLayerStatistics
Expand Down Expand Up @@ -128,7 +134,8 @@ def __init__(self):
VariableDistanceBuffer(), Dissolve(), Difference(),
Intersection(), Union(), Clip(), ExtentFromLayer(),
RandomSelection(), RandomSelectionWithinSubsets(),
SelectByLocation(),
SelectByLocation(), RandomExtract(), RandomExtractWithinSubsets(),
ExtractByLocation(),
# ------ mmqgisx ------
mmqgisx_delete_columns_algorithm(),
mmqgisx_delete_duplicate_geometries_algorithm(),
Expand All @@ -139,6 +146,7 @@ def __init__(self):
mmqgisx_hub_lines_algorithm(),
mmqgisx_merge_algorithm(),
mmqgisx_select_algorithm(),
mmqgisx_extract_algorithm(),
mmqgisx_text_to_float_algorithm(),
# ------ native algs ------
AddTableField(), FieldsCalculator(),
Expand Down
13 changes: 6 additions & 7 deletions python/plugins/processing/algs/SaveSelectedFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,28 @@ def processAlgorithm(self, progress):
# first available format from the provider is used, and the
# corresponding file extension appended.

provider = vectorLayer.dataProvider()

# vectorLayer.crs() is the layer crs. By default all resulting
# layers are assumed to be in the same crs are the inputs, and
# will be loaded with this assumptions when executed from the
# toolbox. The self.crs variable has to be canged in case this
# toolbox. The self.crs variable has to be changed in case this
# is not true, or in case there are no input layer from which
# the output crs can be infered


provider = vectorLayer.dataProvider()

writer = output.getVectorWriter(provider.fields(),
provider.geometryType(), vectorLayer.crs())

# Now we take the selected features and add them to the output
# layer
features = vector.features(vectorLayer)
total = len(features)
i = 0
total = len(features)
for (i, feat) in enumerate(features):
writer.addFeature(feat)

# We use the progress object to communicate with the user
progress.setPercentage(100 * i / float(total))
i += 1
progress.setPercentage(100 * i / float(total))
del writer

# There is nothing more to do here. We do not have to open the
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/ftools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
FILE(GLOB PY_FILES *.py)
FILE(GLOB OTHER_FILES copyright.txt)
FILE(GLOB ICON_FILES icons/*.png)

PLUGIN_INSTALL(processing ./algs/ftools ${PY_FILES} ${OTHER_FILES})
PLUGIN_INSTALL(processing ./algs/ftools/icons ${ICON_FILES})
84 changes: 84 additions & 0 deletions python/plugins/processing/algs/ftools/ExtractByLocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
ExtractByLocation.py
---------------------
Date : August 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__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from PyQt4.QtCore import *
from qgis.core import *
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterVector import ParameterVector
from processing.outputs.OutputVector import OutputVector
from processing.tools import dataobjects, vector


class ExtractByLocation(GeoAlgorithm):

INPUT = 'INPUT'
INTERSECT = 'INTERSECT'
OUTPUT = 'OUTPUT'

def defineCharacteristics(self):
self.name = 'Extract by location'
self.group = 'Vector selection tools'
self.addParameter(ParameterVector(self.INPUT, 'Layer to select from',
[ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterVector(self.INTERSECT,
'Additional layer (intersection layer)',
[ParameterVector.VECTOR_TYPE_ANY]))
self.addOutput(OutputVector(self.OUTPUT, 'Selection'))

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
layer = dataobjects.getObjectFromUri(filename)
filename = self.getParameterValue(self.INTERSECT)
selectLayer = dataobjects.getObjectFromUri(filename)
index = vector.spatialindex(layer)

geom = QgsGeometry()
selectedSet = []
current = 0
features = vector.features(selectLayer)
featureCount = len(features)
total = 100.0 / float(len(features))
for current,f in enumerate(features):
geom = QgsGeometry(f.geometry())
intersects = index.intersects(geom.boundingBox())
for i in intersects:
request = QgsFeatureRequest().setFilterFid(i)
feat = layer.getFeatures(request).next()
tmpGeom = QgsGeometry(feat.geometry())
if geom.intersects(tmpGeom):
selectedSet.append(feat.id())
progress.setPercentage(int(current * total))

output = self.getOutputFromName(self.OUTPUT)
writer = output.getVectorWriter(layer.fields(),
layer.geometryType(), layer.crs())

for (i, feat) in enumerate(features):
if feat.id() in selectedSet:
writer.addFeature(feat)
progress.setPercentage(100 * i / float(featureCount))
del writer
96 changes: 96 additions & 0 deletions python/plugins/processing/algs/ftools/RandomExtract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
RandomExtract.py
---------------------
Date : August 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__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import random

from PyQt4.QtCore import *
from qgis.core import *

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from processing.parameters.ParameterSelection import ParameterSelection
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterNumber import ParameterNumber
from processing.outputs.OutputVector import OutputVector
from processing.tools import dataobjects, vector


class RandomExtract(GeoAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
METHOD = 'METHOD'
NUMBER = 'NUMBER'

METHODS = ['Number of selected features',
'Percentage of selected features']
def defineCharacteristics(self):
self.name = 'Random extract'
self.group = 'Vector selection tools'

self.addParameter(ParameterVector(self.INPUT, 'Input layer',
[ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterSelection(self.METHOD, 'Method',
self.METHODS, 0))
self.addParameter(ParameterNumber(self.NUMBER,
'Number/percentage of selected features', 0, None,
10))
self.addOutput(OutputVector(self.OUTPUT, 'Selection'))

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
layer = dataobjects.getObjectFromUri(filename)
method = self.getParameterValue(self.METHOD)

features = vector.features(layer)
featureCount = len(features)
value = int(self.getParameterValue(self.NUMBER))

if method == 0:
if value > featureCount:
raise GeoAlgorithmExecutionException(
'Selected number is greater than feature count. \
Choose a lower value and try again.')
else:
if value > 100:
raise GeoAlgorithmExecutionException(
"Percentage can't be greater than 100. Set a \
different value and try again.")
value = int(round(value / 100.0000, 4) * featureCount)

selran = random.sample(xrange(0, featureCount), value)

output = self.getOutputFromName(self.OUTPUT)
writer = output.getVectorWriter(layer.fields(),
layer.geometryType(), layer.crs())

for (i, feat) in enumerate(features):
if i in selran:
writer.addFeature(feat)
progress.setPercentage(100 * i / float(featureCount))
del writer
134 changes: 134 additions & 0 deletions python/plugins/processing/algs/ftools/RandomExtractWithinSubsets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
RandomSelectionWithinSubsets.py
---------------------
Date : August 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__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import random
from PyQt4.QtCore import *
from qgis.core import *
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from processing.parameters.ParameterSelection import ParameterSelection
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterTableField import ParameterTableField
from processing.outputs.OutputVector import OutputVector
from processing.tools import dataobjects, vector


class RandomExtractWithinSubsets(GeoAlgorithm):

INPUT = 'INPUT'
METHOD = 'METHOD'
NUMBER = 'NUMBER'
FIELD = 'FIELD'
OUTPUT = 'OUTPUT'

METHODS = ['Number of selected features',
'Percentage of selected features']

def defineCharacteristics(self):
self.name = 'Random extract within subsets'
self.group = 'Vector selection tools'

self.addParameter(ParameterVector(self.INPUT, 'Input layer',
[ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(self.FIELD, 'ID Field',
self.INPUT))
self.addParameter(ParameterSelection(self.METHOD, 'Method',
self.METHODS, 0))
self.addParameter(ParameterNumber(self.NUMBER,
'Number/percentage of selected features', 1, None,
10))

self.addOutput(OutputVector(self.OUTPUT, 'Selection'))

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)

layer = dataobjects.getObjectFromUri(filename)
field = self.getParameterValue(self.FIELD)
method = self.getParameterValue(self.METHOD)

index = layer.fieldNameIndex(field)

features = vector.features(layer)
featureCount = len(features)
unique = vector.getUniqueValues(layer, index)
value = int(self.getParameterValue(self.NUMBER))
if method == 0:
if value > featureCount:
raise GeoAlgorithmExecutionException(
'Selected number is greater that feature count. \
Choose lesser value and try again.')
else:
if value > 100:
raise GeoAlgorithmExecutionException(
"Percentage can't be greater than 100. Set correct \
value and try again.")
value = value / 100.0


output = self.getOutputFromName(self.OUTPUT)
writer = output.getVectorWriter(layer.fields(),
layer.geometryType(), layer.crs())

selran = []
current = 0
total = 100.0 / float(featureCount * len(unique))
features = vector.features(layer)

if not len(unique) == featureCount:
for classValue in unique:
classFeatures = []
for i, feature in enumerate(features):
attrs = feature.attributes()
if attrs[index] == classValue:
classFeatures.append(i)
current += 1
progress.setPercentage(int(current * total))

if method == 1:
selValue = int(round(value * len(classFeatures), 0))
else:
selValue = value

if selValue >= len(classFeatures):
selFeat = classFeatures
else:
selFeat = random.sample(classFeatures, selValue)

selran.extend(selFeat)
else:
selran = range(0, featureCount)


features = vector.features(layer)
for (i, feat) in enumerate(features):
if i in selran:
writer.addFeature(feat)
progress.setPercentage(100 * i / float(featureCount))
del writer
Loading