Skip to content

Commit c4c780f

Browse files
committedOct 11, 2017
[processing] tests for clipping (raster and vector) algorithms
1 parent 67265c6 commit c4c780f

File tree

8 files changed

+252
-20
lines changed

8 files changed

+252
-20
lines changed
 

‎python/plugins/processing/algs/gdal/ClipVectorByExtent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import (QgsProcessing,
28+
from qgis.core import (QgsVectorLayer,
29+
QgsProcessing,
2930
QgsProcessingParameterDefinition,
3031
QgsProcessingParameterFeatureSource,
3132
QgsProcessingParameterExtent,
@@ -75,8 +76,8 @@ def commandName(self):
7576

7677
def getConsoleCommands(self, parameters, context, feedback):
7778
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
78-
inLayer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
79-
extent = self.parameterAsExtent(parameters, self.EXTENT, context, inLayer.crs())
79+
source = self.parameterAsSource(parameters, self.INPUT, context)
80+
extent = self.parameterAsExtent(parameters, self.EXTENT, context, source.sourceCrs())
8081
options = self.parameterAsString(parameters, self.OPTIONS, context)
8182
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
8283

‎python/plugins/processing/tests/testdata/expected/gdal/clip_lines.gml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66
xmlns:gml="http://www.opengis.net/gml">
77
<gml:boundedBy>
88
<gml:Box>
9-
<gml:coord><gml:X>4.430364372469636</gml:X><gml:Y>-2.103238866396762</gml:Y></gml:coord>
10-
<gml:coord><gml:X>8.630364372469638</gml:X><gml:Y>2</gml:Y></gml:coord>
9+
<gml:coord><gml:X>4.294331983805669</gml:X><gml:Y>-2.02672064777328</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8.715384615384616</gml:X><gml:Y>2</gml:Y></gml:coord>
1111
</gml:Box>
1212
</gml:boundedBy>
13-
13+
1414
<gml:featureMember>
15-
<ogr:clip_lines fid="lines.0">
16-
<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>
17-
</ogr:clip_lines>
15+
<ogr:lines fid="lines.0">
16+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 8.71538461538462,2.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
17+
</ogr:lines>
1818
</gml:featureMember>
1919
<gml:featureMember>
20-
<ogr:clip_lines fid="lines.3">
21-
<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>
22-
</ogr:clip_lines>
20+
<ogr:lines fid="lines.3">
21+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>4.29433198380567,1.0 5,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
22+
</ogr:lines>
2323
</gml:featureMember>
2424
<gml:featureMember>
25-
<ogr:clip_lines fid="lines.5">
26-
<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>
27-
</ogr:clip_lines>
25+
<ogr:lines fid="lines.5">
26+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6.97327935222672,-2.02672064777328 8.71538461538462,-0.284615384615383</gml:coordinates></gml:LineString></ogr:geometryProperty>
27+
</ogr:lines>
2828
</gml:featureMember>
2929
<gml:featureMember>
30-
<ogr:clip_lines fid="lines.6">
31-
</ogr:clip_lines>
30+
<ogr:lines fid="lines.6">
31+
</ogr:lines>
3232
</gml:featureMember>
3333
</ogr:FeatureCollection>

‎python/plugins/processing/tests/testdata/expected/gdal/clip_lines.xsd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
</xs:extension>
1111
</xs:complexContent>
1212
</xs:complexType>
13-
<xs:element name="clip_lines" type="ogr:clip_lines_Type" substitutionGroup="gml:_Feature"/>
14-
<xs:complexType name="clip_lines_Type">
13+
<xs:element name="lines" type="ogr:lines_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="lines_Type">
1515
<xs:complexContent>
1616
<xs:extension base="gml:AbstractFeatureType">
1717
<xs:sequence>
18-
<xs:element name="geometryProperty" type="gml:MultiLineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
18+
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
1919
</xs:sequence>
2020
</xs:extension>
2121
</xs:complexContent>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ clip_points.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>1</gml:X><gml:Y>1</gml:Y></gml:coord>
10+
<gml:coord><gml:X>5</gml:X><gml:Y>2</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:points fid="points.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
<ogr:id>1</ogr:id>
18+
<ogr:id2>2</ogr:id2>
19+
</ogr:points>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:points fid="points.2">
23+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
24+
<ogr:id>3</ogr:id>
25+
<ogr:id2>0</ogr:id2>
26+
</ogr:points>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:points fid="points.3">
30+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty>
31+
<ogr:id>4</ogr:id>
32+
<ogr:id2>2</ogr:id2>
33+
</ogr:points>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:points fid="points.4">
37+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
38+
<ogr:id>5</ogr:id>
39+
<ogr:id2>1</ogr:id2>
40+
</ogr:points>
41+
</gml:featureMember>
42+
</ogr:FeatureCollection>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="points" type="ogr:points_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="points_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="16"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="id2" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:integer">
29+
<xs:totalDigits value="16"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
</xs:sequence>
34+
</xs:extension>
35+
</xs:complexContent>
36+
</xs:complexType>
37+
</xs:schema>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ clip_polygons.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0.9040662650602393</gml:X><gml:Y>0.6460843373493974</gml:Y></gml:coord>
10+
<gml:coord><gml:X>4.680271084337348</gml:X><gml:Y>5.465963855421688</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:polys2 fid="polys.0">
16+
<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>
17+
<ogr:name>aaaaa</ogr:name>
18+
<ogr:intval>33</ogr:intval>
19+
<ogr:floatval>44.123456</ogr:floatval>
20+
</ogr:polys2>
21+
</gml:featureMember>
22+
<gml:featureMember>
23+
<ogr:polys2 fid="polys.1">
24+
<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>
25+
<ogr:name>Aaaaa</ogr:name>
26+
<ogr:intval>-33</ogr:intval>
27+
<ogr:floatval>0</ogr:floatval>
28+
</ogr:polys2>
29+
</gml:featureMember>
30+
<gml:featureMember>
31+
<ogr:polys2 fid="polys.2">
32+
<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>
33+
<ogr:name>bbaaa</ogr:name>
34+
<ogr:floatval>0.123</ogr:floatval>
35+
</ogr:polys2>
36+
</gml:featureMember>
37+
<gml:featureMember>
38+
<ogr:polys2 fid="polys.4">
39+
<ogr:intval>120</ogr:intval>
40+
<ogr:floatval>-100291.43213</ogr:floatval>
41+
</ogr:polys2>
42+
</gml:featureMember>
43+
<gml:featureMember>
44+
<ogr:polys2 fid="polys.5">
45+
<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>
46+
<ogr:name>elim</ogr:name>
47+
<ogr:intval>2</ogr:intval>
48+
<ogr:floatval>3.33</ogr:floatval>
49+
</ogr:polys2>
50+
</gml:featureMember>
51+
</ogr:FeatureCollection>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="polys2" type="ogr:polys2_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="polys2_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="name" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
<xs:maxLength value="5"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="intval" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:integer">
29+
<xs:totalDigits value="16"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
<xs:element name="floatval" nillable="true" minOccurs="0" maxOccurs="1">
34+
<xs:simpleType>
35+
<xs:restriction base="xs:decimal">
36+
</xs:restriction>
37+
</xs:simpleType>
38+
</xs:element>
39+
</xs:sequence>
40+
</xs:extension>
41+
</xs:complexContent>
42+
</xs:complexType>
43+
</xs:schema>

‎python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ tests:
3232
hash: f4dd2d3693afe0b95a6b6d0c98a57331b8f7c6a61a372f52da912c07
3333
type: rasterhash
3434

35+
- algorithm: gdal:cliprasterbyextent
36+
name: Test (gdal:cliprasterbyextent)
37+
params:
38+
DATA_TYPE: 5
39+
INPUT:
40+
name: dem.tif
41+
type: raster
42+
NODATA: 0.0
43+
OPTIONS: ''
44+
PROJWIN: 18.674136950224096,18.70011285383855,45.78239420868433,45.80342583519035
45+
[EPSG:4326]
46+
results:
47+
OUTPUT:
48+
hash: c71cf9c654ee0f27ea8778576787301a868556e52773cb061a8fff00
49+
type: rasterhash
50+
3551
- algorithm: gdal:cliprasterbymasklayer
3652
name: Clip raster by mask layer (gdalwarp)
3753
params:
@@ -505,6 +521,20 @@ tests:
505521
name: expected/gdal/buffer_polys_dissolve.gml
506522
type: vector
507523

524+
- algorithm: gdal:clipvectorbyextent
525+
name: Clip points by extent
526+
params:
527+
EXTENT: 0.4662650602409637,5.695180722891566,0.36626506024096406,2.221686746987952
528+
[EPSG:4326]
529+
INPUT:
530+
name: points.gml
531+
type: vector
532+
OPTIONS: ''
533+
results:
534+
OUTPUT:
535+
name: expected/gdal/clip_points.gml
536+
type: vector
537+
508538
- algorithm: gdal:clipvectorbypolygon
509539
name: Clip lines by polygons
510540
params:
@@ -535,6 +565,34 @@ tests:
535565
name: expected/gdal/clip_lines_by_multipolygon.gml
536566
type: vector
537567

568+
- algorithm: gdal:clipvectorbyextent
569+
name: Clip lines by extent
570+
params:
571+
EXTENT: 4.294331983805669,8.715384615384616,-2.0267206477732795,2.9894736842105267
572+
[EPSG:4326]
573+
INPUT:
574+
name: lines.gml
575+
type: vector
576+
OPTIONS: ''
577+
results:
578+
OUTPUT:
579+
name: expected/gdal/clip_lines.gml
580+
type: vector
581+
582+
- algorithm: gdal:clipvectorbyextent
583+
name: Clip polygons by extent
584+
params:
585+
EXTENT: 0.9040662650602393,4.680271084337348,0.6460843373493974,5.465963855421688
586+
[EPSG:4326]
587+
INPUT:
588+
name: polys.gml
589+
type: vector
590+
OPTIONS: ''
591+
results:
592+
OUTPUT:
593+
name: expected/gdal/clip_polygons.gml
594+
type: vector
595+
538596
- algorithm: gdal:clipvectorbypolygon
539597
name: Clip points by polygons
540598
params:

0 commit comments

Comments
 (0)
Please sign in to comment.