Skip to content

Commit 0036f27

Browse files
authored
Merge pull request #4794 from nyalldawson/tests2
Use native algorithms for processing tests where possible
2 parents cb6c6f3 + 3a31f54 commit 0036f27

File tree

7 files changed

+89
-52
lines changed

7 files changed

+89
-52
lines changed

.ci/travis/scripts/ctest2travis.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ def start_fold(tag):
4545

4646

4747
def end_fold():
48-
tag = fold_stack.pop()
49-
sys.stdout.write('travis_fold:end:{}\n'.format(tag))
48+
try:
49+
tag = fold_stack.pop()
50+
sys.stdout.write('travis_fold:end:{}\n'.format(tag))
51+
except IndexError:
52+
updated_line = colored("======================", 'magenta')
53+
updated_line += colored("ctest2travis error when processing the following line:", 'magenta')
54+
updated_line += colored("----------------------", 'magenta')
55+
updated_line += colored(updated_line, 'magenta')
56+
updated_line += colored("----------------------", 'magenta')
57+
updated_line += colored("Tried to end fold, but fold was never started.", 'magenta')
58+
updated_line += colored("======================", 'magenta')
5059

5160

5261
test_count = 0

python/plugins/processing/tests/testdata/expected/dissolve_field.gml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<gml:featureMember>
1515
<ogr:dissolve_field fid="polys.1">
16-
<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>
16+
<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>
1717
<ogr:name>dd</ogr:name>
1818
<ogr:floatval>0</ogr:floatval>
1919
</ogr:dissolve_field>
@@ -26,7 +26,7 @@
2626
</gml:featureMember>
2727
<gml:featureMember>
2828
<ogr:dissolve_field fid="polys.0">
29-
<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>
29+
<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>
3030
<ogr:name>aa</ogr:name>
3131
<ogr:intval>1</ogr:intval>
3232
<ogr:floatval>44.123456</ogr:floatval>
@@ -42,7 +42,7 @@
4242
</gml:featureMember>
4343
<gml:featureMember>
4444
<ogr:dissolve_field fid="polys.7">
45-
<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>
45+
<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>
4646
<ogr:name>cc</ogr:name>
4747
<ogr:floatval>0.123</ogr:floatval>
4848
</ogr:dissolve_field>

python/plugins/processing/tests/testdata/expected/dissolve_two_fields.gml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
<gml:featureMember>
1515
<ogr:dissolve_two_fields fid="polys.8">
16-
<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>
16+
<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>
1717
<ogr:name>bb</ogr:name>
1818
<ogr:intval>2</ogr:intval>
1919
<ogr:floatval>0.123</ogr:floatval>
2020
</ogr:dissolve_two_fields>
2121
</gml:featureMember>
2222
<gml:featureMember>
2323
<ogr:dissolve_two_fields fid="polys.1">
24-
<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>
24+
<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>
2525
<ogr:name>dd</ogr:name>
2626
<ogr:floatval>0</ogr:floatval>
2727
</ogr:dissolve_two_fields>
@@ -42,15 +42,15 @@
4242
</gml:featureMember>
4343
<gml:featureMember>
4444
<ogr:dissolve_two_fields fid="polys.0">
45-
<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>
45+
<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>
4646
<ogr:name>aa</ogr:name>
4747
<ogr:intval>1</ogr:intval>
4848
<ogr:floatval>44.123456</ogr:floatval>
4949
</ogr:dissolve_two_fields>
5050
</gml:featureMember>
5151
<gml:featureMember>
5252
<ogr:dissolve_two_fields fid="polys.7">
53-
<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>
53+
<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>
5454
<ogr:name>cc</ogr:name>
5555
<ogr:floatval>0.123</ogr:floatval>
5656
</ogr:dissolve_two_fields>

python/plugins/processing/tests/testdata/expected/nullGeometryDissolve_output.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<gml:featureMember>
1515
<ogr:nullGeometryDissolve_output fid="nullGeometryDissolve.0">
16-
<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>
16+
<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>
1717
</ogr:nullGeometryDissolve_output>
1818
</gml:featureMember>
1919
</ogr:FeatureCollection>

python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -252,32 +252,30 @@ tests:
252252
name: expected/autoincrement_field.gml
253253
type: vector
254254

255-
# - algorithm: qgis:dissolve
256-
# name: Dissolve using field
257-
# params:
258-
# DISSOLVE_ALL: false
259-
# FIELD: name
260-
# INPUT:
261-
# name: dissolve_polys.gml
262-
# type: vector
263-
# results:
264-
# OUTPUT:
265-
# name: expected/dissolve_field.gml
266-
# type: vector
267-
#
268-
# - algorithm: qgis:dissolve
269-
# name: Dissolve using two fields
270-
# params:
271-
# DISSOLVE_ALL: false
272-
# FIELD: intval;name
273-
# INPUT:
274-
# name: dissolve_polys.gml
275-
# type: vector
276-
# results:
277-
# OUTPUT:
278-
# name: expected/dissolve_two_fields.gml
279-
# type: vector
280-
#
255+
- algorithm: native:dissolve
256+
name: Dissolve using field
257+
params:
258+
FIELD: name
259+
INPUT:
260+
name: dissolve_polys.gml
261+
type: vector
262+
results:
263+
OUTPUT:
264+
name: expected/dissolve_field.gml
265+
type: vector
266+
267+
- algorithm: native:dissolve
268+
name: Dissolve using two fields
269+
params:
270+
FIELD: intval;name
271+
INPUT:
272+
name: dissolve_polys.gml
273+
type: vector
274+
results:
275+
OUTPUT:
276+
name: expected/dissolve_two_fields.gml
277+
type: vector
278+
281279
# - name: Dissolve with geometries reported as valid but as invalid with isGeosValid
282280
# algorithm: qgis:dissolve
283281
# params:

src/core/processing/qgsnativealgorithms.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ QString QgsDissolveAlgorithm::shortHelpString() const
269269
return QObject::tr( "This algorithm takes a polygon or line vector layer and combines their geometries into new geometries. One or more attributes can "
270270
"be specified to dissolve only geometries belonging to the same class (having the same value for the specified attributes), alternatively "
271271
"all geometries can be dissolved.\n\n"
272-
"If the geometries to be dissolved are spatially separated from each other the output will be multi geometries. "
272+
"All output geometries will be converted to multi geometries. "
273273
"In case the input is a polygon layer, common boundaries of adjacent polygons being dissolved will get erased." );
274274
}
275275

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

365-
if ( f.hasGeometry() && f.geometry() )
365+
QVariantList indexAttributes;
366+
Q_FOREACH ( int index, fieldIndexes )
366367
{
367-
QVariantList indexAttributes;
368-
Q_FOREACH ( int index, fieldIndexes )
369-
{
370-
indexAttributes << f.attribute( index );
371-
}
368+
indexAttributes << f.attribute( index );
369+
}
372370

373-
if ( !attributeHash.contains( indexAttributes ) )
374-
{
375-
// keep attributes of first feature
376-
attributeHash.insert( indexAttributes, f.attributes() );
377-
}
371+
if ( !attributeHash.contains( indexAttributes ) )
372+
{
373+
// keep attributes of first feature
374+
attributeHash.insert( indexAttributes, f.attributes() );
375+
}
376+
377+
if ( f.hasGeometry() && f.geometry() )
378+
{
378379
geometryHash[ indexAttributes ].append( f.geometry() );
379380
}
380381
}
381382

382383
int numberFeatures = attributeHash.count();
383-
QHash< QVariant, QList< QgsGeometry > >::const_iterator geomIt = geometryHash.constBegin();
384-
for ( ; geomIt != geometryHash.constEnd(); ++geomIt )
384+
QHash< QVariant, QgsAttributes >::const_iterator attrIt = attributeHash.constBegin();
385+
for ( ; attrIt != attributeHash.constEnd(); ++attrIt )
385386
{
386387
if ( feedback->isCanceled() )
387388
{
388389
break;
389390
}
390391

391392
QgsFeature outputFeature;
392-
outputFeature.setGeometry( QgsGeometry::unaryUnion( geomIt.value() ) );
393-
outputFeature.setAttributes( attributeHash.value( geomIt.key() ) );
393+
if ( geometryHash.contains( attrIt.key() ) )
394+
{
395+
QgsGeometry geom = QgsGeometry::unaryUnion( geometryHash.value( attrIt.key() ) );
396+
if ( !geom.isMultipart() )
397+
{
398+
geom.convertToMultiType();
399+
}
400+
outputFeature.setGeometry( geom );
401+
}
402+
outputFeature.setAttributes( attrIt.value() );
394403
sink->addFeature( outputFeature, QgsFeatureSink::FastInsert );
395404

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

src/core/qgis.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,30 @@ uint qHash( const QVariant &variant )
247247
case QVariant::Char:
248248
return qHash( variant.toChar() );
249249
case QVariant::List:
250+
251+
#if QT_VERSION >= 0x050600
250252
return qHash( variant.toList() );
253+
#else
254+
{
255+
QVariantList list = variant.toList();
256+
if ( list.isEmpty() )
257+
return -1;
258+
else
259+
return qHash( list.at( 0 ) );
260+
}
261+
#endif
251262
case QVariant::StringList:
263+
#if QT_VERSION >= 0x050600
252264
return qHash( variant.toStringList() );
265+
#else
266+
{
267+
QStringList list = variant.toStringList();
268+
if ( list.isEmpty() )
269+
return -1;
270+
else
271+
return qHash( list.at( 0 ) );
272+
}
273+
#endif
253274
case QVariant::ByteArray:
254275
return qHash( variant.toByteArray() );
255276
case QVariant::Date:

0 commit comments

Comments
 (0)