mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-19 00:04:52 -04:00
Use native algorithms for processing tests where possible
And fix a few issues in the dissolve algorithm
This commit is contained in:
parent
cb6c6f39a2
commit
05e8928e30
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_field fid="polys.1">
|
<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:name>dd</ogr:name>
|
||||||
<ogr:floatval>0</ogr:floatval>
|
<ogr:floatval>0</ogr:floatval>
|
||||||
</ogr:dissolve_field>
|
</ogr:dissolve_field>
|
||||||
@ -26,7 +26,7 @@
|
|||||||
</gml:featureMember>
|
</gml:featureMember>
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_field fid="polys.0">
|
<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:name>aa</ogr:name>
|
||||||
<ogr:intval>1</ogr:intval>
|
<ogr:intval>1</ogr:intval>
|
||||||
<ogr:floatval>44.123456</ogr:floatval>
|
<ogr:floatval>44.123456</ogr:floatval>
|
||||||
@ -42,7 +42,7 @@
|
|||||||
</gml:featureMember>
|
</gml:featureMember>
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_field fid="polys.7">
|
<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:name>cc</ogr:name>
|
||||||
<ogr:floatval>0.123</ogr:floatval>
|
<ogr:floatval>0.123</ogr:floatval>
|
||||||
</ogr:dissolve_field>
|
</ogr:dissolve_field>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_two_fields fid="polys.8">
|
<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:name>bb</ogr:name>
|
||||||
<ogr:intval>2</ogr:intval>
|
<ogr:intval>2</ogr:intval>
|
||||||
<ogr:floatval>0.123</ogr:floatval>
|
<ogr:floatval>0.123</ogr:floatval>
|
||||||
@ -21,7 +21,7 @@
|
|||||||
</gml:featureMember>
|
</gml:featureMember>
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_two_fields fid="polys.1">
|
<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:name>dd</ogr:name>
|
||||||
<ogr:floatval>0</ogr:floatval>
|
<ogr:floatval>0</ogr:floatval>
|
||||||
</ogr:dissolve_two_fields>
|
</ogr:dissolve_two_fields>
|
||||||
@ -42,7 +42,7 @@
|
|||||||
</gml:featureMember>
|
</gml:featureMember>
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_two_fields fid="polys.0">
|
<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:name>aa</ogr:name>
|
||||||
<ogr:intval>1</ogr:intval>
|
<ogr:intval>1</ogr:intval>
|
||||||
<ogr:floatval>44.123456</ogr:floatval>
|
<ogr:floatval>44.123456</ogr:floatval>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
</gml:featureMember>
|
</gml:featureMember>
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:dissolve_two_fields fid="polys.7">
|
<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:name>cc</ogr:name>
|
||||||
<ogr:floatval>0.123</ogr:floatval>
|
<ogr:floatval>0.123</ogr:floatval>
|
||||||
</ogr:dissolve_two_fields>
|
</ogr:dissolve_two_fields>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<gml:featureMember>
|
<gml:featureMember>
|
||||||
<ogr:nullGeometryDissolve_output fid="nullGeometryDissolve.0">
|
<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>
|
</ogr:nullGeometryDissolve_output>
|
||||||
</gml:featureMember>
|
</gml:featureMember>
|
||||||
</ogr:FeatureCollection>
|
</ogr:FeatureCollection>
|
||||||
|
@ -252,32 +252,30 @@ tests:
|
|||||||
name: expected/autoincrement_field.gml
|
name: expected/autoincrement_field.gml
|
||||||
type: vector
|
type: vector
|
||||||
|
|
||||||
# - algorithm: qgis:dissolve
|
- algorithm: native:dissolve
|
||||||
# name: Dissolve using field
|
name: Dissolve using field
|
||||||
# params:
|
params:
|
||||||
# DISSOLVE_ALL: false
|
FIELD: name
|
||||||
# FIELD: name
|
INPUT:
|
||||||
# INPUT:
|
name: dissolve_polys.gml
|
||||||
# name: dissolve_polys.gml
|
type: vector
|
||||||
# type: vector
|
results:
|
||||||
# results:
|
OUTPUT:
|
||||||
# OUTPUT:
|
name: expected/dissolve_field.gml
|
||||||
# name: expected/dissolve_field.gml
|
type: vector
|
||||||
# type: vector
|
|
||||||
#
|
- algorithm: native:dissolve
|
||||||
# - algorithm: qgis:dissolve
|
name: Dissolve using two fields
|
||||||
# name: Dissolve using two fields
|
params:
|
||||||
# params:
|
FIELD: intval;name
|
||||||
# DISSOLVE_ALL: false
|
INPUT:
|
||||||
# FIELD: intval;name
|
name: dissolve_polys.gml
|
||||||
# INPUT:
|
type: vector
|
||||||
# name: dissolve_polys.gml
|
results:
|
||||||
# type: vector
|
OUTPUT:
|
||||||
# results:
|
name: expected/dissolve_two_fields.gml
|
||||||
# OUTPUT:
|
type: vector
|
||||||
# name: expected/dissolve_two_fields.gml
|
|
||||||
# type: vector
|
|
||||||
#
|
|
||||||
# - name: Dissolve with geometries reported as valid but as invalid with isGeosValid
|
# - name: Dissolve with geometries reported as valid but as invalid with isGeosValid
|
||||||
# algorithm: qgis:dissolve
|
# algorithm: qgis:dissolve
|
||||||
# params:
|
# 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 "
|
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 "
|
"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"
|
"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." );
|
"In case the input is a polygon layer, common boundaries of adjacent polygons being dissolved will get erased." );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,26 +362,27 @@ QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap ¶meter
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantList indexAttributes;
|
||||||
|
Q_FOREACH ( int index, fieldIndexes )
|
||||||
|
{
|
||||||
|
indexAttributes << f.attribute( index );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !attributeHash.contains( indexAttributes ) )
|
||||||
|
{
|
||||||
|
// keep attributes of first feature
|
||||||
|
attributeHash.insert( indexAttributes, f.attributes() );
|
||||||
|
}
|
||||||
|
|
||||||
if ( f.hasGeometry() && f.geometry() )
|
if ( f.hasGeometry() && f.geometry() )
|
||||||
{
|
{
|
||||||
QVariantList indexAttributes;
|
|
||||||
Q_FOREACH ( int index, fieldIndexes )
|
|
||||||
{
|
|
||||||
indexAttributes << f.attribute( index );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !attributeHash.contains( indexAttributes ) )
|
|
||||||
{
|
|
||||||
// keep attributes of first feature
|
|
||||||
attributeHash.insert( indexAttributes, f.attributes() );
|
|
||||||
}
|
|
||||||
geometryHash[ indexAttributes ].append( f.geometry() );
|
geometryHash[ indexAttributes ].append( f.geometry() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int numberFeatures = attributeHash.count();
|
int numberFeatures = attributeHash.count();
|
||||||
QHash< QVariant, QList< QgsGeometry > >::const_iterator geomIt = geometryHash.constBegin();
|
QHash< QVariant, QgsAttributes >::const_iterator attrIt = attributeHash.constBegin();
|
||||||
for ( ; geomIt != geometryHash.constEnd(); ++geomIt )
|
for ( ; attrIt != attributeHash.constEnd(); ++attrIt )
|
||||||
{
|
{
|
||||||
if ( feedback->isCanceled() )
|
if ( feedback->isCanceled() )
|
||||||
{
|
{
|
||||||
@ -389,8 +390,16 @@ QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap ¶meter
|
|||||||
}
|
}
|
||||||
|
|
||||||
QgsFeature outputFeature;
|
QgsFeature outputFeature;
|
||||||
outputFeature.setGeometry( QgsGeometry::unaryUnion( geomIt.value() ) );
|
if ( geometryHash.contains( attrIt.key() ) )
|
||||||
outputFeature.setAttributes( attributeHash.value( geomIt.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 );
|
sink->addFeature( outputFeature, QgsFeatureSink::FastInsert );
|
||||||
|
|
||||||
feedback->setProgress( current * 100.0 / numberFeatures );
|
feedback->setProgress( current * 100.0 / numberFeatures );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user