Skip to content
Permalink
Browse files
Processing tests (#4259)
* [processing] qgis regular points test

* [processing] qgis shape buffer variable tests

* [processing] qgis create grid lines test

* [processing] qgis convert geometry test

* [processing] qgis extract by location test

* [processing] qgis add field test

* [processing] trying to fix travis failing

* [processing] trying to fix travis failing/2

* trying to fix travis failing/3

* [processing] Add new default option "ProjectCrs" to ParameterCrs

* [processing] RegularPoints tests shouldn't rely on iface

* [processing] Fix regular points test

* [processing] RandmPointsExtent new CRS parameter

* [processing] qgis random point in extent test

* [processing] qgis random point in extent test/2

* [processing] remove qgis random point in extent test

* no output random points in extent test

* remove useless output
  • Loading branch information
ghtmtt authored and m-kuhn committed Mar 16, 2017
1 parent 56e6752 commit 3bcf287a7e2a5569aeb2da713154cc860a4bfde7
Showing with 3,626 additions and 9 deletions.
  1. +11 −4 python/plugins/processing/algs/qgis/RandomPointsExtent.py
  2. +9 −3 python/plugins/processing/algs/qgis/RegularPoints.py
  3. +5 −0 python/plugins/processing/core/parameters.py
  4. +8 −2 python/plugins/processing/gui/wrappers.py
  5. +26 −0 python/plugins/processing/tests/testdata/expected/add_field.gfs
  6. +77 −0 python/plugins/processing/tests/testdata/expected/add_field.gml
  7. +21 −0 python/plugins/processing/tests/testdata/expected/buffer_diamond.gfs
  8. +74 −0 python/plugins/processing/tests/testdata/expected/buffer_diamond.gml
  9. +21 −0 python/plugins/processing/tests/testdata/expected/buffer_ovals.gfs
  10. +74 −0 python/plugins/processing/tests/testdata/expected/buffer_ovals.gml
  11. +21 −0 python/plugins/processing/tests/testdata/expected/buffer_rect.gfs
  12. +74 −0 python/plugins/processing/tests/testdata/expected/buffer_rect.gml
  13. +32 −0 python/plugins/processing/tests/testdata/expected/convert_poly_centroid.gfs
  14. +52 −0 python/plugins/processing/tests/testdata/expected/convert_poly_centroid.gml
  15. +32 −0 python/plugins/processing/tests/testdata/expected/convert_poly_multiline.gfs
  16. +52 −0 python/plugins/processing/tests/testdata/expected/convert_poly_multiline.gml
  17. +32 −0 python/plugins/processing/tests/testdata/expected/convert_poly_nodes.gfs
  18. +255 −0 python/plugins/processing/tests/testdata/expected/convert_poly_nodes.gml
  19. +46 −0 python/plugins/processing/tests/testdata/expected/create_grid_lines.gfs
  20. +1,730 −0 python/plugins/processing/tests/testdata/expected/create_grid_lines.gml
  21. +32 −0 python/plugins/processing/tests/testdata/expected/extract_by_location_intersection.gfs
  22. +37 −0 python/plugins/processing/tests/testdata/expected/extract_by_location_intersection.gml
  23. +26 −0 python/plugins/processing/tests/testdata/expected/extract_by_location_within.gfs
  24. +28 −0 python/plugins/processing/tests/testdata/expected/extract_by_location_within.gml
  25. +21 −0 python/plugins/processing/tests/testdata/expected/regular_points.gfs
  26. +662 −0 python/plugins/processing/tests/testdata/expected/regular_points.gml
  27. +168 −0 python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
@@ -32,13 +32,15 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsGeometry, QgsRectangle, QgsFeature, QgsFields, QgsWkbTypes,
QgsField, QgsSpatialIndex, QgsPoint)
QgsField, QgsSpatialIndex, QgsPoint,
QgsCoordinateReferenceSystem)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterExtent
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterCrs
from processing.core.outputs import OutputVector
from processing.tools import vector, dataobjects

@@ -51,6 +53,7 @@ class RandomPointsExtent(GeoAlgorithm):
POINT_NUMBER = 'POINT_NUMBER'
MIN_DISTANCE = 'MIN_DISTANCE'
OUTPUT = 'OUTPUT'
CRS = 'CRS'

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'random_points.png'))
@@ -64,14 +67,19 @@ def defineCharacteristics(self):
self.tr('Points number'), 1, None, 1))
self.addParameter(ParameterNumber(self.MIN_DISTANCE,
self.tr('Minimum distance'), 0.0, None, 0.0))

self.addParameter(ParameterCrs(self.CRS,
self.tr('Output layer CRS'), 'ProjectCrs'))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Random points'), datatype=[dataobjects.TYPE_VECTOR_POINT]))

def processAlgorithm(self, feedback):
pointCount = int(self.getParameterValue(self.POINT_NUMBER))
minDistance = float(self.getParameterValue(self.MIN_DISTANCE))
extent = str(self.getParameterValue(self.EXTENT)).split(',')

crsId = self.getParameterValue(self.CRS)
crs = QgsCoordinateReferenceSystem()
crs.createFromUserInput(crsId)

xMin = float(extent[0])
xMax = float(extent[1])
yMin = float(extent[2])
@@ -81,9 +89,8 @@ def processAlgorithm(self, feedback):

fields = QgsFields()
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
mapCRS = iface.mapCanvas().mapSettings().destinationCrs()
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields, QgsWkbTypes.Point, mapCRS)
fields, QgsWkbTypes.Point, crs)

nPoints = 0
nIterations = 0
@@ -33,13 +33,14 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsRectangle, QgsFields, QgsField, QgsFeature, QgsWkbTypes,
QgsGeometry, QgsPoint)
QgsGeometry, QgsPoint, QgsCoordinateReferenceSystem)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterExtent
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterCrs
from processing.core.outputs import OutputVector
from processing.tools import dataobjects

@@ -54,6 +55,7 @@ class RegularPoints(GeoAlgorithm):
RANDOMIZE = 'RANDOMIZE'
IS_SPACING = 'IS_SPACING'
OUTPUT = 'OUTPUT'
CRS = 'CRS'

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'regular_points.png'))
@@ -72,6 +74,8 @@ def defineCharacteristics(self):
self.tr('Apply random offset to point spacing'), False))
self.addParameter(ParameterBoolean(self.IS_SPACING,
self.tr('Use point spacing'), True))
self.addParameter(ParameterCrs(self.CRS,
self.tr('Output layer CRS'), 'ProjectCrs'))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Regular points'), datatype=[dataobjects.TYPE_VECTOR_POINT]))

def processAlgorithm(self, feedback):
@@ -81,16 +85,18 @@ def processAlgorithm(self, feedback):
inset = float(self.getParameterValue(self.INSET))
randomize = self.getParameterValue(self.RANDOMIZE)
isSpacing = self.getParameterValue(self.IS_SPACING)
crsId = self.getParameterValue(self.CRS)
crs = QgsCoordinateReferenceSystem()
crs.createFromUserInput(crsId)

extent = QgsRectangle(float(extent[0]), float(extent[2]),
float(extent[1]), float(extent[3]))

fields = QgsFields()
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
mapCRS = iface.mapCanvas().mapSettings().destinationCrs()

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fields, QgsWkbTypes.Point, mapCRS)
fields, QgsWkbTypes.Point, crs)

if randomize:
seed()
@@ -259,6 +259,8 @@ def __init__(self, name='', description='', default=None, optional=False, metada
(if the authority is EPSG) or proj4 string of the CRS (in case
of other authorities or user defined projections).'''
Parameter.__init__(self, name, description, default, optional, metadata)
if self.value == 'ProjectCrs':
self.value = QgsProject.instance().crs().authid()

def setValue(self, value):
if not bool(value):
@@ -280,6 +282,9 @@ def setValue(self, value):
return True
except:
pass
if value == 'ProjectCrs':
self.value = QgsProject.instance().crs().authid()
return True

# TODO: check it is a valid authid
self.value = value
@@ -38,7 +38,8 @@
QgsExpression,
QgsMapLayerProxyModel,
QgsWkbTypes,
QgsSettings
QgsSettings,
QgsProject
)
from qgis.PyQt.QtWidgets import (
QCheckBox,
@@ -304,7 +305,10 @@ def createWidget(self):
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)

if self.param.default:
crs = QgsCoordinateReferenceSystem(self.param.default)
if self.param.default == 'ProjectCrs':
crs = QgsProject.instance().crs()
else:
crs = QgsCoordinateReferenceSystem(self.param.default)
widget.setCrs(crs)
else:
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
@@ -323,6 +327,8 @@ def selectProjection(self):
def setValue(self, value):
if self.dialogType == DIALOG_MODELER:
self.setComboValue(value, self.combo)
elif value == 'ProjectCrs':
self.widget.setCrs(QgsProject.instance().crs())
else:
self.widget.setCrs(QgsCoordinateReferenceSystem(value))

@@ -0,0 +1,26 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>add_field</Name>
<ElementPath>add_field</ElementPath>
<!--POINT-->
<GeometryType>1</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>9</FeatureCount>
<ExtentXMin>0.00000</ExtentXMin>
<ExtentXMax>8.00000</ExtentXMax>
<ExtentYMin>-5.00000</ExtentYMin>
<ExtentYMax>3.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>id</Name>
<ElementPath>id</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>id2</Name>
<ElementPath>id2</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:add_field fid="points.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>1</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>2</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>3</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>4</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>5</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>6</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>7</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>8</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:add_field>
</gml:featureMember>
<gml:featureMember>
<ogr:add_field fid="points.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>9</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:add_field>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,21 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>buffer_diamond</Name>
<ElementPath>buffer_diamond</ElementPath>
<!--POLYGON-->
<GeometryType>3</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>10</FeatureCount>
<ExtentXMin>-2.92606</ExtentXMin>
<ExtentXMax>12.09096</ExtentXMax>
<ExtentYMin>-5.61064</ExtentYMin>
<ExtentYMax>8.22553</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>id</Name>
<ElementPath>id</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-2.926063829787234</gml:X><gml:Y>-5.61063829787234</gml:Y></gml:coord>
<gml:coord><gml:X>12.09095744680851</gml:X><gml:Y>8.225531914893619</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-0.426063829787234,-0.30744680851064 -2.92606382978723,2.19255319148936 -0.426063829787234,4.69255319148936 2.07393617021277,2.19255319148936 -0.426063829787234,-0.30744680851064</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>5</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.45053191489362,-0.53085106382979 -1.04946808510638,1.96914893617021 1.45053191489362,4.46914893617021 3.95053191489362,1.96914893617021 1.45053191489362,-0.53085106382979</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>5</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.40585106382979,-1.69255319148936 -1.09414893617021,0.807446808510639 1.40585106382979,3.30744680851064 3.90585106382979,0.807446808510639 1.40585106382979,-1.69255319148936</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>5</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.3">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.199468085106383,-2.9436170212766 -2.30053191489362,-0.443617021276596 0.199468085106383,2.0563829787234 2.69946808510638,-0.443617021276596 0.199468085106383,-2.9436170212766</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>5</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.4">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3.63989361702128,-1.68404255319149 1.63989361702128,0.315957446808511 3.63989361702128,2.31595744680851 5.63989361702128,0.315957446808511 3.63989361702128,-1.68404255319149</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>4</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4.28776595744681,-1.32340425531915 3.78776595744681,-0.823404255319149 4.28776595744681,-0.323404255319149 4.78776595744681,-0.823404255319149 4.28776595744681,-1.32340425531915</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>1</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.6">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5.04734042553191,-1.92978723404255 3.04734042553191,0.070212765957447 5.04734042553191,2.07021276595745 7.04734042553191,0.070212765957447 5.04734042553191,-1.92978723404255</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>4</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.7">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.90159574468085,-2.09468085106383 4.40159574468085,0.40531914893617 6.90159574468085,2.90531914893617 9.40159574468085,0.40531914893617 6.90159574468085,-2.09468085106383</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>5</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.8">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>9.09095744680851,-5.61063829787234 6.09095744680851,-2.61063829787234 9.09095744680851,0.38936170212766 12.0909574468085,-2.61063829787234 9.09095744680851,-5.61063829787234</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>6</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
<gml:featureMember>
<ogr:buffer_diamond fid="points_wighted.9">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5.04734042553191,0.22553191489362 1.04734042553191,4.22553191489362 5.04734042553191,8.22553191489362 9.04734042553191,4.22553191489362 5.04734042553191,0.22553191489362</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>8</ogr:id>
</ogr:buffer_diamond>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,21 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>buffer_ovals</Name>
<ElementPath>buffer_ovals</ElementPath>
<!--POLYGON-->
<GeometryType>3</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>10</FeatureCount>
<ExtentXMin>-2.92606</ExtentXMin>
<ExtentXMax>12.09096</ExtentXMax>
<ExtentYMin>-5.61064</ExtentYMin>
<ExtentYMax>8.22553</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>id</Name>
<ElementPath>id</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>

0 comments on commit 3bcf287

Please sign in to comment.