Skip to content
Permalink
Browse files

[processing] Fix Rectangles/Ovals/...(variable) chokes on angle value…

…s of 0

Change the test to a NULL test instead, as angle values of 0 are valid
  • Loading branch information
nyalldawson committed May 30, 2018
1 parent 377f393 commit 37b06bcf29c9da032227d20451affcf35bca27f9
@@ -28,7 +28,8 @@
import math

from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsWkbTypes,
from qgis.core import (NULL,
QgsWkbTypes,
QgsFeature,
QgsFeatureSink,
QgsGeometry,
@@ -148,9 +149,15 @@ def rectangles(self, sink, source, width, height, rotation, feedback):
w = feat[width]
h = feat[height]
angle = feat[rotation]
if not w or not h or not angle:
# block 0/NULL width or height, but allow 0 as angle value
if not w or not h:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width or height. '
'Skipping…').format(feat.id()))
continue
if angle is NULL:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width, height or angle. '
'angle. '
'Skipping…').format(feat.id()))
continue

@@ -217,9 +224,15 @@ def diamonds(self, sink, source, width, height, rotation, feedback):
w = feat[width]
h = feat[height]
angle = feat[rotation]
if not w or not h or not angle:
# block 0/NULL width or height, but allow 0 as angle value
if not w or not h:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width, height or angle. '
'width or height. '
'Skipping…').format(feat.id()))
continue
if angle is NULL:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'angle. '
'Skipping…').format(feat.id()))
continue

@@ -284,9 +297,15 @@ def ovals(self, sink, source, width, height, rotation, segments, feedback):
w = feat[width]
h = feat[height]
angle = feat[rotation]
if not w or not h or not angle:
# block 0/NULL width or height, but allow 0 as angle value
if not w or not h:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width or height. '
'Skipping…').format(feat.id()))
continue
if angle == NULL:
feedback.pushInfo(QCoreApplication.translate('RectanglesOvalsDiamondsVariable', 'Feature {} has empty '
'width, height or angle. '
'angle. '
'Skipping…').format(feat.id()))
continue

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ rectanglesovalsdiamondsvariable.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-4.5</gml:X><gml:Y>-8</gml:Y></gml:coord>
<gml:coord><gml:X>11.5</gml:X><gml:Y>4.068580647443193</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.0">
<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>
<ogr:id>1</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.1">
<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>
<ogr:id>2</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.2">
<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>
<ogr:id>3</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.3">
<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>
<ogr:id>4</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.4">
<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>
<ogr:id>5</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.5">
<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>
<ogr:id>6</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.6">
<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>
<ogr:id>7</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.7">
<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>
<ogr:id>8</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
<gml:featureMember>
<ogr:rectanglesovalsdiamondsvariable fid="points.8">
<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>
<ogr:id>9</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:rectanglesovalsdiamondsvariable>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -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="rectanglesovalsdiamondsvariable" type="ogr:rectanglesovalsdiamondsvariable_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="rectanglesovalsdiamondsvariable_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="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</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="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -642,6 +642,22 @@ tests:
geometry:
precision: 7

- algorithm: qgis:rectanglesovalsdiamondsvariable
name: Rectangles ovals diamonds variable
params:
HEIGHT: id
INPUT:
name: points.gml
type: vector
ROTATION: id2
SEGMENTS: 1
SHAPE: 0
WIDTH: id
results:
OUTPUT:
name: expected/rectanglesovalsdiamondsvariable.gml
type: vector

- algorithm: native:mergelines
name: Merge lines algorithm
params:

0 comments on commit 37b06bc

Please sign in to comment.
You can’t perform that action at this time.