@@ -188,9 +188,14 @@ QgsAbstractGeometryV2* QgsGeos::combine( const QList< const QgsAbstractGeometryV
188
188
geosGeometries[i] = asGeos ( geomList.at ( i ) );
189
189
}
190
190
191
- GEOSGeometry* geomCollection = createGeosCollection ( GEOS_GEOMETRYCOLLECTION, geosGeometries );
192
- GEOSGeometry* geomUnion = GEOSUnaryUnion_r ( geosinit.ctxt , geomCollection );
193
- GEOSGeom_destroy_r ( geosinit.ctxt , geomCollection );
191
+ GEOSGeometry* geomUnion = 0 ;
192
+ try
193
+ {
194
+ GEOSGeometry* geomCollection = createGeosCollection ( GEOS_GEOMETRYCOLLECTION, geosGeometries );
195
+ geomUnion = GEOSUnaryUnion_r ( geosinit.ctxt , geomCollection );
196
+ GEOSGeom_destroy_r ( geosinit.ctxt , geomCollection );
197
+ }
198
+ CATCH_GEOS ( 0 )
194
199
195
200
QgsAbstractGeometryV2* result = fromGeos ( geomUnion );
196
201
GEOSGeom_destroy_r ( geosinit.ctxt , geomUnion );
@@ -385,46 +390,51 @@ int QgsGeos::topologicalTestPointsSplit( const GEOSGeometry* splitLine, QList<Qg
385
390
return 1 ;
386
391
}
387
392
388
- testPoints.clear ();
389
- GEOSGeometry* intersectionGeom = GEOSIntersection_r ( geosinit.ctxt , mGeos , splitLine );
390
- if ( !intersectionGeom )
391
- return 1 ;
392
-
393
- bool simple = false ;
394
- int nIntersectGeoms = 1 ;
395
- if ( GEOSGeomTypeId_r ( geosinit.ctxt , intersectionGeom ) == GEOS_LINESTRING
396
- || GEOSGeomTypeId_r ( geosinit.ctxt , intersectionGeom ) == GEOS_POINT )
397
- simple = true ;
393
+ try
394
+ {
395
+ testPoints.clear ();
396
+ GEOSGeometry* intersectionGeom = GEOSIntersection_r ( geosinit.ctxt , mGeos , splitLine );
397
+ if ( !intersectionGeom )
398
+ return 1 ;
398
399
399
- if ( !simple )
400
- nIntersectGeoms = GEOSGetNumGeometries_r ( geosinit.ctxt , intersectionGeom );
400
+ bool simple = false ;
401
+ int nIntersectGeoms = 1 ;
402
+ if ( GEOSGeomTypeId_r ( geosinit.ctxt , intersectionGeom ) == GEOS_LINESTRING
403
+ || GEOSGeomTypeId_r ( geosinit.ctxt , intersectionGeom ) == GEOS_POINT )
404
+ simple = true ;
401
405
402
- for ( int i = 0 ; i < nIntersectGeoms; ++i )
403
- {
404
- const GEOSGeometry* currentIntersectGeom;
405
- if ( simple )
406
- currentIntersectGeom = intersectionGeom;
407
- else
408
- currentIntersectGeom = GEOSGetGeometryN_r ( geosinit.ctxt , intersectionGeom, i );
406
+ if ( !simple )
407
+ nIntersectGeoms = GEOSGetNumGeometries_r ( geosinit.ctxt , intersectionGeom );
409
408
410
- const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq_r ( geosinit.ctxt , currentIntersectGeom );
411
- unsigned int sequenceSize = 0 ;
412
- double x, y;
413
- if ( GEOSCoordSeq_getSize_r ( geosinit.ctxt , lineSequence, &sequenceSize ) != 0 )
409
+ for ( int i = 0 ; i < nIntersectGeoms; ++i )
414
410
{
415
- for ( unsigned int i = 0 ; i < sequenceSize; ++i )
411
+ const GEOSGeometry* currentIntersectGeom;
412
+ if ( simple )
413
+ currentIntersectGeom = intersectionGeom;
414
+ else
415
+ currentIntersectGeom = GEOSGetGeometryN_r ( geosinit.ctxt , intersectionGeom, i );
416
+
417
+ const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq_r ( geosinit.ctxt , currentIntersectGeom );
418
+ unsigned int sequenceSize = 0 ;
419
+ double x, y;
420
+ if ( GEOSCoordSeq_getSize_r ( geosinit.ctxt , lineSequence, &sequenceSize ) != 0 )
416
421
{
417
- if ( GEOSCoordSeq_getX_r ( geosinit. ctxt , lineSequence, i, &x ) ! = 0 )
422
+ for ( unsigned int i = 0 ; i < sequenceSize; ++i )
418
423
{
419
- if ( GEOSCoordSeq_getY_r ( geosinit.ctxt , lineSequence, i, &y ) != 0 )
424
+ if ( GEOSCoordSeq_getX_r ( geosinit.ctxt , lineSequence, i, &x ) != 0 )
420
425
{
421
- testPoints.push_back ( QgsPointV2 ( x, y ) );
426
+ if ( GEOSCoordSeq_getY_r ( geosinit.ctxt , lineSequence, i, &y ) != 0 )
427
+ {
428
+ testPoints.push_back ( QgsPointV2 ( x, y ) );
429
+ }
422
430
}
423
431
}
424
432
}
425
433
}
434
+ GEOSGeom_destroy_r ( geosinit.ctxt , intersectionGeom );
426
435
}
427
- GEOSGeom_destroy_r ( geosinit.ctxt , intersectionGeom );
436
+ CATCH_GEOS ( 1 )
437
+
428
438
return 0 ;
429
439
}
430
440
@@ -1526,61 +1536,65 @@ QgsAbstractGeometryV2* QgsGeos::reshapeGeometry( const QgsLineStringV2& reshapeW
1526
1536
}
1527
1537
else
1528
1538
{
1529
- // call reshape for each geometry part and replace mGeos with new geometry if reshape took place
1530
- bool reshapeTookPlace = false ;
1539
+ try
1540
+ {
1541
+ // call reshape for each geometry part and replace mGeos with new geometry if reshape took place
1542
+ bool reshapeTookPlace = false ;
1531
1543
1532
- GEOSGeometry* currentReshapeGeometry = 0 ;
1533
- GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
1544
+ GEOSGeometry* currentReshapeGeometry = 0 ;
1545
+ GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
1534
1546
1535
- for ( int i = 0 ; i < numGeoms; ++i )
1536
- {
1537
- if ( isLine )
1538
- currentReshapeGeometry = reshapeLine ( GEOSGetGeometryN_r ( geosinit.ctxt , mGeos , i ), reshapeLineGeos );
1539
- else
1540
- currentReshapeGeometry = reshapePolygon ( GEOSGetGeometryN_r ( geosinit.ctxt , mGeos , i ), reshapeLineGeos );
1547
+ for ( int i = 0 ; i < numGeoms; ++i )
1548
+ {
1549
+ if ( isLine )
1550
+ currentReshapeGeometry = reshapeLine ( GEOSGetGeometryN_r ( geosinit.ctxt , mGeos , i ), reshapeLineGeos );
1551
+ else
1552
+ currentReshapeGeometry = reshapePolygon ( GEOSGetGeometryN_r ( geosinit.ctxt , mGeos , i ), reshapeLineGeos );
1553
+
1554
+ if ( currentReshapeGeometry )
1555
+ {
1556
+ newGeoms[i] = currentReshapeGeometry;
1557
+ reshapeTookPlace = true ;
1558
+ }
1559
+ else
1560
+ {
1561
+ newGeoms[i] = GEOSGeom_clone_r ( geosinit.ctxt , GEOSGetGeometryN ( mGeos , i ) );
1562
+ }
1563
+ }
1564
+ GEOSGeom_destroy_r ( geosinit.ctxt , reshapeLineGeos );
1541
1565
1542
- if ( currentReshapeGeometry )
1566
+ GEOSGeometry* newMultiGeom = 0 ;
1567
+ if ( isLine )
1543
1568
{
1544
- newGeoms[i] = currentReshapeGeometry;
1545
- reshapeTookPlace = true ;
1569
+ newMultiGeom = GEOSGeom_createCollection_r ( geosinit.ctxt , GEOS_MULTILINESTRING, newGeoms, numGeoms );
1546
1570
}
1547
- else
1571
+ else // multipolygon
1548
1572
{
1549
- newGeoms[i] = GEOSGeom_clone_r ( geosinit.ctxt , GEOSGetGeometryN ( mGeos , i ) );
1573
+ newMultiGeom = GEOSGeom_createCollection_r ( geosinit.ctxt , GEOS_MULTIPOLYGON, newGeoms, numGeoms );
1550
1574
}
1551
- }
1552
- GEOSGeom_destroy_r ( geosinit.ctxt , reshapeLineGeos );
1553
-
1554
- GEOSGeometry* newMultiGeom = 0 ;
1555
- if ( isLine )
1556
- {
1557
- newMultiGeom = GEOSGeom_createCollection_r ( geosinit.ctxt , GEOS_MULTILINESTRING, newGeoms, numGeoms );
1558
- }
1559
- else // multipolygon
1560
- {
1561
- newMultiGeom = GEOSGeom_createCollection_r ( geosinit.ctxt , GEOS_MULTIPOLYGON, newGeoms, numGeoms );
1562
- }
1563
1575
1564
- delete[] newGeoms;
1565
- if ( !newMultiGeom )
1566
- {
1567
- if ( errorCode ) { *errorCode = 3 ; }
1568
- return 0 ;
1569
- }
1576
+ delete[] newGeoms;
1577
+ if ( !newMultiGeom )
1578
+ {
1579
+ if ( errorCode ) { *errorCode = 3 ; }
1580
+ return 0 ;
1581
+ }
1570
1582
1571
- if ( reshapeTookPlace )
1572
- {
1573
- if ( errorCode ) { *errorCode = 0 ; }
1574
- QgsAbstractGeometryV2* reshapedMultiGeom = fromGeos ( newMultiGeom );
1575
- GEOSGeom_destroy_r ( geosinit.ctxt , newMultiGeom );
1576
- return reshapedMultiGeom;
1577
- }
1578
- else
1579
- {
1580
- GEOSGeom_destroy_r ( geosinit.ctxt , newMultiGeom );
1581
- if ( errorCode ) { *errorCode = 1 ; }
1582
- return 0 ;
1583
+ if ( reshapeTookPlace )
1584
+ {
1585
+ if ( errorCode ) { *errorCode = 0 ; }
1586
+ QgsAbstractGeometryV2* reshapedMultiGeom = fromGeos ( newMultiGeom );
1587
+ GEOSGeom_destroy_r ( geosinit.ctxt , newMultiGeom );
1588
+ return reshapedMultiGeom;
1589
+ }
1590
+ else
1591
+ {
1592
+ GEOSGeom_destroy_r ( geosinit.ctxt , newMultiGeom );
1593
+ if ( errorCode ) { *errorCode = 1 ; }
1594
+ return 0 ;
1595
+ }
1583
1596
}
1597
+ CATCH_GEOS ( 0 )
1584
1598
}
1585
1599
return 0 ;
1586
1600
}
0 commit comments