Skip to content

Commit e87cb5b

Browse files
committed
More geos exceptions
1 parent 53cb5df commit e87cb5b

File tree

1 file changed

+59
-34
lines changed

1 file changed

+59
-34
lines changed

src/core/geometry/qgsgeos.cpp

+59-34
Original file line numberDiff line numberDiff line change
@@ -1354,21 +1354,26 @@ GEOSCoordSequence* QgsGeos::createCoordinateSequence( const QgsCurveV2* curve )
13541354
}
13551355

13561356
int numPoints = line->numPoints();
1357-
GEOSCoordSequence* coordSeq = GEOSCoordSeq_create_r( geosinit.ctxt, numPoints, coordDims );
1358-
for ( int i = 0; i < numPoints; ++i )
1357+
GEOSCoordSequence* coordSeq = 0;
1358+
try
13591359
{
1360-
QgsPointV2 pt = line->pointN( i ); //todo: create method to get const point reference
1361-
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, i, pt.x() );
1362-
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, i, pt.y() );
1363-
if ( hasZ )
1364-
{
1365-
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, i, 2, pt.z() );
1366-
}
1367-
if ( hasM )
1360+
coordSeq = GEOSCoordSeq_create_r( geosinit.ctxt, numPoints, coordDims );
1361+
for ( int i = 0; i < numPoints; ++i )
13681362
{
1369-
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, i, 3, pt.m() );
1363+
QgsPointV2 pt = line->pointN( i ); //todo: create method to get const point reference
1364+
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, i, pt.x() );
1365+
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, i, pt.y() );
1366+
if ( hasZ )
1367+
{
1368+
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, i, 2, pt.z() );
1369+
}
1370+
if ( hasM )
1371+
{
1372+
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, i, 3, pt.m() );
1373+
}
13701374
}
13711375
}
1376+
CATCH_GEOS( 0 )
13721377

13731378
if ( segmentize )
13741379
{
@@ -1383,18 +1388,25 @@ GEOSGeometry* QgsGeos::createGeosPoint( const QgsAbstractGeometryV2* point, int
13831388
if ( !pt )
13841389
return 0;
13851390

1386-
GEOSCoordSequence* coordSeq = GEOSCoordSeq_create_r( geosinit.ctxt, 1, coordDims );
1387-
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, 0, pt->x() );
1388-
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, 0, pt->y() );
1389-
if ( pt->is3D() )
1390-
{
1391-
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, 0, 2, pt->z() );
1392-
}
1393-
if ( pt->isMeasure() )
1391+
GEOSGeometry* geosPoint = 0;
1392+
1393+
try
13941394
{
1395-
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, 0, 3, pt->m() );
1395+
GEOSCoordSequence* coordSeq = GEOSCoordSeq_create_r( geosinit.ctxt, 1, coordDims );
1396+
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, 0, pt->x() );
1397+
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, 0, pt->y() );
1398+
if ( pt->is3D() )
1399+
{
1400+
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, 0, 2, pt->z() );
1401+
}
1402+
if ( pt->isMeasure() )
1403+
{
1404+
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, 0, 3, pt->m() );
1405+
}
1406+
geosPoint = GEOSGeom_createPoint_r( geosinit.ctxt, coordSeq );
13961407
}
1397-
return GEOSGeom_createPoint_r( geosinit.ctxt, coordSeq );
1408+
CATCH_GEOS( 0 )
1409+
return geosPoint;
13981410
}
13991411

14001412
GEOSGeometry* QgsGeos::createGeosLinestring( const QgsAbstractGeometryV2* curve )
@@ -1407,7 +1419,13 @@ GEOSGeometry* QgsGeos::createGeosLinestring( const QgsAbstractGeometryV2* curve
14071419
if ( !coordSeq )
14081420
return 0;
14091421

1410-
return GEOSGeom_createLineString_r( geosinit.ctxt, coordSeq );
1422+
GEOSGeometry* geosGeom = 0;
1423+
try
1424+
{
1425+
geosGeom = GEOSGeom_createLineString_r( geosinit.ctxt, coordSeq );
1426+
}
1427+
CATCH_GEOS( 0 )
1428+
return geosGeom;
14111429
}
14121430

14131431
GEOSGeometry* QgsGeos::createGeosPolygon( const QgsAbstractGeometryV2* poly )
@@ -1421,22 +1439,29 @@ GEOSGeometry* QgsGeos::createGeosPolygon( const QgsAbstractGeometryV2* poly )
14211439
{
14221440
return 0;
14231441
}
1424-
GEOSGeometry* exteriorRingGeos = GEOSGeom_createLinearRing_r( geosinit.ctxt, createCoordinateSequence( exteriorRing ) );
14251442

1426-
int nHoles = polygon->numInteriorRings();
1427-
GEOSGeometry** holes = 0;
1428-
if ( nHoles > 0 )
1443+
GEOSGeometry* geosPolygon = 0;
1444+
try
14291445
{
1430-
holes = new GEOSGeometry*[ nHoles ];
1431-
}
1446+
GEOSGeometry* exteriorRingGeos = GEOSGeom_createLinearRing_r( geosinit.ctxt, createCoordinateSequence( exteriorRing ) );
14321447

1433-
for ( int i = 0; i < nHoles; ++i )
1434-
{
1435-
const QgsCurveV2* interiorRing = polygon->interiorRing( i );
1436-
holes[i] = GEOSGeom_createLinearRing_r( geosinit.ctxt, createCoordinateSequence( interiorRing ) );
1448+
1449+
int nHoles = polygon->numInteriorRings();
1450+
GEOSGeometry** holes = 0;
1451+
if ( nHoles > 0 )
1452+
{
1453+
holes = new GEOSGeometry*[ nHoles ];
1454+
}
1455+
1456+
for ( int i = 0; i < nHoles; ++i )
1457+
{
1458+
const QgsCurveV2* interiorRing = polygon->interiorRing( i );
1459+
holes[i] = GEOSGeom_createLinearRing_r( geosinit.ctxt, createCoordinateSequence( interiorRing ) );
1460+
}
1461+
geosPolygon = GEOSGeom_createPolygon_r( geosinit.ctxt, exteriorRingGeos, holes, nHoles );
1462+
delete[] holes;
14371463
}
1438-
GEOSGeometry* geosPolygon = GEOSGeom_createPolygon_r( geosinit.ctxt, exteriorRingGeos, holes, nHoles );
1439-
delete[] holes;
1464+
CATCH_GEOS( 0 )
14401465

14411466
return geosPolygon;
14421467
}

0 commit comments

Comments
 (0)