Skip to content
Permalink
Browse files

[processing] Add test & adjust handling of negative distance value

for multi ring (constant) algorithm
  • Loading branch information
nirvn committed Nov 28, 2018
1 parent 5f6dff0 commit cdda5818197f97be314eca5264bf97aaf27f8dfe
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

@@ -0,0 +1,58 @@
<?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="multiring_negative_buffer" type="ogr:multiring_negative_buffer_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="multiring_negative_buffer_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:MultiPolygonPropertyType" 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:element name="ringId" 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="distance" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:totalDigits value="21"/>
<xs:fractionDigits value="6"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -5329,6 +5329,19 @@ tests:
name: expected/multiring_buffer.gml
type: vector

- algorithm: native:multiringconstantbuffer
name: Multi-ring negative buffer with polygons
params:
DISTANCE: -0.05
INPUT:
name: polys.gml
type: vector
RINGS: 3
results:
OUTPUT:
name: expected/multiring_negative_buffer.gml
type: vector

- algorithm: native:segmentizebymaxangle
name: Segmentize by angle
params:
@@ -133,6 +133,11 @@ QgsFeatureList QgsMultiRingConstantBufferAlgorithm::processFeature( const QgsFea

QgsFeatureList outputs;

// Set previous geometry to a zero-distance buffer of the original geometry,
// this is needed for negative distance values
previousGeometry = feature.geometry().buffer( 0.0, 40 );
previousGeometry.convertToMultiType();

for ( int i = 1; i <= rings; ++i )
{
QgsFeature out;
@@ -145,7 +150,11 @@ QgsFeatureList QgsMultiRingConstantBufferAlgorithm::processFeature( const QgsFea
continue;
}

if ( i == 1 )
if ( distance < 0.0 )
{
out.setGeometry( previousGeometry.symDifference( outputGeometry ) );
}
else if ( i == 1 )
{
out.setGeometry( outputGeometry );
}
@@ -159,6 +168,18 @@ QgsFeatureList QgsMultiRingConstantBufferAlgorithm::processFeature( const QgsFea
out.setAttributes( attrs );
outputs.append( out );
}

// For negative distance values, the last generated buffer geometry needs to be added
if ( distance < 0.0 )
{
QgsFeature out;
out.setGeometry( previousGeometry );
QgsAttributes attrs = feature.attributes();
attrs << 0 << 0.0;
out.setAttributes( attrs );
outputs.append( out );
}

return outputs;
}

0 comments on commit cdda581

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