Skip to content
Permalink
Browse files

Use native algorithms for processing tests where possible

And fix a few issues in the dissolve algorithm
  • Loading branch information
nyalldawson committed Jul 7, 2017
1 parent cb6c6f3 commit 05e8928e30c31574ba3517259769a37c8079cfd9
@@ -13,7 +13,7 @@

<gml:featureMember>
<ogr:dissolve_field fid="polys.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.241458733205375,-0.054510556621882 7.241458733205375,-1.054510556621882 5.241458733205375,-1.054510556621882 6.241458733205375,-0.054510556621882</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.241458733205375,-0.054510556621882 7.241458733205375,-1.054510556621882 5.241458733205375,-1.054510556621882 6.241458733205375,-0.054510556621882</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>dd</ogr:name>
<ogr:floatval>0</ogr:floatval>
</ogr:dissolve_field>
@@ -26,7 +26,7 @@
</gml:featureMember>
<gml:featureMember>
<ogr:dissolve_field fid="polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 -1,-1 -1,3 3,3 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 -1,-1 -1,3 3,3 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>aa</ogr:name>
<ogr:intval>1</ogr:intval>
<ogr:floatval>44.123456</ogr:floatval>
@@ -42,7 +42,7 @@
</gml:featureMember>
<gml:featureMember>
<ogr:dissolve_field fid="polys.7">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8.162955854126682,2.738771593090211 8.162955854126682,3.738771593090211 9.162955854126682,3.738771593090211 9.162955854126682,2.738771593090211 8.162955854126682,2.738771593090211</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8.162955854126682,2.738771593090211 8.162955854126682,3.738771593090211 9.162955854126682,3.738771593090211 9.162955854126682,2.738771593090211 8.162955854126682,2.738771593090211</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>cc</ogr:name>
<ogr:floatval>0.123</ogr:floatval>
</ogr:dissolve_field>
@@ -13,15 +13,15 @@

<gml:featureMember>
<ogr:dissolve_two_fields fid="polys.8">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2.620729366602688,5.088675623800385 2.620729366602688,6.088675623800385 3.620729366602688,6.088675623800385 3.620729366602688,5.088675623800385 2.620729366602688,5.088675623800385</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2.620729366602688,5.088675623800385 2.620729366602688,6.088675623800385 3.620729366602688,6.088675623800385 3.620729366602688,5.088675623800385 2.620729366602688,5.088675623800385</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>bb</ogr:name>
<ogr:intval>2</ogr:intval>
<ogr:floatval>0.123</ogr:floatval>
</ogr:dissolve_two_fields>
</gml:featureMember>
<gml:featureMember>
<ogr:dissolve_two_fields fid="polys.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.241458733205375,-0.054510556621882 7.241458733205375,-1.054510556621882 5.241458733205375,-1.054510556621882 6.241458733205375,-0.054510556621882</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.241458733205375,-0.054510556621882 7.241458733205375,-1.054510556621882 5.241458733205375,-1.054510556621882 6.241458733205375,-0.054510556621882</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>dd</ogr:name>
<ogr:floatval>0</ogr:floatval>
</ogr:dissolve_two_fields>
@@ -42,15 +42,15 @@
</gml:featureMember>
<gml:featureMember>
<ogr:dissolve_two_fields fid="polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 -1,-1 -1,3 3,3 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 -1,-1 -1,3 3,3 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>aa</ogr:name>
<ogr:intval>1</ogr:intval>
<ogr:floatval>44.123456</ogr:floatval>
</ogr:dissolve_two_fields>
</gml:featureMember>
<gml:featureMember>
<ogr:dissolve_two_fields fid="polys.7">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8.162955854126682,2.738771593090211 8.162955854126682,3.738771593090211 9.162955854126682,3.738771593090211 9.162955854126682,2.738771593090211 8.162955854126682,2.738771593090211</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>8.162955854126682,2.738771593090211 8.162955854126682,3.738771593090211 9.162955854126682,3.738771593090211 9.162955854126682,2.738771593090211 8.162955854126682,2.738771593090211</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:name>cc</ogr:name>
<ogr:floatval>0.123</ogr:floatval>
</ogr:dissolve_two_fields>
@@ -13,7 +13,7 @@

<gml:featureMember>
<ogr:nullGeometryDissolve_output fid="nullGeometryDissolve.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:3003"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1756812.050985608249903,5080657.52322755753994 1758058.328737602569163,5080656.446172921918333 1758032.602247689384967,5078868.455123908817768 1756869.935587913962081,5078877.136755040846765 1755007.051325645996258,5078864.273510087281466 1754831.111262238584459,5080811.882167040370405 1756812.050985608249903,5080657.52322755753994</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3003"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1756812.050985608249903,5080657.52322755753994 1758058.328737602569163,5080656.446172921918333 1758032.602247689384967,5078868.455123908817768 1756869.935587913962081,5078877.136755040846765 1755007.051325645996258,5078864.273510087281466 1754831.111262238584459,5080811.882167040370405 1756812.050985608249903,5080657.52322755753994</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
</ogr:nullGeometryDissolve_output>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -252,32 +252,30 @@ tests:
name: expected/autoincrement_field.gml
type: vector

# - algorithm: qgis:dissolve
# name: Dissolve using field
# params:
# DISSOLVE_ALL: false
# FIELD: name
# INPUT:
# name: dissolve_polys.gml
# type: vector
# results:
# OUTPUT:
# name: expected/dissolve_field.gml
# type: vector
#
# - algorithm: qgis:dissolve
# name: Dissolve using two fields
# params:
# DISSOLVE_ALL: false
# FIELD: intval;name
# INPUT:
# name: dissolve_polys.gml
# type: vector
# results:
# OUTPUT:
# name: expected/dissolve_two_fields.gml
# type: vector
#
- algorithm: native:dissolve
name: Dissolve using field
params:
FIELD: name
INPUT:
name: dissolve_polys.gml
type: vector
results:
OUTPUT:
name: expected/dissolve_field.gml
type: vector

- algorithm: native:dissolve
name: Dissolve using two fields
params:
FIELD: intval;name
INPUT:
name: dissolve_polys.gml
type: vector
results:
OUTPUT:
name: expected/dissolve_two_fields.gml
type: vector

# - name: Dissolve with geometries reported as valid but as invalid with isGeosValid
# algorithm: qgis:dissolve
# params:
@@ -269,7 +269,7 @@ QString QgsDissolveAlgorithm::shortHelpString() const
return QObject::tr( "This algorithm takes a polygon or line vector layer and combines their geometries into new geometries. One or more attributes can "
"be specified to dissolve only geometries belonging to the same class (having the same value for the specified attributes), alternatively "
"all geometries can be dissolved.\n\n"
"If the geometries to be dissolved are spatially separated from each other the output will be multi geometries. "
"All output geometries will be converted to multi geometries. "
"In case the input is a polygon layer, common boundaries of adjacent polygons being dissolved will get erased." );
}

@@ -362,35 +362,44 @@ QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap &parameter
break;
}

if ( f.hasGeometry() && f.geometry() )
QVariantList indexAttributes;
Q_FOREACH ( int index, fieldIndexes )
{
QVariantList indexAttributes;
Q_FOREACH ( int index, fieldIndexes )
{
indexAttributes << f.attribute( index );
}
indexAttributes << f.attribute( index );
}

if ( !attributeHash.contains( indexAttributes ) )
{
// keep attributes of first feature
attributeHash.insert( indexAttributes, f.attributes() );
}
if ( !attributeHash.contains( indexAttributes ) )
{
// keep attributes of first feature
attributeHash.insert( indexAttributes, f.attributes() );
}

if ( f.hasGeometry() && f.geometry() )
{
geometryHash[ indexAttributes ].append( f.geometry() );
}
}

int numberFeatures = attributeHash.count();
QHash< QVariant, QList< QgsGeometry > >::const_iterator geomIt = geometryHash.constBegin();
for ( ; geomIt != geometryHash.constEnd(); ++geomIt )
QHash< QVariant, QgsAttributes >::const_iterator attrIt = attributeHash.constBegin();
for ( ; attrIt != attributeHash.constEnd(); ++attrIt )
{
if ( feedback->isCanceled() )
{
break;
}

QgsFeature outputFeature;
outputFeature.setGeometry( QgsGeometry::unaryUnion( geomIt.value() ) );
outputFeature.setAttributes( attributeHash.value( geomIt.key() ) );
if ( geometryHash.contains( attrIt.key() ) )
{
QgsGeometry geom = QgsGeometry::unaryUnion( geometryHash.value( attrIt.key() ) );
if ( !geom.isMultipart() )
{
geom.convertToMultiType();
}
outputFeature.setGeometry( geom );
}
outputFeature.setAttributes( attrIt.value() );
sink->addFeature( outputFeature, QgsFeatureSink::FastInsert );

feedback->setProgress( current * 100.0 / numberFeatures );

0 comments on commit 05e8928

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