Skip to content

Commit

Permalink
[processing] Fix broken Densify by Interval algorithm, add test
Browse files Browse the repository at this point in the history
Fix #18640
  • Loading branch information
nyalldawson committed Apr 6, 2018
1 parent 6a925f9 commit 78a6118
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def inputLayerTypes(self):
return [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]

def prepareAlgorithm(self, parameters, context, feedback):
interval = self.parameterAsDouble(parameters, self.INTERVAL, context)
self.interval = self.parameterAsDouble(parameters, self.INTERVAL, context)
return True

def processFeature(self, feature, context, feedback):
if feature.hasGeometry():
new_geometry = feature.geometry().densifyByDistance(float(interval))
new_geometry = feature.geometry().densifyByDistance(float(self.interval))
feature.setGeometry(new_geometry)
return [feature]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ densify_by_interval_polys.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>-3</gml:Y></gml:coord>
<gml:coord><gml:X>10</gml:X><gml:Y>6</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:densify_by_interval_polys fid="polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-1,-1 -1.0,-0.2 -1.0,0.6 -1.0,1.4 -1.0,2.2 -1,3 -0.2,3.0 0.6,3.0 1.4,3.0 2.2,3.0 3,3 3.0,2.5 3,2 2.5,2.0 2,2 2.0,1.25 2.0,0.5 2.0,-0.25 2,-1 1.25,-1.0 0.5,-1.0 -0.25,-1.0 -1,-1</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:densify_by_interval_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:densify_by_interval_polys fid="polys.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5,5 5.5,4.5 6,4 5.33333333333333,4.0 4.66666666666667,4.0 4,4 4.5,4.5 5,5</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:densify_by_interval_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:densify_by_interval_polys fid="polys.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,5 2.0,5.5 2,6 2.5,6.0 3,6 3.0,5.5 3,5 2.5,5.0 2,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>bbaaa</ogr:name>
<ogr:floatval>0.123</ogr:floatval>
</ogr:densify_by_interval_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:densify_by_interval_polys fid="polys.3">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,1 6.8,1.0 7.6,1.0 8.4,1.0 9.2,1.0 10,1 10.0,0.2 10.0,-0.6 10.0,-1.4 10.0,-2.2 10,-3 9.2,-3.0 8.4,-3.0 7.6,-3.0 6.8,-3.0 6,-3 6.0,-2.2 6.0,-1.4 6.0,-0.6 6.0,0.2 6,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>7,0 7.0,-0.666666666666667 7.0,-1.33333333333333 7,-2 7.66666666666667,-2.0 8.33333333333333,-2.0 9,-2 9.0,-1.33333333333333 9.0,-0.666666666666667 9,0 8.33333333333333,0.0 7.66666666666667,0.0 7,0</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>ASDF</ogr:name>
<ogr:intval>0</ogr:intval>
</ogr:densify_by_interval_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:densify_by_interval_polys fid="polys.4">
<ogr:intval>120</ogr:intval>
<ogr:floatval>-100291.43213</ogr:floatval>
</ogr:densify_by_interval_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:densify_by_interval_polys fid="polys.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 3.75,1.75 4.5,1.5 5.25,1.25 6,1 6.0,0.2 6.0,-0.6 6.0,-1.4 6.0,-2.2 6,-3 5.2,-2.6 4.4,-2.2 3.6,-1.8 2.8,-1.4 2,-1 2.0,-0.25 2.0,0.5 2.0,1.25 2,2 2.5,2.0 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:densify_by_interval_polys>
</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="densify_by_interval_polys" type="ogr:densify_by_interval_polys_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="densify_by_interval_polys_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="10"/>
</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>
12 changes: 12 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ tests:
name: expected/multipolys_densify.gml
type: vector

- algorithm: qgis:densifygeometriesgivenaninterval
name: Densify polygons by interval
params:
INPUT:
name: polys.gml
type: vector
INTERVAL: 1.0
results:
OUTPUT:
name: expected/densify_by_interval_polys.gml
type: vector

- name: Polygons to Lines
algorithm: qgis:polygonstolines
params:
Expand Down

0 comments on commit 78a6118

Please sign in to comment.