Skip to content

Commit

Permalink
[processing] tests for clipping (raster and vector) algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 11, 2017
1 parent 67265c6 commit c4c780f
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 20 deletions.
7 changes: 4 additions & 3 deletions python/plugins/processing/algs/gdal/ClipVectorByExtent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessing,
from qgis.core import (QgsVectorLayer,
QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterExtent,
Expand Down Expand Up @@ -75,8 +76,8 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
inLayer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
extent = self.parameterAsExtent(parameters, self.EXTENT, context, inLayer.crs())
source = self.parameterAsSource(parameters, self.INPUT, context)
extent = self.parameterAsExtent(parameters, self.EXTENT, context, source.sourceCrs())
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>4.430364372469636</gml:X><gml:Y>-2.103238866396762</gml:Y></gml:coord>
<gml:coord><gml:X>8.630364372469638</gml:X><gml:Y>2</gml:Y></gml:coord>
<gml:coord><gml:X>4.294331983805669</gml:X><gml:Y>-2.02672064777328</gml:Y></gml:coord>
<gml:coord><gml:X>8.715384615384616</gml:X><gml:Y>2</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:clip_lines fid="lines.0">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6,2 8.63036437246964,2.0</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:clip_lines>
<ogr:lines fid="lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 8.71538461538462,2.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:clip_lines fid="lines.3">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>4.43036437246964,1.0 5,1</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:clip_lines>
<ogr:lines fid="lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>4.29433198380567,1.0 5,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:clip_lines fid="lines.5">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>6.89676113360324,-2.10323886639676 8.63036437246964,-0.369635627530362</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:clip_lines>
<ogr:lines fid="lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6.97327935222672,-2.02672064777328 8.71538461538462,-0.284615384615383</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:clip_lines fid="lines.6">
</ogr:clip_lines>
<ogr:lines fid="lines.6">
</ogr:lines>
</gml:featureMember>
</ogr:FeatureCollection>
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="clip_lines" type="ogr:clip_lines_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="clip_lines_Type">
<xs:element name="lines" type="ogr:lines_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="lines_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:MultiLineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ clip_points.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>1</gml:X><gml:Y>1</gml:Y></gml:coord>
<gml:coord><gml:X>5</gml:X><gml:Y>2</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:points 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:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points 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:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points 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:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points 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:points>
</gml:featureMember>
</ogr:FeatureCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="points" type="ogr:points_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="points_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="16"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="id2" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="16"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ clip_polygons.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0.9040662650602393</gml:X><gml:Y>0.6460843373493974</gml:Y></gml:coord>
<gml:coord><gml:X>4.680271084337348</gml:X><gml:Y>5.465963855421688</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:polys2 fid="polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.904066265060239,3.0 3,3 3,2 2,2 2.0,0.646084337349397 0.904066265060239,0.646084337349397 0.904066265060239,3.0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>aaaaa</ogr:name>
<ogr:intval>33</ogr:intval>
<ogr:floatval>44.123456</ogr:floatval>
</ogr:polys2>
</gml:featureMember>
<gml:featureMember>
<ogr:polys2 fid="polys.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4.68027108433735,4.0 4,4 4.68027108433735,4.68027108433735 4.68027108433735,4.0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>Aaaaa</ogr:name>
<ogr:intval>-33</ogr:intval>
<ogr:floatval>0</ogr:floatval>
</ogr:polys2>
</gml:featureMember>
<gml:featureMember>
<ogr:polys2 fid="polys.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,5 2.0,5.46596385542169 3.0,5.46596385542169 3,5 2,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>bbaaa</ogr:name>
<ogr:floatval>0.123</ogr:floatval>
</ogr:polys2>
</gml:featureMember>
<gml:featureMember>
<ogr:polys2 fid="polys.4">
<ogr:intval>120</ogr:intval>
<ogr:floatval>-100291.43213</ogr:floatval>
</ogr:polys2>
</gml:featureMember>
<gml:featureMember>
<ogr:polys2 fid="polys.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 4.68027108433735,1.43990963855422 4.68027108433735,0.646084337349397 2.0,0.646084337349397 2,2 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>elim</ogr:name>
<ogr:intval>2</ogr:intval>
<ogr:floatval>3.33</ogr:floatval>
</ogr:polys2>
</gml:featureMember>
</ogr:FeatureCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="polys2" type="ogr:polys2_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="polys2_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="name" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="intval" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="16"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="floatval" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
58 changes: 58 additions & 0 deletions python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ tests:
hash: f4dd2d3693afe0b95a6b6d0c98a57331b8f7c6a61a372f52da912c07
type: rasterhash

- algorithm: gdal:cliprasterbyextent
name: Test (gdal:cliprasterbyextent)
params:
DATA_TYPE: 5
INPUT:
name: dem.tif
type: raster
NODATA: 0.0
OPTIONS: ''
PROJWIN: 18.674136950224096,18.70011285383855,45.78239420868433,45.80342583519035
[EPSG:4326]
results:
OUTPUT:
hash: c71cf9c654ee0f27ea8778576787301a868556e52773cb061a8fff00
type: rasterhash

- algorithm: gdal:cliprasterbymasklayer
name: Clip raster by mask layer (gdalwarp)
params:
Expand Down Expand Up @@ -505,6 +521,20 @@ tests:
name: expected/gdal/buffer_polys_dissolve.gml
type: vector

- algorithm: gdal:clipvectorbyextent
name: Clip points by extent
params:
EXTENT: 0.4662650602409637,5.695180722891566,0.36626506024096406,2.221686746987952
[EPSG:4326]
INPUT:
name: points.gml
type: vector
OPTIONS: ''
results:
OUTPUT:
name: expected/gdal/clip_points.gml
type: vector

- algorithm: gdal:clipvectorbypolygon
name: Clip lines by polygons
params:
Expand Down Expand Up @@ -535,6 +565,34 @@ tests:
name: expected/gdal/clip_lines_by_multipolygon.gml
type: vector

- algorithm: gdal:clipvectorbyextent
name: Clip lines by extent
params:
EXTENT: 4.294331983805669,8.715384615384616,-2.0267206477732795,2.9894736842105267
[EPSG:4326]
INPUT:
name: lines.gml
type: vector
OPTIONS: ''
results:
OUTPUT:
name: expected/gdal/clip_lines.gml
type: vector

- algorithm: gdal:clipvectorbyextent
name: Clip polygons by extent
params:
EXTENT: 0.9040662650602393,4.680271084337348,0.6460843373493974,5.465963855421688
[EPSG:4326]
INPUT:
name: polys.gml
type: vector
OPTIONS: ''
results:
OUTPUT:
name: expected/gdal/clip_polygons.gml
type: vector

- algorithm: gdal:clipvectorbypolygon
name: Clip points by polygons
params:
Expand Down

0 comments on commit c4c780f

Please sign in to comment.