Skip to content

Commit 37b06bc

Browse files
committedMay 30, 2018
[processing] Fix Rectangles/Ovals/...(variable) chokes on angle values of 0
Change the test to a NULL test instead, as angle values of 0 are valid
1 parent 377f393 commit 37b06bc

File tree

4 files changed

+156
-7
lines changed

4 files changed

+156
-7
lines changed
 

‎python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import math
2929

3030
from qgis.PyQt.QtCore import QCoreApplication
31-
from qgis.core import (QgsWkbTypes,
31+
from qgis.core import (NULL,
32+
QgsWkbTypes,
3233
QgsFeature,
3334
QgsFeatureSink,
3435
QgsGeometry,
@@ -148,9 +149,15 @@ def rectangles(self, sink, source, width, height, rotation, feedback):
148149
w = feat[width]
149150
h = feat[height]
150151
angle = feat[rotation]
151-
if not w or not h or not angle:
152+
# block 0/NULL width or height, but allow 0 as angle value
153+
if not w or not h:
154+
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
155+
'width or height. '
156+
'Skipping…').format(feat.id()))
157+
continue
158+
if angle is NULL:
152159
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
153-
'width, height or angle. '
160+
'angle. '
154161
'Skipping…').format(feat.id()))
155162
continue
156163

@@ -217,9 +224,15 @@ def diamonds(self, sink, source, width, height, rotation, feedback):
217224
w = feat[width]
218225
h = feat[height]
219226
angle = feat[rotation]
220-
if not w or not h or not angle:
227+
# block 0/NULL width or height, but allow 0 as angle value
228+
if not w or not h:
221229
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
222-
'width, height or angle. '
230+
'width or height. '
231+
'Skipping…').format(feat.id()))
232+
continue
233+
if angle is NULL:
234+
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
235+
'angle. '
223236
'Skipping…').format(feat.id()))
224237
continue
225238

@@ -284,9 +297,15 @@ def ovals(self, sink, source, width, height, rotation, segments, feedback):
284297
w = feat[width]
285298
h = feat[height]
286299
angle = feat[rotation]
287-
if not w or not h or not angle:
300+
# block 0/NULL width or height, but allow 0 as angle value
301+
if not w or not h:
302+
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
303+
'width or height. '
304+
'Skipping…').format(feat.id()))
305+
continue
306+
if angle == NULL:
288307
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
289-
'width, height or angle. '
308+
'angle. '
290309
'Skipping…').format(feat.id()))
291310
continue
292311

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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/ rectanglesovalsdiamondsvariable.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>-4.5</gml:X><gml:Y>-8</gml:Y></gml:coord>
10+
<gml:coord><gml:X>11.5</gml:X><gml:Y>4.068580647443193</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:rectanglesovalsdiamondsvariable fid="points.0">
16+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.482854838139202,0.517754334841703 0.517754334841703,1.5171451618608 1.5171451618608,1.4822456651583 1.4822456651583,0.482854838139202 0.482854838139202,0.517754334841703</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
17+
<ogr:id>1</ogr:id>
18+
<ogr:id2>2</ogr:id2>
19+
</ogr:rectanglesovalsdiamondsvariable>
20+
</gml:featureMember>
21+
<gml:featureMember>
22+
<ogr:rectanglesovalsdiamondsvariable fid="points.1">
23+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.98269989840633,2.01760471128089 2.01760471128089,4.01730010159367 4.01730010159367,3.98239528871911 3.98239528871911,1.98269989840633 1.98269989840633,2.01760471128089</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
24+
<ogr:id>2</ogr:id>
25+
<ogr:id2>1</ogr:id2>
26+
</ogr:rectanglesovalsdiamondsvariable>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:rectanglesovalsdiamondsvariable fid="points.2">
30+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.5,0.5 0.5,3.5 3.5,3.5 3.5,0.5 0.5,0.5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
31+
<ogr:id>3</ogr:id>
32+
<ogr:id2>0</ogr:id2>
33+
</ogr:rectanglesovalsdiamondsvariable>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:rectanglesovalsdiamondsvariable fid="points.3">
37+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2.93141935255681,0.07101733936681 3.07101733936681,4.06858064744319 7.06858064744319,3.92898266063319 6.92898266063319,-0.068580647443194 2.93141935255681,0.07101733936681</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
38+
<ogr:id>4</ogr:id>
39+
<ogr:id2>2</ogr:id2>
40+
</ogr:rectanglesovalsdiamondsvariable>
41+
</gml:featureMember>
42+
<gml:featureMember>
43+
<ogr:rectanglesovalsdiamondsvariable fid="points.4">
44+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.45674974601581,-1.45598822179777 1.54401177820223,3.54325025398419 6.54325025398419,3.45598822179777 6.45598822179777,-1.54325025398419 1.45674974601581,-1.45598822179777</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
45+
<ogr:id>5</ogr:id>
46+
<ogr:id2>1</ogr:id2>
47+
</ogr:rectanglesovalsdiamondsvariable>
48+
</gml:featureMember>
49+
<gml:featureMember>
50+
<ogr:rectanglesovalsdiamondsvariable fid="points.5">
51+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-3,-8 -3,-2 3,-2 3,-8 -3,-8</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
52+
<ogr:id>6</ogr:id>
53+
<ogr:id2>0</ogr:id2>
54+
</ogr:rectanglesovalsdiamondsvariable>
55+
</gml:featureMember>
56+
<gml:featureMember>
57+
<ogr:rectanglesovalsdiamondsvariable fid="points.6">
58+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4.5,-4.5 4.5,2.5 11.5,2.5 11.5,-4.5 4.5,-4.5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
59+
<ogr:id>7</ogr:id>
60+
<ogr:id2>0</ogr:id2>
61+
</ogr:rectanglesovalsdiamondsvariable>
62+
</gml:featureMember>
63+
<gml:featureMember>
64+
<ogr:rectanglesovalsdiamondsvariable fid="points.7">
65+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,-5 3,3 11,3 11,-5 3,-5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
66+
<ogr:id>8</ogr:id>
67+
<ogr:id2>0</ogr:id2>
68+
</ogr:rectanglesovalsdiamondsvariable>
69+
</gml:featureMember>
70+
<gml:featureMember>
71+
<ogr:rectanglesovalsdiamondsvariable fid="points.8">
72+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-4.5,-5.5 -4.5,3.5 4.5,3.5 4.5,-5.5 -4.5,-5.5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
73+
<ogr:id>9</ogr:id>
74+
<ogr:id2>0</ogr:id2>
75+
</ogr:rectanglesovalsdiamondsvariable>
76+
</gml:featureMember>
77+
</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="rectanglesovalsdiamondsvariable" type="ogr:rectanglesovalsdiamondsvariable_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="rectanglesovalsdiamondsvariable_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="id" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="10"/>
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="10"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
</xs:sequence>
34+
</xs:extension>
35+
</xs:complexContent>
36+
</xs:complexType>
37+
</xs:schema>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,22 @@ tests:
642642
geometry:
643643
precision: 7
644644

645+
- algorithm: qgis:rectanglesovalsdiamondsvariable
646+
name: Rectangles ovals diamonds variable
647+
params:
648+
HEIGHT: id
649+
INPUT:
650+
name: points.gml
651+
type: vector
652+
ROTATION: id2
653+
SEGMENTS: 1
654+
SHAPE: 0
655+
WIDTH: id
656+
results:
657+
OUTPUT:
658+
name: expected/rectanglesovalsdiamondsvariable.gml
659+
type: vector
660+
645661
- algorithm: native:mergelines
646662
name: Merge lines algorithm
647663
params:

0 commit comments

Comments
 (0)
Please sign in to comment.