Skip to content

Commit 1cd4fd6

Browse files
committedJun 5, 2015
Even more geos exceptions
1 parent 476ee1d commit 1cd4fd6

File tree

1 file changed

+90
-76
lines changed

1 file changed

+90
-76
lines changed
 

‎src/core/geometry/qgsgeos.cpp

Lines changed: 90 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,14 @@ QgsAbstractGeometryV2* QgsGeos::combine( const QList< const QgsAbstractGeometryV
188188
geosGeometries[i] = asGeos( geomList.at( i ) );
189189
}
190190

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 )
194199

195200
QgsAbstractGeometryV2* result = fromGeos( geomUnion );
196201
GEOSGeom_destroy_r( geosinit.ctxt, geomUnion );
@@ -385,46 +390,51 @@ int QgsGeos::topologicalTestPointsSplit( const GEOSGeometry* splitLine, QList<Qg
385390
return 1;
386391
}
387392

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;
398399

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;
401405

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 );
409408

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 )
414410
{
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 )
416421
{
417-
if ( GEOSCoordSeq_getX_r( geosinit.ctxt, lineSequence, i, &x ) != 0 )
422+
for ( unsigned int i = 0; i < sequenceSize; ++i )
418423
{
419-
if ( GEOSCoordSeq_getY_r( geosinit.ctxt, lineSequence, i, &y ) != 0 )
424+
if ( GEOSCoordSeq_getX_r( geosinit.ctxt, lineSequence, i, &x ) != 0 )
420425
{
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+
}
422430
}
423431
}
424432
}
425433
}
434+
GEOSGeom_destroy_r( geosinit.ctxt, intersectionGeom );
426435
}
427-
GEOSGeom_destroy_r( geosinit.ctxt, intersectionGeom );
436+
CATCH_GEOS( 1 )
437+
428438
return 0;
429439
}
430440

@@ -1526,61 +1536,65 @@ QgsAbstractGeometryV2* QgsGeos::reshapeGeometry( const QgsLineStringV2& reshapeW
15261536
}
15271537
else
15281538
{
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;
15311543

1532-
GEOSGeometry* currentReshapeGeometry = 0;
1533-
GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
1544+
GEOSGeometry* currentReshapeGeometry = 0;
1545+
GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
15341546

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 );
15411565

1542-
if ( currentReshapeGeometry )
1566+
GEOSGeometry* newMultiGeom = 0;
1567+
if ( isLine )
15431568
{
1544-
newGeoms[i] = currentReshapeGeometry;
1545-
reshapeTookPlace = true;
1569+
newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTILINESTRING, newGeoms, numGeoms );
15461570
}
1547-
else
1571+
else //multipolygon
15481572
{
1549-
newGeoms[i] = GEOSGeom_clone_r( geosinit.ctxt, GEOSGetGeometryN( mGeos, i ) );
1573+
newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTIPOLYGON, newGeoms, numGeoms );
15501574
}
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-
}
15631575

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+
}
15701582

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+
}
15831596
}
1597+
CATCH_GEOS( 0 )
15841598
}
15851599
return 0;
15861600
}

0 commit comments

Comments
 (0)
Failed to load comments.