@@ -1354,21 +1354,26 @@ GEOSCoordSequence* QgsGeos::createCoordinateSequence( const QgsCurveV2* curve )
1354
1354
}
1355
1355
1356
1356
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
1359
1359
{
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 )
1368
1362
{
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
+ }
1370
1374
}
1371
1375
}
1376
+ CATCH_GEOS ( 0 )
1372
1377
1373
1378
if ( segmentize )
1374
1379
{
@@ -1383,18 +1388,25 @@ GEOSGeometry* QgsGeos::createGeosPoint( const QgsAbstractGeometryV2* point, int
1383
1388
if ( !pt )
1384
1389
return 0 ;
1385
1390
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
1394
1394
{
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 );
1396
1407
}
1397
- return GEOSGeom_createPoint_r ( geosinit.ctxt , coordSeq );
1408
+ CATCH_GEOS ( 0 )
1409
+ return geosPoint;
1398
1410
}
1399
1411
1400
1412
GEOSGeometry* QgsGeos::createGeosLinestring ( const QgsAbstractGeometryV2* curve )
@@ -1407,7 +1419,13 @@ GEOSGeometry* QgsGeos::createGeosLinestring( const QgsAbstractGeometryV2* curve
1407
1419
if ( !coordSeq )
1408
1420
return 0 ;
1409
1421
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;
1411
1429
}
1412
1430
1413
1431
GEOSGeometry* QgsGeos::createGeosPolygon ( const QgsAbstractGeometryV2* poly )
@@ -1421,22 +1439,29 @@ GEOSGeometry* QgsGeos::createGeosPolygon( const QgsAbstractGeometryV2* poly )
1421
1439
{
1422
1440
return 0 ;
1423
1441
}
1424
- GEOSGeometry* exteriorRingGeos = GEOSGeom_createLinearRing_r ( geosinit.ctxt , createCoordinateSequence ( exteriorRing ) );
1425
1442
1426
- int nHoles = polygon->numInteriorRings ();
1427
- GEOSGeometry** holes = 0 ;
1428
- if ( nHoles > 0 )
1443
+ GEOSGeometry* geosPolygon = 0 ;
1444
+ try
1429
1445
{
1430
- holes = new GEOSGeometry*[ nHoles ];
1431
- }
1446
+ GEOSGeometry* exteriorRingGeos = GEOSGeom_createLinearRing_r ( geosinit.ctxt , createCoordinateSequence ( exteriorRing ) );
1432
1447
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;
1437
1463
}
1438
- GEOSGeometry* geosPolygon = GEOSGeom_createPolygon_r ( geosinit.ctxt , exteriorRingGeos, holes, nHoles );
1439
- delete[] holes;
1464
+ CATCH_GEOS ( 0 )
1440
1465
1441
1466
return geosPolygon;
1442
1467
}
0 commit comments