@@ -35,6 +35,15 @@ email : morb at ozemail dot com dot au
35
35
#define GEOS_SIZE_T int
36
36
#define COORD_SEQ_FACTORY DefaultCoordinateSequenceFactory
37
37
#define GEOS_EXCEPTION GEOS_UTIL::GEOSException*
38
+
39
+ #define CATCH_GEOS (r ) \
40
+ catch (GEOS_EXCEPTION e) \
41
+ { \
42
+ QString error = e->toString ().c_str (); \
43
+ delete e; \
44
+ QgsDebugMsg (" GEOS: " + error); \
45
+ return r; \
46
+ }
38
47
#else
39
48
#include < geos/geom/CoordinateArraySequence.h>
40
49
#include < geos/geom/CoordinateArraySequenceFactory.h>
@@ -56,6 +65,13 @@ email : morb at ozemail dot com dot au
56
65
#define GEOS_SIZE_T size_t
57
66
#define COORD_SEQ_FACTORY CoordinateArraySequenceFactory
58
67
#define GEOS_EXCEPTION GEOS_UTIL::GEOSException&
68
+
69
+ #define CATCH_GEOS (r ) \
70
+ catch (GEOS_EXCEPTION e) \
71
+ { \
72
+ QgsDebugMsg (" GEOS: " + QString ( e.what () ) ); \
73
+ return r; \
74
+ }
59
75
#endif
60
76
61
77
// Set up static GEOS geometry factory
@@ -77,12 +93,9 @@ mDirtyGeos(FALSE)
77
93
QgsGeometry::QgsGeometry ( QgsGeometry const & rhs )
78
94
: mGeometry(0 ),
79
95
mGeometrySize( rhs.mGeometrySize ),
80
-
81
96
mDirtyWkb( rhs.mDirtyWkb ),
82
- mDirtyGeos( rhs.mDirtyGeos )
83
- {
84
-
85
-
97
+ mDirtyGeos( rhs.mDirtyGeos )
98
+ {
86
99
if ( mGeometrySize && rhs.mGeometry )
87
100
{
88
101
mGeometry = new unsigned char [mGeometrySize ];
@@ -93,40 +106,40 @@ mDirtyGeos( rhs.mDirtyGeos )
93
106
if (rhs.mGeos )
94
107
{
95
108
if (rhs.mGeos ->getGeometryTypeId () == GEOS_GEOM::GEOS_MULTIPOLYGON)// MH:problems with cloning for multipolygons in geos 2
109
+ {
110
+ GEOS_GEOM::MultiPolygon* multiPoly = dynamic_cast <GEOS_GEOM::MultiPolygon*>(rhs.mGeos );
111
+ if (multiPoly)
96
112
{
97
- GEOS_GEOM::MultiPolygon* multiPoly = dynamic_cast <GEOS_GEOM::MultiPolygon*>(rhs.mGeos );
98
- if (multiPoly)
99
- {
100
- std::vector<GEOS_GEOM::Geometry*> polygonVector;
101
- for (GEOS_SIZE_T i = 0 ; i < multiPoly->getNumGeometries (); ++i)
102
- {
103
- polygonVector.push_back ((GEOS_GEOM::Geometry*)(multiPoly->getGeometryN (i)));
104
- }
105
- mGeos = geosGeometryFactory->createMultiPolygon (polygonVector);
106
- }
113
+ std::vector<GEOS_GEOM::Geometry*> polygonVector;
114
+ for (GEOS_SIZE_T i = 0 ; i < multiPoly->getNumGeometries (); ++i)
115
+ {
116
+ polygonVector.push_back ((GEOS_GEOM::Geometry*)(multiPoly->getGeometryN (i)));
117
+ }
118
+ mGeos = geosGeometryFactory->createMultiPolygon (polygonVector);
107
119
}
120
+ }
108
121
else if (rhs.mGeos ->getGeometryTypeId () == GEOS_GEOM::GEOS_MULTILINESTRING) // MH: and also for cloning multilines
122
+ {
123
+ GEOS_GEOM::MultiLineString* multiLine = dynamic_cast <GEOS_GEOM::MultiLineString*>(rhs.mGeos );
124
+ if (multiLine)
109
125
{
110
- GEOS_GEOM::MultiLineString* multiLine = dynamic_cast <GEOS_GEOM::MultiLineString*>(rhs.mGeos );
111
- if (multiLine)
112
- {
113
- std::vector<GEOS_GEOM::Geometry*> lineVector;
114
- for (GEOS_SIZE_T i = 0 ; i < multiLine->getNumGeometries (); ++i)
115
- {
116
- lineVector.push_back ((GEOS_GEOM::Geometry*)(multiLine->getGeometryN (i)));
117
- }
118
- mGeos = geosGeometryFactory->createMultiLineString (lineVector);
119
- }
126
+ std::vector<GEOS_GEOM::Geometry*> lineVector;
127
+ for (GEOS_SIZE_T i = 0 ; i < multiLine->getNumGeometries (); ++i)
128
+ {
129
+ lineVector.push_back ((GEOS_GEOM::Geometry*)(multiLine->getGeometryN (i)));
130
+ }
131
+ mGeos = geosGeometryFactory->createMultiLineString (lineVector);
120
132
}
133
+ }
121
134
else
122
- {
123
- mGeos = rhs.mGeos ->clone ();
124
- }
135
+ {
136
+ mGeos = rhs.mGeos ->clone ();
137
+ }
125
138
}
126
139
else
127
140
{
128
141
mGeos = 0 ;
129
- }
142
+ }
130
143
}
131
144
132
145
QgsGeometry* QgsGeometry::fromWkt (QString wkt)
@@ -143,18 +156,11 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
143
156
GEOS_GEOM::Coordinate coord = GEOS_GEOM::Coordinate (point.x (), point.y ());
144
157
GEOS_GEOM::Geometry* geom = 0 ;
145
158
try
146
- {
147
- geom = geosGeometryFactory->createPoint (coord);
148
- }
149
- catch (GEOS_EXCEPTION e)
150
- {
151
- #if GEOS_VERSION_MAJOR < 3
152
- delete e;
153
- #else
154
- UNUSED (e);
155
- #endif
156
- return 0 ;
157
- }
159
+ {
160
+ geom = geosGeometryFactory->createPoint (coord);
161
+ }
162
+ CATCH_GEOS (0 )
163
+
158
164
QgsGeometry* g = new QgsGeometry;
159
165
g->setGeos (geom);
160
166
return g;
@@ -164,41 +170,27 @@ QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
164
170
{
165
171
std::vector<GEOS_GEOM::Geometry*>* pointVector = new std::vector<GEOS_GEOM::Geometry*>(multipoint.size ());
166
172
GEOS_GEOM::Coordinate currentCoord;
173
+ std::auto_ptr< std::vector<GEOS_GEOM::Geometry*> > owner (pointVector);
167
174
168
175
for (int i = 0 ; i < multipoint.size (); ++i)
169
- {
170
- currentCoord.x = multipoint.at (i).x ();
171
- currentCoord.y = multipoint.at (i).y ();
172
- try
173
- {
174
- (*pointVector)[i] = geosGeometryFactory->createPoint (currentCoord);
175
- }
176
- catch (GEOS_EXCEPTION e)
177
- {
178
- #if GEOS_VERSION_MAJOR < 3
179
- delete e;
180
- #else
181
- UNUSED (e);
182
- #endif
183
- delete pointVector; return 0 ;
184
- }
176
+ {
177
+ currentCoord.x = multipoint.at (i).x ();
178
+ currentCoord.y = multipoint.at (i).y ();
179
+ try
180
+ {
181
+ (*pointVector)[i] = geosGeometryFactory->createPoint (currentCoord);
185
182
}
183
+ CATCH_GEOS (0 )
184
+ }
186
185
187
186
GEOS_GEOM::Geometry* geom = 0 ;
188
187
try
189
- {
190
- geom = geosGeometryFactory->createMultiPoint (pointVector);
191
- }
192
- catch (GEOS_EXCEPTION e)
193
- {
194
- #if GEOS_VERSION_MAJOR < 3
195
- delete e;
196
- #else
197
- UNUSED (e);
198
- #endif
199
- return 0 ;
200
- }
201
-
188
+ {
189
+ geom = geosGeometryFactory->createMultiPoint (pointVector);
190
+ owner.release ();
191
+ }
192
+ CATCH_GEOS (0 )
193
+
202
194
QgsGeometry* g = new QgsGeometry;
203
195
g->setGeos (geom);
204
196
return g;
@@ -208,6 +200,7 @@ QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
208
200
{
209
201
const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance ();
210
202
GEOS_GEOM::CoordinateSequence* seq = seqFactory->create (polyline.count (), 2 );
203
+ std::auto_ptr< GEOS_GEOM::CoordinateSequence > owner (seq);
211
204
212
205
QgsPolyline::const_iterator it;
213
206
int i = 0 ;
@@ -221,17 +214,10 @@ QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
221
214
try
222
215
{
223
216
geom = geosGeometryFactory->createLineString (seq);
217
+ owner.release ();
224
218
}
225
- catch (GEOS_EXCEPTION e)
226
- {
227
- #if GEOS_VERSION_MAJOR < 3
228
- delete e;
229
- #else
230
- UNUSED (e);
231
- #endif
232
- delete seq;
233
- return 0 ;
234
- }
219
+ CATCH_GEOS (0 )
220
+
235
221
QgsGeometry* g = new QgsGeometry;
236
222
g->setGeos (geom);
237
223
return g;
@@ -242,46 +228,36 @@ QgsGeometry* QgsGeometry::fromMultiPolyline(const QgsMultiPolyline& multiline)
242
228
const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance ();
243
229
std::vector<GEOS_GEOM::Geometry*>* lineVector = new std::vector<GEOS_GEOM::Geometry*>(multiline.count ());
244
230
GEOS_GEOM::LineString* currentLineString = 0 ;
245
-
231
+ std::auto_ptr< std::vector<GEOS_GEOM::Geometry*> > owner (lineVector);
232
+
246
233
for (int i = 0 ; i < multiline.count (); ++i)
234
+ {
235
+ QgsPolyline currentLine = multiline.at (i);
236
+ GEOS_GEOM::CoordinateSequence* seq = seqFactory->create (currentLine.count (), 2 );
237
+ std::auto_ptr< GEOS_GEOM::CoordinateSequence > owner (seq);
238
+
239
+ for (int j = 0 ; j < currentLine.count (); ++j)
247
240
{
248
- QgsPolyline currentLine = multiline.at (i);
249
- GEOS_GEOM::CoordinateSequence* seq = seqFactory->create (currentLine.count (), 2 );
250
- for (int j = 0 ; j < currentLine.count (); ++j)
251
- {
252
- seq->setAt (GEOS_GEOM::Coordinate (currentLine.at (j).x (), currentLine.at (j).y ()), j);
253
- }
254
- try
255
- {
256
- currentLineString = geosGeometryFactory->createLineString (seq);
257
- }
258
- catch (GEOS_EXCEPTION e)
259
- {
260
- #if GEOS_VERSION_MAJOR < 3
261
- delete e;
262
- #else
263
- UNUSED (e);
264
- #endif
265
- delete lineVector; delete seq;
266
- return 0 ;
267
- }
268
- (*lineVector)[i] = currentLineString;
269
- }
270
-
271
- GEOS_GEOM::Geometry* geom = 0 ;
272
- try
273
- {
274
- geom = geosGeometryFactory->createMultiLineString (lineVector);
241
+ seq->setAt (GEOS_GEOM::Coordinate (currentLine.at (j).x (), currentLine.at (j).y ()), j);
275
242
}
276
- catch (GEOS_EXCEPTION e)
243
+ try
277
244
{
278
- #if GEOS_VERSION_MAJOR < 3
279
- delete e;
280
- #else
281
- UNUSED (e);
282
- #endif
283
- return 0 ;
245
+ currentLineString = geosGeometryFactory->createLineString (seq);
246
+ owner.release ();
284
247
}
248
+ CATCH_GEOS (0 )
249
+
250
+ (*lineVector)[i] = currentLineString;
251
+ }
252
+
253
+ GEOS_GEOM::Geometry* geom = 0 ;
254
+ try
255
+ {
256
+ geom = geosGeometryFactory->createMultiLineString (lineVector);
257
+ owner.release ();
258
+ }
259
+ CATCH_GEOS (0 )
260
+
285
261
QgsGeometry* g = new QgsGeometry;
286
262
g->setGeos (geom);
287
263
return g;
@@ -301,40 +277,32 @@ static GEOS_GEOM::LinearRing* _createGeosLinearRing(const QgsPolyline& ring)
301
277
{
302
278
seq->setAt (GEOS_GEOM::Coordinate (it->x (), it->y ()), i++);
303
279
}
304
-
280
+
305
281
// add the first point to close the ring if needed
306
282
if (needRepeatLastPnt)
307
283
seq->setAt (GEOS_GEOM::Coordinate (ring[0 ].x (), ring[0 ].y ()), ring.count ());
308
-
284
+
309
285
// ring takes ownership of the sequence
310
286
GEOS_GEOM::LinearRing* linRing = 0 ;
311
287
try
312
- {
313
- linRing = geosGeometryFactory->createLinearRing (seq);
314
- }
315
- catch (GEOS_EXCEPTION e)
316
- {
317
- #if GEOS_VERSION_MAJOR < 3
318
- delete e;
319
- #else
320
- UNUSED (e);
321
- #endif
322
- return 0 ;
323
- }
324
-
288
+ {
289
+ linRing = geosGeometryFactory->createLinearRing (seq);
290
+ }
291
+ CATCH_GEOS (0 )
292
+
325
293
return linRing;
326
294
}
327
295
328
296
QgsGeometry* QgsGeometry::fromPolygon (const QgsPolygon& polygon)
329
297
{
330
298
if (polygon.count () == 0 )
331
299
return NULL ;
332
-
300
+
333
301
const QgsPolyline& ring0 = polygon[0 ];
334
-
302
+
335
303
// outer ring
336
304
GEOS_GEOM::LinearRing* outerRing = _createGeosLinearRing (ring0);
337
-
305
+
338
306
// holes
339
307
std::vector<GEOS_GEOM::Geometry*>* holes = new std::vector<GEOS_GEOM::Geometry*> (polygon.count ()-1 );
340
308
for (int i = 1 ; i < polygon.count (); i++)
@@ -345,18 +313,11 @@ QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
345
313
// new geometry takes ownership of outerRing and vector of holes
346
314
GEOS_GEOM::Geometry* geom = 0 ;
347
315
try
348
- {
349
- geom = geosGeometryFactory->createPolygon (outerRing, holes);
350
- }
351
- catch (GEOS_EXCEPTION e)
352
- {
353
- #if GEOS_VERSION_MAJOR < 3
354
- delete e;
355
- #else
356
- UNUSED (e);
357
- #endif
358
- return 0 ;
359
- }
316
+ {
317
+ geom = geosGeometryFactory->createPolygon (outerRing, holes);
318
+ }
319
+ CATCH_GEOS (0 )
320
+
360
321
QgsGeometry* g = new QgsGeometry;
361
322
g->setGeos (geom);
362
323
return g;
@@ -365,53 +326,41 @@ QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
365
326
QgsGeometry* QgsGeometry::fromMultiPolygon (const QgsMultiPolygon& multipoly)
366
327
{
367
328
if (multipoly.count () == 0 )
368
- {
369
- return 0 ;
370
- }
329
+ {
330
+ return 0 ;
331
+ }
371
332
372
333
std::vector<GEOS_GEOM::Geometry*>* polygons = new std::vector<GEOS_GEOM::Geometry*>(multipoly.count ());
334
+ std::auto_ptr< std::vector<GEOS_GEOM::Geometry*> > owner (polygons);
373
335
GEOS_GEOM::Polygon* currentPolygon = 0 ;
374
336
GEOS_GEOM::LinearRing* currentOuterRing = 0 ;
375
337
std::vector<GEOS_GEOM::Geometry*>* currentHoles = 0 ;
376
338
377
339
for (int i = 0 ; i < multipoly.count (); ++i)
340
+ {
341
+ currentOuterRing = _createGeosLinearRing (multipoly[i].at (0 ));
342
+ currentHoles = new std::vector<GEOS_GEOM::Geometry*>(multipoly[i].count () - 1 );
343
+ for (int j = 1 ; j < multipoly[i].count (); ++j)
378
344
{
379
- currentOuterRing = _createGeosLinearRing (multipoly[i].at (0 ));
380
- currentHoles = new std::vector<GEOS_GEOM::Geometry*>(multipoly[i].count () - 1 );
381
- for (int j = 1 ; j < multipoly[i].count (); ++j)
382
- {
383
- (*currentHoles)[j-1 ] = _createGeosLinearRing (multipoly[i].at (j));
384
- }
385
- try
386
- {
387
- currentPolygon = geosGeometryFactory->createPolygon (currentOuterRing, currentHoles);
388
- }
389
- catch (GEOS_EXCEPTION e)
390
- {
391
- #if GEOS_VERSION_MAJOR < 3
392
- delete e;
393
- #else
394
- UNUSED (e);
395
- #endif
396
- delete polygons; return 0 ;
397
- }
398
- (*polygons)[i] = currentPolygon;
345
+ (*currentHoles)[j-1 ] = _createGeosLinearRing (multipoly[i].at (j));
346
+ }
347
+ try
348
+ {
349
+ currentPolygon = geosGeometryFactory->createPolygon (currentOuterRing, currentHoles);
399
350
}
351
+ CATCH_GEOS (0 )
352
+
353
+ (*polygons)[i] = currentPolygon;
354
+ }
400
355
401
356
GEOS_GEOM::Geometry* geom = 0 ;
402
357
try
403
- {
404
- geom = geosGeometryFactory->createMultiPolygon (polygons);
405
- }
406
- catch (GEOS_EXCEPTION e)
407
- {
408
- #if GEOS_VERSION_MAJOR < 3
409
- delete e;
410
- #else
411
- UNUSED (e);
412
- #endif
413
- return 0 ;
414
- }
358
+ {
359
+ geom = geosGeometryFactory->createMultiPolygon (polygons);
360
+ owner.release ();
361
+ }
362
+ CATCH_GEOS (0 )
363
+
415
364
QgsGeometry* g = new QgsGeometry;
416
365
g->setGeos (geom);
417
366
return g;
@@ -452,35 +401,35 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
452
401
if (rhs.mGeos )
453
402
{
454
403
if (rhs.mGeos ->getGeometryTypeId () == GEOS_GEOM::GEOS_MULTIPOLYGON)// MH:problems with cloning for multipolygons in geos 2
404
+ {
405
+ GEOS_GEOM::MultiPolygon* multiPoly = dynamic_cast <GEOS_GEOM::MultiPolygon*>(rhs.mGeos );
406
+ if (multiPoly)
455
407
{
456
- GEOS_GEOM::MultiPolygon* multiPoly = dynamic_cast <GEOS_GEOM::MultiPolygon*>(rhs.mGeos );
457
- if (multiPoly)
458
- {
459
- std::vector<GEOS_GEOM::Geometry*> polygonVector;
460
- for (GEOS_SIZE_T i = 0 ; i < multiPoly->getNumGeometries (); ++i)
461
- {
462
- polygonVector.push_back ((GEOS_GEOM::Geometry*)(multiPoly->getGeometryN (i)));
463
- }
464
- mGeos = geosGeometryFactory->createMultiPolygon (polygonVector);
465
- }
408
+ std::vector<GEOS_GEOM::Geometry*> polygonVector;
409
+ for (GEOS_SIZE_T i = 0 ; i < multiPoly->getNumGeometries (); ++i)
410
+ {
411
+ polygonVector.push_back ((GEOS_GEOM::Geometry*)(multiPoly->getGeometryN (i)));
412
+ }
413
+ mGeos = geosGeometryFactory->createMultiPolygon (polygonVector);
466
414
}
415
+ }
467
416
else if (rhs.mGeos ->getGeometryTypeId () == GEOS_GEOM::GEOS_MULTILINESTRING) // MH: and also for cloning multilines
417
+ {
418
+ GEOS_GEOM::MultiLineString* multiLine = dynamic_cast <GEOS_GEOM::MultiLineString*>(rhs.mGeos );
419
+ if (multiLine)
468
420
{
469
- GEOS_GEOM::MultiLineString* multiLine = dynamic_cast <GEOS_GEOM::MultiLineString*>(rhs.mGeos );
470
- if (multiLine)
471
- {
472
- std::vector<GEOS_GEOM::Geometry*> lineVector;
473
- for (GEOS_SIZE_T i = 0 ; i < multiLine->getNumGeometries (); ++i)
474
- {
475
- lineVector.push_back ((GEOS_GEOM::Geometry*)(multiLine->getGeometryN (i)));
476
- }
477
- mGeos = geosGeometryFactory->createMultiLineString (lineVector);
478
- }
421
+ std::vector<GEOS_GEOM::Geometry*> lineVector;
422
+ for (GEOS_SIZE_T i = 0 ; i < multiLine->getNumGeometries (); ++i)
423
+ {
424
+ lineVector.push_back ((GEOS_GEOM::Geometry*)(multiLine->getGeometryN (i)));
425
+ }
426
+ mGeos = geosGeometryFactory->createMultiLineString (lineVector);
479
427
}
428
+ }
480
429
else
481
- {
482
- mGeos = rhs.mGeos ->clone ();
483
- }
430
+ {
431
+ mGeos = rhs.mGeos ->clone ();
432
+ }
484
433
}
485
434
else
486
435
{
@@ -534,7 +483,6 @@ void QgsGeometry::setWkbAndOwnership(unsigned char * wkb, size_t length)
534
483
535
484
mDirtyWkb = FALSE ;
536
485
mDirtyGeos = TRUE ;
537
-
538
486
}
539
487
540
488
unsigned char * QgsGeometry::wkbBuffer ()
@@ -563,15 +511,15 @@ QGis::WKBTYPE QgsGeometry::wkbType()
563
511
{
564
512
unsigned char *geom = wkbBuffer (); // ensure that wkb representation exists
565
513
if (geom)
566
- {
567
- unsigned int wkbType;
568
- memcpy (&wkbType, (geom+1 ), sizeof (wkbType));
569
- return (QGis::WKBTYPE) wkbType;
570
- }
514
+ {
515
+ unsigned int wkbType;
516
+ memcpy (&wkbType, (geom+1 ), sizeof (wkbType));
517
+ return (QGis::WKBTYPE) wkbType;
518
+ }
571
519
else
572
- {
573
- return QGis::WKBUnknown;
574
- }
520
+ {
521
+ return QGis::WKBUnknown;
522
+ }
575
523
}
576
524
577
525
@@ -2541,308 +2489,294 @@ int QgsGeometry::addRing(const QList<QgsPoint>& ring)
2541
2489
{
2542
2490
// bail out if this geometry is not polygon/multipolygon
2543
2491
if (vectorType () != QGis::Polygon)
2544
- {
2545
- return 1 ;
2546
- }
2492
+ {
2493
+ return 1 ;
2494
+ }
2547
2495
2548
2496
// test for invalid geometries
2549
2497
if (ring.size () < 4 )
2550
- {
2551
- return 3 ;
2552
- }
2498
+ {
2499
+ return 3 ;
2500
+ }
2553
2501
2554
2502
// ring must be closed
2555
2503
if (ring.first () != ring.last ())
2556
- {
2557
- return 2 ;
2558
- }
2559
-
2504
+ {
2505
+ return 2 ;
2506
+ }
2507
+
2560
2508
// create geos geometry from wkb if not already there
2561
2509
if (!mGeos || mDirtyGeos )
2562
- {
2563
- exportWkbToGeos ();
2564
- }
2565
-
2510
+ {
2511
+ exportWkbToGeos ();
2512
+ }
2513
+
2566
2514
// Fill GEOS Polygons of the feature into list
2567
2515
std::list<GEOS_GEOM::Polygon*> polygonList; // list of polygon pointers (only one for polygon geometries)
2568
2516
GEOS_GEOM::Polygon* thisPolygon = 0 ;
2569
2517
GEOS_GEOM::MultiPolygon* thisMultiPolygon = 0 ;
2570
2518
2571
2519
if (this ->wkbType () == QGis::WKBPolygon)
2520
+ {
2521
+ thisPolygon = dynamic_cast <GEOS_GEOM::Polygon*>(mGeos );
2522
+ if (!thisPolygon)
2572
2523
{
2573
- thisPolygon = dynamic_cast <GEOS_GEOM::Polygon*>(mGeos );
2574
- if (!thisPolygon)
2575
- {
2576
- return 1 ;
2577
- }
2578
- polygonList.push_back (thisPolygon);
2524
+ return 1 ;
2579
2525
}
2526
+ polygonList.push_back (thisPolygon);
2527
+ }
2580
2528
else if (this ->wkbType () == QGis::WKBMultiPolygon)
2529
+ {
2530
+ thisMultiPolygon = dynamic_cast <GEOS_GEOM::MultiPolygon*>(mGeos );
2531
+ if (!thisMultiPolygon)
2581
2532
{
2582
- thisMultiPolygon = dynamic_cast <GEOS_GEOM::MultiPolygon*>(mGeos );
2583
- if (!thisMultiPolygon)
2584
- {
2585
- return 1 ;
2586
- }
2587
- int numPolys = thisMultiPolygon->getNumGeometries ();
2588
- for (int i = 0 ; i < numPolys; ++i)
2589
- {
2590
- polygonList.push_back ((GEOS_GEOM::Polygon*)(thisMultiPolygon->getGeometryN (i)));
2591
- }
2533
+ return 1 ;
2534
+ }
2535
+ int numPolys = thisMultiPolygon->getNumGeometries ();
2536
+ for (int i = 0 ; i < numPolys; ++i)
2537
+ {
2538
+ polygonList.push_back ((GEOS_GEOM::Polygon*)(thisMultiPolygon->getGeometryN (i)));
2592
2539
}
2540
+ }
2593
2541
2594
2542
// create new ring
2595
2543
GEOS_GEOM::DefaultCoordinateSequence* newSequence=new GEOS_GEOM::DefaultCoordinateSequence ();
2544
+ std::auto_ptr< GEOS_GEOM::DefaultCoordinateSequence > owner (newSequence);
2596
2545
for (QList<QgsPoint>::const_iterator it = ring.begin (); it != ring.end (); ++it)
2597
- {
2598
- newSequence->add (GEOS_GEOM::Coordinate (it->x (),it->y ()));
2599
- }
2600
-
2601
-
2546
+ {
2547
+ newSequence->add (GEOS_GEOM::Coordinate (it->x (),it->y ()));
2548
+ }
2549
+
2602
2550
// create new ring
2603
2551
GEOS_GEOM::LinearRing* newRing = 0 ;
2604
2552
try
2605
- {
2606
- newRing = geosGeometryFactory->createLinearRing (newSequence);
2607
- }
2608
- catch (GEOS_EXCEPTION e)
2609
- {
2610
- #if GEOS_VERSION_MAJOR < 3
2611
- delete e;
2612
- #else
2613
- UNUSED (e);
2614
- #endif
2615
- delete newSequence;
2616
- return 3 ;
2617
- }
2553
+ {
2554
+ newRing = geosGeometryFactory->createLinearRing (newSequence);
2555
+ owner.release ();
2556
+ }
2557
+ CATCH_GEOS (3 )
2558
+
2618
2559
std::vector<GEOS_GEOM::Geometry*> dummyVector;
2619
2560
2620
2561
// create polygon from new ring because there is a problem with geos operations and linear rings
2621
2562
GEOS_GEOM::Polygon* newRingPolygon = geosGeometryFactory->createPolygon (*newRing, dummyVector);
2622
2563
if (!newRing || !newRingPolygon || !newRing->isValid () || !newRingPolygon->isValid ())
2623
- {
2624
- QgsDebugMsg (" ring is not valid" );
2625
- delete newRing;
2626
- delete newRingPolygon;
2627
- return 3 ;
2628
- }
2629
-
2630
- GEOS_GEOM::LinearRing* outerRing = 0 ; // outer ring of already existing feature
2564
+ {
2565
+ QgsDebugMsg (" ring is not valid" );
2566
+ delete newRing;
2567
+ delete newRingPolygon;
2568
+ return 3 ;
2569
+ }
2570
+
2571
+ GEOS_GEOM::LinearRing* outerRing = 0 ; // outer ring of already existing feature
2631
2572
std::vector<GEOS_GEOM::Geometry*>* inner = 0 ; // vector of inner rings. The existing rings and the new one will be added
2632
2573
int numberOfPolyContainingRing = 0 ; // for multipolygons: store index of the polygon where the ring is
2633
2574
bool foundPoly = false ; // set to true as soon we found a polygon containing the ring
2634
2575
2635
2576
for (std::list<GEOS_GEOM::Polygon*>::const_iterator it = polygonList.begin (); it != polygonList.end (); ++it)
2577
+ {
2578
+ /* **********inner rings*****************************************/
2579
+ // consider already existing rings
2580
+ inner=new std::vector<GEOS_GEOM::Geometry*>();
2581
+ int numExistingRings = (*it)->getNumInteriorRing ();
2582
+ inner->resize (numExistingRings + 1 );
2583
+ for (int i = 0 ; i < numExistingRings; ++i)
2636
2584
{
2637
- /* **********inner rings*****************************************/
2638
- // consider already existing rings
2639
- inner=new std::vector<GEOS_GEOM::Geometry*>();
2640
- int numExistingRings = (*it)->getNumInteriorRing ();
2641
- inner->resize (numExistingRings + 1 );
2642
- for (int i = 0 ; i < numExistingRings; ++i)
2643
- {
2644
- GEOS_GEOM::LinearRing* existingRing = geosGeometryFactory->createLinearRing ((*it)->getInteriorRingN (i)->getCoordinates ());
2645
- // create polygon from new ring because there is a problem with geos operations and linear rings
2646
- GEOS_GEOM::Polygon* existingRingPolygon = geosGeometryFactory->createPolygon (*existingRing, dummyVector);
2647
-
2585
+ GEOS_GEOM::LinearRing* existingRing = geosGeometryFactory->createLinearRing ((*it)->getInteriorRingN (i)->getCoordinates ());
2586
+ // create polygon from new ring because there is a problem with geos operations and linear rings
2587
+ GEOS_GEOM::Polygon* existingRingPolygon = geosGeometryFactory->createPolygon (*existingRing, dummyVector);
2588
+
2648
2589
// check, if the new ring intersects the existing one and bail out if yes
2649
- // if(existingRing->disjoint(newRing))
2650
- if (!existingRingPolygon->disjoint (newRingPolygon)) // does only work with polygons, not linear rings
2651
- {
2652
- QgsDebugMsg (" new ring not disjoint with existing ring" );
2653
- // delete objects wich are no longer needed
2654
- delete existingRing;
2655
- delete existingRingPolygon;
2656
- for (std::vector<GEOS_GEOM::Geometry*>::iterator it = inner->begin (); it != inner->end (); ++it)
2657
- {
2658
- delete *it;
2659
- }
2660
- delete inner;
2661
- delete newRing;
2662
- delete newRingPolygon;
2663
- return 4 ; // error: ring not disjoint with existing rings
2664
- }
2665
- (*inner)[i] = existingRing;
2666
- delete existingRingPolygon; // delete since this polygon has only be created for disjoint() test
2667
- }
2668
-
2669
- // also add new ring to the vector
2670
- if (newRing)
2671
- {
2672
- (*inner)[numExistingRings] = newRing;
2673
- }
2590
+ // if(existingRing->disjoint(newRing))
2591
+ if (!existingRingPolygon->disjoint (newRingPolygon)) // does only work with polygons, not linear rings
2592
+ {
2593
+ QgsDebugMsg (" new ring not disjoint with existing ring" );
2594
+ // delete objects wich are no longer needed
2595
+ delete existingRing;
2596
+ delete existingRingPolygon;
2597
+ for (std::vector<GEOS_GEOM::Geometry*>::iterator it = inner->begin (); it != inner->end (); ++it)
2598
+ {
2599
+ delete *it;
2600
+ }
2601
+ delete inner;
2602
+ delete newRing;
2603
+ delete newRingPolygon;
2604
+ return 4 ; // error: ring not disjoint with existing rings
2605
+ }
2606
+ (*inner)[i] = existingRing;
2607
+ delete existingRingPolygon; // delete since this polygon has only be created for disjoint() test
2608
+ }
2674
2609
2675
- /* ****************outer ring****************/
2676
- outerRing = geosGeometryFactory->createLinearRing ((*it)->getExteriorRing ()->getCoordinates ());
2677
- // create polygon from new ring because there is a problem with geos operations and linear rings
2678
- GEOS_GEOM::Polygon* outerRingPolygon = geosGeometryFactory->createPolygon (*outerRing, dummyVector);
2610
+ // also add new ring to the vector
2611
+ if (newRing)
2612
+ {
2613
+ (*inner)[numExistingRings] = newRing;
2614
+ }
2679
2615
2680
- // check if the new ring is within the outer shell of the polygon and bail out if not
2681
- // if(newRing->within(outerRing))
2682
- if (newRingPolygon->within (outerRingPolygon)) // does only work for polygons, not linear rings
2683
- {
2684
- QgsDebugMsg (" new ring within outer ring" );
2685
- foundPoly = true ;
2686
- delete outerRingPolygon;
2687
- break ; // ring is in geometry and does not intersect existing rings -> proceed with adding ring to feature
2688
- }
2616
+ /* ****************outer ring****************/
2617
+ outerRing = geosGeometryFactory->createLinearRing ((*it)->getExteriorRing ()->getCoordinates ());
2618
+ // create polygon from new ring because there is a problem with geos operations and linear rings
2619
+ GEOS_GEOM::Polygon* outerRingPolygon = geosGeometryFactory->createPolygon (*outerRing, dummyVector);
2620
+
2621
+ // check if the new ring is within the outer shell of the polygon and bail out if not
2622
+ // if(newRing->within(outerRing))
2623
+ if (newRingPolygon->within (outerRingPolygon)) // does only work for polygons, not linear rings
2624
+ {
2625
+ QgsDebugMsg (" new ring within outer ring" );
2626
+ foundPoly = true ;
2627
+ delete outerRingPolygon;
2628
+ break ; // ring is in geometry and does not intersect existing rings -> proceed with adding ring to feature
2629
+ }
2689
2630
2690
- // we need to search in other polygons...
2691
- for (std::vector<GEOS_GEOM::Geometry*>::iterator it = inner->begin (); it != inner->end (); ++it)
2631
+ // we need to search in other polygons...
2632
+ for (std::vector<GEOS_GEOM::Geometry*>::iterator it = inner->begin (); it != inner->end (); ++it)
2633
+ {
2634
+ if ( (*it) != newRing) // we need newRing for later polygons
2692
2635
{
2693
- if ( (*it) != newRing) // we need newRing for later polygons
2694
- {
2695
- delete *it;
2696
- }
2636
+ delete *it;
2697
2637
}
2698
- delete inner;
2699
- delete outerRing;
2700
- delete outerRingPolygon;
2701
-
2702
- ++numberOfPolyContainingRing;
2703
2638
}
2639
+ delete inner;
2640
+ delete outerRing;
2641
+ delete outerRingPolygon;
2642
+
2643
+ ++numberOfPolyContainingRing;
2644
+ }
2704
2645
2705
2646
delete newRingPolygon;
2706
-
2647
+
2707
2648
if (foundPoly)
2649
+ {
2650
+ GEOS_GEOM::Polygon* newPolygon = geosGeometryFactory->createPolygon (outerRing,inner);
2651
+ if (this ->wkbType () == QGis::WKBPolygon)
2708
2652
{
2709
- GEOS_GEOM::Polygon* newPolygon = geosGeometryFactory->createPolygon (outerRing,inner);
2710
- if (this ->wkbType () == QGis::WKBPolygon)
2711
- {
2712
- delete mGeos ;
2713
- mGeos = newPolygon;
2714
- }
2715
- else if (this ->wkbType () == QGis::WKBMultiPolygon)
2716
- {
2717
- // remember in which polygon the ring is and replace only this polygon
2718
- std::vector<GEOS_GEOM::Geometry*>* polygons = new std::vector<GEOS_GEOM::Geometry*>();
2719
- int numPolys = thisMultiPolygon->getNumGeometries ();
2720
- for (int i = 0 ; i < numPolys; ++i)
2721
- {
2722
- if (i == numberOfPolyContainingRing)
2723
- {
2724
- polygons->push_back (newPolygon);
2725
- }
2726
- else
2727
- {
2728
- GEOS_GEOM::Polygon* p = (GEOS_GEOM::Polygon*)(thisMultiPolygon->getGeometryN (i)->clone ());
2729
- polygons->push_back (p);
2730
- }
2731
- }
2732
- delete mGeos ;
2733
- mGeos = geosGeometryFactory->createMultiPolygon (polygons);
2734
- }
2735
- mDirtyWkb = true ;
2736
- mDirtyGeos = false ;
2737
- return 0 ;
2653
+ delete mGeos ;
2654
+ mGeos = newPolygon;
2738
2655
}
2739
- else
2656
+ else if ( this -> wkbType () == QGis::WKBMultiPolygon)
2740
2657
{
2741
- delete newRing;
2742
- return 5 ;
2658
+ // remember in which polygon the ring is and replace only this polygon
2659
+ std::vector<GEOS_GEOM::Geometry*>* polygons = new std::vector<GEOS_GEOM::Geometry*>();
2660
+ int numPolys = thisMultiPolygon->getNumGeometries ();
2661
+ for (int i = 0 ; i < numPolys; ++i)
2662
+ {
2663
+ if (i == numberOfPolyContainingRing)
2664
+ {
2665
+ polygons->push_back (newPolygon);
2666
+ }
2667
+ else
2668
+ {
2669
+ GEOS_GEOM::Polygon* p = (GEOS_GEOM::Polygon*)(thisMultiPolygon->getGeometryN (i)->clone ());
2670
+ polygons->push_back (p);
2671
+ }
2672
+ }
2673
+ delete mGeos ;
2674
+ mGeos = geosGeometryFactory->createMultiPolygon (polygons);
2743
2675
}
2676
+ mDirtyWkb = true ;
2677
+ mDirtyGeos = false ;
2678
+ return 0 ;
2679
+ }
2680
+ else
2681
+ {
2682
+ delete newRing;
2683
+ return 5 ;
2684
+ }
2744
2685
}
2745
2686
2746
2687
int QgsGeometry::addIsland (const QList<QgsPoint>& ring)
2747
2688
{
2748
2689
// Ring needs to have at least three points and must be closed
2749
2690
if (ring.size () < 4 )
2750
- {
2751
- return 2 ;
2752
- }
2691
+ {
2692
+ return 2 ;
2693
+ }
2753
2694
2754
2695
// ring must be closed
2755
2696
if (ring.first () != ring.last ())
2756
- {
2757
- return 2 ;
2758
- }
2697
+ {
2698
+ return 2 ;
2699
+ }
2759
2700
2760
2701
if (wkbType () == QGis::WKBPolygon || wkbType () == QGis::WKBPolygon25D)
2702
+ {
2703
+ if (!convertToMultiType ())
2761
2704
{
2762
- if (!convertToMultiType ())
2763
- {
2764
- return 1 ;
2765
- }
2705
+ return 1 ;
2766
2706
}
2707
+ }
2767
2708
2768
2709
// bail out if wkbtype is not multipolygon
2769
2710
if (wkbType () != QGis::WKBMultiPolygon && wkbType () != QGis::WKBMultiPolygon25D)
2770
- {
2771
- return 1 ;
2772
- }
2711
+ {
2712
+ return 1 ;
2713
+ }
2773
2714
2774
2715
// create geos geometry from wkb if not already there
2775
2716
if (!mGeos || mDirtyGeos )
2776
- {
2777
- exportWkbToGeos ();
2778
- }
2717
+ {
2718
+ exportWkbToGeos ();
2719
+ }
2779
2720
2780
2721
// this multipolygon
2781
2722
GEOS_GEOM::MultiPolygon* thisMultiPolygon = dynamic_cast <GEOS_GEOM::MultiPolygon*>(mGeos );
2782
2723
if (!thisMultiPolygon)
2783
- {
2784
- return 1 ;
2785
- }
2724
+ {
2725
+ return 1 ;
2726
+ }
2786
2727
2787
2728
// create new polygon from ring
2788
2729
2789
2730
// coordinate sequence first
2790
2731
GEOS_GEOM::DefaultCoordinateSequence* newSequence=new GEOS_GEOM::DefaultCoordinateSequence ();
2732
+ std::auto_ptr< GEOS_GEOM::DefaultCoordinateSequence > owner (newSequence);
2791
2733
for (QList<QgsPoint>::const_iterator it = ring.begin (); it != ring.end (); ++it)
2792
- {
2793
- newSequence->add (GEOS_GEOM::Coordinate (it->x (),it->y ()));
2794
- }
2795
-
2734
+ {
2735
+ newSequence->add (GEOS_GEOM::Coordinate (it->x (),it->y ()));
2736
+ }
2737
+
2796
2738
// then linear ring
2797
2739
GEOS_GEOM::LinearRing* newRing = 0 ;
2798
2740
try
2799
- {
2800
- newRing = geosGeometryFactory->createLinearRing (newSequence);
2801
- }
2802
- catch (GEOS_EXCEPTION e)
2803
- {
2804
- #if GEOS_VERSION_MAJOR < 3
2805
- delete e;
2806
- #else
2807
- UNUSED (e);
2808
- #endif
2809
- delete newSequence;
2810
- return 2 ;
2811
- }
2741
+ {
2742
+ newRing = geosGeometryFactory->createLinearRing (newSequence);
2743
+ owner.release ();
2744
+ }
2745
+ CATCH_GEOS (2 )
2812
2746
2813
2747
// finally the polygon
2814
2748
std::vector<GEOS_GEOM::Geometry*> dummyVector;
2815
2749
GEOS_GEOM::Polygon* newPolygon = geosGeometryFactory->createPolygon (*newRing, dummyVector);
2816
2750
delete newRing;
2817
2751
2818
2752
if (!newPolygon || !newPolygon->isValid ())
2819
- {
2820
- delete newPolygon;
2821
- return 2 ;
2822
- }
2753
+ {
2754
+ delete newPolygon;
2755
+ return 2 ;
2756
+ }
2823
2757
2824
2758
// create new multipolygon
2825
2759
std::vector<GEOS_GEOM::Geometry*>* newMultiPolygonVector = new std::vector<GEOS_GEOM::Geometry*>();
2826
2760
for (GEOS_SIZE_T i = 0 ; i < thisMultiPolygon->getNumGeometries (); ++i)
2761
+ {
2762
+ const GEOS_GEOM::Geometry* polygonN = thisMultiPolygon->getGeometryN (i);
2763
+
2764
+ // bail out if new polygon is not disjoint with existing ones
2765
+ if (!polygonN->disjoint (newPolygon))
2827
2766
{
2828
- const GEOS_GEOM::Geometry* polygonN = thisMultiPolygon->getGeometryN (i);
2829
-
2830
- // bail out if new polygon is not disjoint with existing ones
2831
- if (!polygonN->disjoint (newPolygon))
2832
- {
2833
- delete newPolygon;
2834
- for (std::vector<GEOS_GEOM::Geometry*>::iterator it =newMultiPolygonVector->begin (); it != newMultiPolygonVector->end (); ++it)
2835
- {
2836
- delete *it;
2837
- }
2838
- delete newMultiPolygonVector;
2839
- return 3 ;
2840
- }
2841
- newMultiPolygonVector->push_back (polygonN->clone ());
2767
+ delete newPolygon;
2768
+ for (std::vector<GEOS_GEOM::Geometry*>::iterator it =newMultiPolygonVector->begin (); it != newMultiPolygonVector->end (); ++it)
2769
+ {
2770
+ delete *it;
2771
+ }
2772
+ delete newMultiPolygonVector;
2773
+ return 3 ;
2842
2774
}
2775
+ newMultiPolygonVector->push_back (polygonN->clone ());
2776
+ }
2843
2777
newMultiPolygonVector->push_back (newPolygon);
2844
2778
GEOS_GEOM::MultiPolygon* newMultiPolygon = geosGeometryFactory->createMultiPolygon (newMultiPolygonVector);
2845
-
2779
+
2846
2780
delete mGeos ;
2847
2781
mGeos = newMultiPolygon;
2848
2782
@@ -2983,138 +2917,123 @@ int QgsGeometry::splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeomet
2983
2917
2984
2918
// return if this type is point/multipoint
2985
2919
if (vectorType () == QGis::Point)
2986
- {
2987
- return 1 ; // cannot split points
2988
- }
2920
+ {
2921
+ return 1 ; // cannot split points
2922
+ }
2989
2923
2990
2924
// make sure, mGeos and mWkb are there and up-to-date
2991
2925
if (mDirtyWkb )
2992
- {
2993
- exportGeosToWkb ();
2994
- }
2926
+ {
2927
+ exportGeosToWkb ();
2928
+ }
2995
2929
if (!mGeos || mDirtyGeos )
2996
- {
2997
- exportWkbToGeos ();
2998
- }
2930
+ {
2931
+ exportWkbToGeos ();
2932
+ }
2999
2933
3000
2934
// make sure splitLine is valid
3001
2935
if (splitLine.size () < 2 )
2936
+ {
2937
+ return 1 ;
2938
+ }
2939
+
2940
+ newGeometries.clear ();
2941
+
2942
+ try
2943
+ {
2944
+ GEOS_GEOM::DefaultCoordinateSequence* splitLineCoords = new GEOS_GEOM::DefaultCoordinateSequence ();
2945
+ QList<QgsPoint>::const_iterator lineIt;
2946
+ for (lineIt = splitLine.constBegin (); lineIt != splitLine.constEnd (); ++lineIt)
2947
+ {
2948
+ splitLineCoords->add (GEOS_GEOM::Coordinate (lineIt->x (),lineIt->y ()));
2949
+ }
2950
+ GEOS_GEOM::LineString* splitLineGeos = geosGeometryFactory->createLineString (splitLineCoords);
2951
+ if (!splitLineGeos)
3002
2952
{
2953
+ delete splitLineCoords;
3003
2954
return 1 ;
3004
2955
}
3005
2956
3006
- newGeometries.clear ();
2957
+ if (!splitLineGeos->isValid () || !splitLineGeos->isSimple ())
2958
+ {
2959
+ delete splitLineGeos;
2960
+ return 1 ;
2961
+ }
3007
2962
3008
- try
2963
+ // for line/multiline: call splitLinearGeometry
2964
+ if (vectorType () == QGis::Line)
3009
2965
{
3010
- GEOS_GEOM::DefaultCoordinateSequence* splitLineCoords = new GEOS_GEOM::DefaultCoordinateSequence ();
3011
- QList<QgsPoint>::const_iterator lineIt;
3012
- for (lineIt = splitLine.constBegin (); lineIt != splitLine.constEnd (); ++lineIt)
3013
- {
3014
- splitLineCoords->add (GEOS_GEOM::Coordinate (lineIt->x (),lineIt->y ()));
3015
- }
3016
- GEOS_GEOM::LineString* splitLineGeos = geosGeometryFactory->createLineString (splitLineCoords);
3017
- if (!splitLineGeos)
3018
- {
3019
- delete splitLineCoords;
3020
- return 1 ;
3021
- }
3022
-
3023
- if (!splitLineGeos->isValid () || !splitLineGeos->isSimple ())
3024
- {
3025
- delete splitLineGeos;
3026
- return 1 ;
3027
- }
3028
-
3029
- // for line/multiline: call splitLinearGeometry
3030
- if (vectorType () == QGis::Line)
3031
- {
3032
- returnCode = splitLinearGeometry (splitLineGeos, newGeometries);
3033
- delete splitLineGeos;
3034
- }
3035
- else if (vectorType () == QGis::Polygon)
3036
- {
3037
- returnCode = splitPolygonGeometry (splitLineGeos, newGeometries);
3038
- delete splitLineGeos;
3039
- }
3040
- else
3041
- {
3042
- return 1 ;
3043
- }
2966
+ returnCode = splitLinearGeometry (splitLineGeos, newGeometries);
2967
+ delete splitLineGeos;
3044
2968
}
3045
- catch (GEOS_EXCEPTION e )
2969
+ else if ( vectorType () == QGis::Polygon )
3046
2970
{
3047
- # if GEOS_VERSION_MAJOR < 3
3048
- delete e ;
3049
- # else
3050
- UNUSED (e);
3051
- # endif
3052
- return 2 ;
2971
+ returnCode = splitPolygonGeometry (splitLineGeos, newGeometries);
2972
+ delete splitLineGeos ;
2973
+ }
2974
+ else
2975
+ {
2976
+ return 1 ;
3053
2977
}
2978
+ }
2979
+ CATCH_GEOS (2 )
2980
+
3054
2981
return returnCode;
3055
2982
}
3056
2983
3057
2984
int QgsGeometry::makeDifference (QgsGeometry* other)
3058
2985
{
3059
2986
// make sure geos geometry is up to date
3060
2987
if (!mGeos || mDirtyGeos )
3061
- {
3062
- exportWkbToGeos ();
3063
- }
2988
+ {
2989
+ exportWkbToGeos ();
2990
+ }
3064
2991
3065
2992
if (!mGeos )
3066
- {
3067
- return 1 ;
3068
- }
2993
+ {
2994
+ return 1 ;
2995
+ }
3069
2996
3070
2997
if (!mGeos ->isValid ())
3071
- {
3072
- return 2 ;
3073
- }
2998
+ {
2999
+ return 2 ;
3000
+ }
3074
3001
3075
3002
if (!mGeos ->isSimple ())
3076
- {
3077
- return 3 ;
3078
- }
3003
+ {
3004
+ return 3 ;
3005
+ }
3079
3006
3080
3007
// convert other geometry to geos
3081
3008
if (!other->mGeos || other->mDirtyGeos )
3082
- {
3083
- other->exportWkbToGeos ();
3084
- }
3085
-
3009
+ {
3010
+ other->exportWkbToGeos ();
3011
+ }
3012
+
3086
3013
if (!other->mGeos )
3087
- {
3088
- return 4 ;
3089
- }
3014
+ {
3015
+ return 4 ;
3016
+ }
3090
3017
3091
3018
// make geometry::difference
3092
3019
try
3020
+ {
3021
+ if (mGeos ->intersects (other->mGeos ))
3093
3022
{
3094
- if (mGeos ->intersects (other->mGeos ))
3095
- {
3096
- mGeos = mGeos ->difference (other->mGeos );
3097
- }
3098
- else
3099
- {
3100
- return 0 ; // nothing to do
3101
- }
3023
+ mGeos = mGeos ->difference (other->mGeos );
3102
3024
}
3103
- catch (GEOS_EXCEPTION e)
3025
+ else
3104
3026
{
3105
- #if GEOS_VERSION_MAJOR < 3
3106
- delete e;
3107
- #else
3108
- UNUSED (e);
3109
- #endif
3110
- return 5 ;
3027
+ return 0 ; // nothing to do
3111
3028
}
3112
-
3029
+ }
3030
+ CATCH_GEOS (5 )
3031
+
3113
3032
if (!mGeos )
3114
- {
3115
- mDirtyGeos = true ;
3116
- return 6 ;
3117
- }
3033
+ {
3034
+ mDirtyGeos = true ;
3035
+ return 6 ;
3036
+ }
3118
3037
3119
3038
// set wkb dirty to true
3120
3039
mDirtyWkb = true ;
@@ -3424,17 +3343,7 @@ bool QgsGeometry::intersects(QgsGeometry* geometry)
3424
3343
3425
3344
return mGeos ->intersects (geometry->mGeos );
3426
3345
}
3427
- catch (GEOS_EXCEPTION e)
3428
- {
3429
- #if GEOS_VERSION_MAJOR < 3
3430
- QString error = e->toString ().c_str ();
3431
- delete e;
3432
- #else
3433
- QString error = e.what ();
3434
- #endif
3435
- QgsLogger::warning (" GEOS: " + error);
3436
- return false ;
3437
- }
3346
+ CATCH_GEOS (false )
3438
3347
}
3439
3348
3440
3349
@@ -3449,10 +3358,15 @@ bool QgsGeometry::contains(QgsPoint* p)
3449
3358
}
3450
3359
3451
3360
GEOS_GEOM::Point* geosPoint = geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (p->x (), p->y ()));
3361
+ std::auto_ptr< GEOS_GEOM::Point > owner (geosPoint);
3452
3362
3453
- bool returnval = mGeos ->contains (geosPoint);
3454
-
3455
- delete geosPoint;
3363
+ bool returnval;
3364
+ try
3365
+ {
3366
+ returnval = mGeos ->contains (geosPoint);
3367
+ owner.release ();
3368
+ }
3369
+ CATCH_GEOS (false )
3456
3370
3457
3371
return returnval;
3458
3372
}
@@ -3779,233 +3693,227 @@ bool QgsGeometry::exportWkbToGeos()
3779
3693
// wkbtype = (mGeometry[0] == 1) ? mGeometry[1] : mGeometry[4];
3780
3694
memcpy (&wkbtype, &(mGeometry [1 ]), sizeof (int ));
3781
3695
3782
- try { // try-catch block for geos exceptions
3696
+ try
3697
+ {
3783
3698
switch (wkbtype)
3699
+ {
3700
+ case QGis::WKBPoint25D:
3701
+ case QGis::WKBPoint:
3784
3702
{
3785
- case QGis::WKBPoint25D:
3786
- case QGis::WKBPoint:
3787
- {
3788
- x = (double *) (mGeometry + 5 );
3789
- y = (double *) (mGeometry + 5 + sizeof (double ));
3703
+ x = (double *) (mGeometry + 5 );
3704
+ y = (double *) (mGeometry + 5 + sizeof (double ));
3790
3705
3791
- mGeos = geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y));
3792
- mDirtyGeos = FALSE ;
3793
- break ;
3794
- }
3795
-
3796
- case QGis::WKBMultiPoint25D:
3797
- hasZValue = true ;
3798
- case QGis::WKBMultiPoint:
3799
- {
3800
- std::vector<GEOS_GEOM::Geometry*>* points=new std::vector<GEOS_GEOM::Geometry*>;
3801
- ptr = mGeometry + 5 ;
3802
- nPoints = (int *) ptr;
3803
- ptr = mGeometry + 1 + 2 * sizeof (int );
3804
- for (idx = 0 ; idx < *nPoints; idx++)
3805
- {
3806
- ptr += (1 + sizeof (int ));
3807
- x = (double *) ptr;
3808
- ptr += sizeof (double );
3809
- y = (double *) ptr;
3810
- ptr += sizeof (double );
3811
- if (hasZValue)
3812
- {
3813
- ptr += sizeof (double );
3814
- }
3815
- points->push_back (geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y)));
3816
- }
3817
- mGeos = geosGeometryFactory->createMultiPoint (points);
3818
- mDirtyGeos = FALSE ;
3819
- break ;
3820
- }
3821
-
3822
- case QGis::WKBLineString25D:
3823
- hasZValue = true ;
3824
- case QGis::WKBLineString:
3825
- {
3826
- QgsDebugMsg (" QgsGeometry::geosGeometry: Linestring found" );
3827
-
3828
- GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3829
- ptr = mGeometry + 5 ;
3830
- nPoints = (int *) ptr;
3831
- ptr = mGeometry + 1 + 2 * sizeof (int );
3832
- for (idx = 0 ; idx < *nPoints; idx++)
3833
- {
3834
- x = (double *) ptr;
3835
- ptr += sizeof (double );
3836
- y = (double *) ptr;
3837
- ptr += sizeof (double );
3838
- if (hasZValue)
3839
- {
3840
- ptr += sizeof (double );
3841
- }
3842
- sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3843
- }
3844
- mDirtyGeos = FALSE ;
3845
- mGeos = geosGeometryFactory->createLineString (sequence);
3846
- break ;
3847
- }
3706
+ mGeos = geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y));
3707
+ mDirtyGeos = FALSE ;
3708
+ break ;
3709
+ }
3710
+
3711
+ case QGis::WKBMultiPoint25D:
3712
+ hasZValue = true ;
3713
+ case QGis::WKBMultiPoint:
3714
+ {
3715
+ std::vector<GEOS_GEOM::Geometry*>* points=new std::vector<GEOS_GEOM::Geometry*>;
3716
+ ptr = mGeometry + 5 ;
3717
+ nPoints = (int *) ptr;
3718
+ ptr = mGeometry + 1 + 2 * sizeof (int );
3719
+ for (idx = 0 ; idx < *nPoints; idx++)
3720
+ {
3721
+ ptr += (1 + sizeof (int ));
3722
+ x = (double *) ptr;
3723
+ ptr += sizeof (double );
3724
+ y = (double *) ptr;
3725
+ ptr += sizeof (double );
3726
+ if (hasZValue)
3727
+ {
3728
+ ptr += sizeof (double );
3729
+ }
3730
+ points->push_back (geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y)));
3731
+ }
3732
+ mGeos = geosGeometryFactory->createMultiPoint (points);
3733
+ mDirtyGeos = FALSE ;
3734
+ break ;
3735
+ }
3736
+
3737
+ case QGis::WKBLineString25D:
3738
+ hasZValue = true ;
3739
+ case QGis::WKBLineString:
3740
+ {
3741
+ QgsDebugMsg (" QgsGeometry::geosGeometry: Linestring found" );
3742
+
3743
+ GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3744
+ ptr = mGeometry + 5 ;
3745
+ nPoints = (int *) ptr;
3746
+ ptr = mGeometry + 1 + 2 * sizeof (int );
3747
+ for (idx = 0 ; idx < *nPoints; idx++)
3748
+ {
3749
+ x = (double *) ptr;
3750
+ ptr += sizeof (double );
3751
+ y = (double *) ptr;
3752
+ ptr += sizeof (double );
3753
+ if (hasZValue)
3754
+ {
3755
+ ptr += sizeof (double );
3756
+ }
3757
+ sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3758
+ }
3759
+ mDirtyGeos = FALSE ;
3760
+ mGeos = geosGeometryFactory->createLineString (sequence);
3761
+ break ;
3762
+ }
3763
+
3764
+ case QGis::WKBMultiLineString25D:
3765
+ hasZValue = true ;
3766
+ case QGis::WKBMultiLineString:
3767
+ {
3768
+ std::vector<GEOS_GEOM::Geometry*>* lines=new std::vector<GEOS_GEOM::Geometry*>;
3769
+ numLineStrings = (int ) (mGeometry [5 ]);
3770
+ ptr = (mGeometry + 9 );
3771
+ for (jdx = 0 ; jdx < numLineStrings; jdx++)
3772
+ {
3773
+ GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3774
+ // each of these is a wbklinestring so must handle as such
3775
+ lsb = *ptr;
3776
+ ptr += 5 ; // skip type since we know its 2
3777
+ nPoints = (int *) ptr;
3778
+ ptr += sizeof (int );
3779
+ for (idx = 0 ; idx < *nPoints; idx++)
3780
+ {
3781
+ x = (double *) ptr;
3782
+ ptr += sizeof (double );
3783
+ y = (double *) ptr;
3784
+ ptr += sizeof (double );
3785
+ if (hasZValue)
3786
+ {
3787
+ ptr += sizeof (double );
3788
+ }
3789
+ sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3790
+ }
3791
+ lines->push_back (geosGeometryFactory->createLineString (sequence));
3792
+ }
3793
+ mGeos = geosGeometryFactory->createMultiLineString (lines);
3794
+ mDirtyGeos = FALSE ;
3795
+ break ;
3796
+ }
3848
3797
3849
- case QGis::WKBMultiLineString25D:
3850
- hasZValue = true ;
3851
- case QGis::WKBMultiLineString:
3852
- {
3853
- std::vector<GEOS_GEOM::Geometry*>* lines=new std::vector<GEOS_GEOM::Geometry*>;
3854
- numLineStrings = (int ) (mGeometry [5 ]);
3855
- ptr = (mGeometry + 9 );
3856
- for (jdx = 0 ; jdx < numLineStrings; jdx++)
3857
- {
3858
- GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3859
- // each of these is a wbklinestring so must handle as such
3860
- lsb = *ptr;
3861
- ptr += 5 ; // skip type since we know its 2
3862
- nPoints = (int *) ptr;
3863
- ptr += sizeof (int );
3864
- for (idx = 0 ; idx < *nPoints; idx++)
3865
- {
3866
- x = (double *) ptr;
3867
- ptr += sizeof (double );
3868
- y = (double *) ptr;
3869
- ptr += sizeof (double );
3870
- if (hasZValue)
3871
- {
3872
- ptr += sizeof (double );
3873
- }
3874
- sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3875
- }
3876
- lines->push_back (geosGeometryFactory->createLineString (sequence));
3877
- }
3878
- mGeos = geosGeometryFactory->createMultiLineString (lines);
3879
- mDirtyGeos = FALSE ;
3880
- break ;
3881
- }
3882
-
3883
- case QGis::WKBPolygon25D:
3884
- hasZValue = true ;
3885
- case QGis::WKBPolygon:
3886
- {
3887
- QgsDebugMsg (" Polygon found" );
3888
-
3889
- // get number of rings in the polygon
3890
- numRings = (int *) (mGeometry + 1 + sizeof (int ));
3891
- ptr = mGeometry + 1 + 2 * sizeof (int );
3892
-
3893
- GEOS_GEOM::LinearRing* outer=0 ;
3894
- std::vector<GEOS_GEOM::Geometry*>* inner=new std::vector<GEOS_GEOM::Geometry*>;
3895
-
3896
- for (idx = 0 ; idx < *numRings; idx++)
3897
- {
3898
-
3899
- // QgsDebugMsg("Ring nr: "+QString::number(idx));
3900
-
3901
- GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3902
- // get number of points in the ring
3903
- nPoints = (int *) ptr;
3798
+ case QGis::WKBPolygon25D:
3799
+ hasZValue = true ;
3800
+ case QGis::WKBPolygon:
3801
+ {
3802
+ QgsDebugMsg (" Polygon found" );
3803
+
3804
+ // get number of rings in the polygon
3805
+ numRings = (int *) (mGeometry + 1 + sizeof (int ));
3806
+ ptr = mGeometry + 1 + 2 * sizeof (int );
3807
+
3808
+ GEOS_GEOM::LinearRing* outer=0 ;
3809
+ std::vector<GEOS_GEOM::Geometry*>* inner=new std::vector<GEOS_GEOM::Geometry*>;
3810
+
3811
+ for (idx = 0 ; idx < *numRings; idx++)
3812
+ {
3813
+
3814
+ // QgsDebugMsg("Ring nr: "+QString::number(idx));
3815
+
3816
+ GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3817
+ // get number of points in the ring
3818
+ nPoints = (int *) ptr;
3904
3819
ptr += 4 ;
3905
3820
for (jdx = 0 ; jdx < *nPoints; jdx++)
3906
- {
3907
- // add points to a point array for drawing the polygon
3908
- x = (double *) ptr;
3909
- ptr += sizeof (double );
3910
- y = (double *) ptr;
3911
- ptr += sizeof (double );
3912
- if (hasZValue)
3913
- {
3914
- ptr += sizeof (double );
3915
- }
3916
- sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3917
- }
3821
+ {
3822
+ // add points to a point array for drawing the polygon
3823
+ x = (double *) ptr;
3824
+ ptr += sizeof (double );
3825
+ y = (double *) ptr;
3826
+ ptr += sizeof (double );
3827
+ if (hasZValue)
3828
+ {
3829
+ ptr += sizeof (double );
3830
+ }
3831
+ sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3832
+ }
3918
3833
GEOS_GEOM::LinearRing* ring=geosGeometryFactory->createLinearRing (sequence);
3919
3834
if (idx==0 )
3920
- {
3921
- outer=ring;
3922
- }
3835
+ {
3836
+ outer=ring;
3837
+ }
3923
3838
else
3924
- {
3925
- inner->push_back (ring);
3926
- }
3927
- }
3928
- mGeos = geosGeometryFactory->createPolygon (outer,inner);
3929
- mDirtyGeos = FALSE ;
3930
- break ;
3931
- }
3932
-
3933
- case QGis::WKBMultiPolygon25D:
3934
- hasZValue = true ;
3935
- case QGis::WKBMultiPolygon:
3936
- {
3937
- QgsDebugMsg (" Multipolygon found" );
3938
-
3939
- std::vector<GEOS_GEOM::Geometry *> *polygons=new std::vector<GEOS_GEOM::Geometry *>;
3940
- // get the number of polygons
3941
- ptr = mGeometry + 5 ;
3942
- numPolygons = (int *) ptr;
3943
- ptr = mGeometry +9 ;
3944
- for (kdx = 0 ; kdx < *numPolygons; kdx++)
3945
- {
3946
-
3947
- // QgsDebugMsg("Polygon nr: "+QString::number(kdx));
3948
-
3949
- GEOS_GEOM::LinearRing* outer=0 ;
3950
- std::vector<GEOS_GEOM::Geometry*>* inner=new std::vector<GEOS_GEOM::Geometry*>;
3951
-
3952
- // skip the endian and mGeometry type info and
3953
- // get number of rings in the polygon
3954
- ptr += 5 ;
3955
- numRings = (int *) ptr;
3956
- ptr += 4 ;
3957
- for (idx = 0 ; idx < *numRings; idx++)
3958
- {
3959
- // QgsDebugMsg("Ring nr: "+QString::number(idx));
3960
-
3961
- GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3962
- // get number of points in the ring
3963
- nPoints = (int *) ptr;
3964
- ptr += 4 ;
3965
- for (jdx = 0 ; jdx < *nPoints; jdx++)
3966
- {
3967
- // add points to a point array for drawing the polygon
3968
- x = (double *) ptr;
3969
- ptr += sizeof (double );
3970
- y = (double *) ptr;
3971
- ptr += sizeof (double );
3972
- if (hasZValue)
3973
- {
3974
- ptr += sizeof (double );
3975
- }
3976
- sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3977
- }
3978
- GEOS_GEOM::LinearRing* ring=geosGeometryFactory->createLinearRing (sequence);
3979
- if (idx==0 )
3980
- {
3981
- outer=ring;
3982
- }
3983
- else
3984
- {
3985
- inner->push_back (ring);
3986
- }
3987
- }
3988
-
3989
- polygons->push_back (geosGeometryFactory->createPolygon (outer,inner));
3990
- }
3991
- mGeos = geosGeometryFactory->createMultiPolygon (polygons);
3992
- mDirtyGeos = FALSE ;
3993
- break ;
3994
- }
3995
-
3996
- default :
3997
- return FALSE ;
3839
+ {
3840
+ inner->push_back (ring);
3841
+ }
3842
+ }
3843
+ mGeos = geosGeometryFactory->createPolygon (outer,inner);
3844
+ mDirtyGeos = FALSE ;
3845
+ break ;
3998
3846
}
3999
- }
4000
- catch (GEOS_EXCEPTION e)
4001
- {
4002
- #if GEOS_VERSION_MAJOR < 3
4003
- delete e;
4004
- #else
4005
- UNUSED (e);
4006
- #endif
3847
+
3848
+ case QGis::WKBMultiPolygon25D:
3849
+ hasZValue = true ;
3850
+ case QGis::WKBMultiPolygon:
3851
+ {
3852
+ QgsDebugMsg (" Multipolygon found" );
3853
+
3854
+ std::vector<GEOS_GEOM::Geometry *> *polygons=new std::vector<GEOS_GEOM::Geometry *>;
3855
+ // get the number of polygons
3856
+ ptr = mGeometry + 5 ;
3857
+ numPolygons = (int *) ptr;
3858
+ ptr = mGeometry +9 ;
3859
+ for (kdx = 0 ; kdx < *numPolygons; kdx++)
3860
+ {
3861
+
3862
+ // QgsDebugMsg("Polygon nr: "+QString::number(kdx));
3863
+
3864
+ GEOS_GEOM::LinearRing* outer=0 ;
3865
+ std::vector<GEOS_GEOM::Geometry*>* inner=new std::vector<GEOS_GEOM::Geometry*>;
3866
+
3867
+ // skip the endian and mGeometry type info and
3868
+ // get number of rings in the polygon
3869
+ ptr += 5 ;
3870
+ numRings = (int *) ptr;
3871
+ ptr += 4 ;
3872
+ for (idx = 0 ; idx < *numRings; idx++)
3873
+ {
3874
+ // QgsDebugMsg("Ring nr: "+QString::number(idx));
3875
+
3876
+ GEOS_GEOM::DefaultCoordinateSequence* sequence=new GEOS_GEOM::DefaultCoordinateSequence ();
3877
+ // get number of points in the ring
3878
+ nPoints = (int *) ptr;
3879
+ ptr += 4 ;
3880
+ for (jdx = 0 ; jdx < *nPoints; jdx++)
3881
+ {
3882
+ // add points to a point array for drawing the polygon
3883
+ x = (double *) ptr;
3884
+ ptr += sizeof (double );
3885
+ y = (double *) ptr;
3886
+ ptr += sizeof (double );
3887
+ if (hasZValue)
3888
+ {
3889
+ ptr += sizeof (double );
3890
+ }
3891
+ sequence->add (GEOS_GEOM::Coordinate (*x,*y));
3892
+ }
3893
+ GEOS_GEOM::LinearRing* ring=geosGeometryFactory->createLinearRing (sequence);
3894
+ if (idx==0 )
3895
+ {
3896
+ outer=ring;
3897
+ }
3898
+ else
3899
+ {
3900
+ inner->push_back (ring);
3901
+ }
3902
+ }
3903
+
3904
+ polygons->push_back (geosGeometryFactory->createPolygon (outer,inner));
3905
+ }
3906
+ mGeos = geosGeometryFactory->createMultiPolygon (polygons);
3907
+ mDirtyGeos = FALSE ;
3908
+ break ;
3909
+ }
3910
+
3911
+ default :
4007
3912
return FALSE ;
4008
3913
}
3914
+ }
3915
+ CATCH_GEOS (FALSE )
3916
+
4009
3917
return TRUE ;
4010
3918
}
4011
3919
@@ -5111,21 +5019,31 @@ double QgsGeometry::distance(QgsGeometry& geom)
5111
5019
geom.exportWkbToGeos ();
5112
5020
}
5113
5021
5114
- return mGeos ->distance (geom.mGeos );
5022
+ try
5023
+ {
5024
+ return mGeos ->distance (geom.mGeos );
5025
+ }
5026
+ CATCH_GEOS (-1.0 )
5115
5027
}
5116
5028
5117
5029
5118
5030
QgsGeometry* QgsGeometry::buffer (double distance, int segments)
5119
5031
{
5120
5032
if (mGeos == NULL )
5121
- {
5122
- exportWkbToGeos ();
5123
- }
5033
+ {
5034
+ exportWkbToGeos ();
5035
+ }
5124
5036
if (!mGeos )
5125
- {
5126
- return 0 ;
5127
- }
5128
- GEOS_GEOM::Geometry* geos = mGeos ->buffer (distance, segments);
5037
+ {
5038
+ return 0 ;
5039
+ }
5040
+ GEOS_GEOM::Geometry* geos;
5041
+ try
5042
+ {
5043
+ geos = mGeos ->buffer (distance, segments);
5044
+ }
5045
+ CATCH_GEOS (0 )
5046
+
5129
5047
QgsGeometry* g = new QgsGeometry;
5130
5048
g->setGeos (geos);
5131
5049
return g;
@@ -5134,14 +5052,21 @@ QgsGeometry* QgsGeometry::buffer(double distance, int segments)
5134
5052
QgsGeometry* QgsGeometry::convexHull ()
5135
5053
{
5136
5054
if (mGeos == NULL )
5137
- {
5138
- exportWkbToGeos ();
5139
- }
5055
+ {
5056
+ exportWkbToGeos ();
5057
+ }
5140
5058
if (!mGeos )
5141
- {
5142
- return 0 ;
5143
- }
5144
- GEOS_GEOM::Geometry* geos = mGeos ->convexHull ();
5059
+ {
5060
+ return 0 ;
5061
+ }
5062
+
5063
+ GEOS_GEOM::Geometry* geos;
5064
+ try
5065
+ {
5066
+ geos = mGeos ->convexHull ();
5067
+ }
5068
+ CATCH_GEOS (0 )
5069
+
5145
5070
QgsGeometry* g = new QgsGeometry;
5146
5071
g->setGeos (geos);
5147
5072
return g;
@@ -5150,22 +5075,29 @@ QgsGeometry* QgsGeometry::convexHull()
5150
5075
QgsGeometry* QgsGeometry::intersection (QgsGeometry* geometry)
5151
5076
{
5152
5077
if (geometry == NULL )
5153
- {
5154
- return NULL ;
5155
- }
5078
+ {
5079
+ return NULL ;
5080
+ }
5156
5081
if (mGeos == NULL )
5157
- {
5158
- exportWkbToGeos ();
5159
- }
5082
+ {
5083
+ exportWkbToGeos ();
5084
+ }
5160
5085
if (geometry->mGeos == NULL )
5161
- {
5162
- geometry->exportWkbToGeos ();
5163
- }
5086
+ {
5087
+ geometry->exportWkbToGeos ();
5088
+ }
5164
5089
if (!mGeos || !geometry->mGeos )
5165
- {
5166
- return 0 ;
5167
- }
5168
- GEOS_GEOM::Geometry* geos = mGeos ->intersection (geometry->mGeos );
5090
+ {
5091
+ return 0 ;
5092
+ }
5093
+
5094
+ GEOS_GEOM::Geometry* geos;
5095
+ try
5096
+ {
5097
+ geos = mGeos ->intersection (geometry->mGeos );
5098
+ }
5099
+ CATCH_GEOS (0 )
5100
+
5169
5101
QgsGeometry* g = new QgsGeometry;
5170
5102
g->setGeos (geos);
5171
5103
return g;
@@ -5174,36 +5106,28 @@ QgsGeometry* QgsGeometry::intersection(QgsGeometry* geometry)
5174
5106
QgsGeometry* QgsGeometry::Union (QgsGeometry* geometry)
5175
5107
{
5176
5108
if (geometry == NULL )
5177
- {
5178
- return NULL ;
5179
- }
5109
+ {
5110
+ return NULL ;
5111
+ }
5180
5112
if (mGeos == NULL )
5181
- {
5182
- exportWkbToGeos ();
5183
- }
5113
+ {
5114
+ exportWkbToGeos ();
5115
+ }
5184
5116
if (geometry->mGeos == NULL )
5185
- {
5186
- geometry->exportWkbToGeos ();
5187
- }
5117
+ {
5118
+ geometry->exportWkbToGeos ();
5119
+ }
5188
5120
if (!mGeos || !geometry->mGeos )
5189
- {
5190
- return 0 ;
5191
- }
5121
+ {
5122
+ return 0 ;
5123
+ }
5192
5124
GEOS_GEOM::Geometry* geos = 0 ;
5193
5125
try
5194
- {
5195
- geos = mGeos ->Union (geometry->mGeos );
5196
- }
5197
- catch (GEOS_EXCEPTION e)
5198
- {
5199
- #if GEOS_VERSION_MAJOR < 3
5200
- delete e;
5201
- #else
5202
- UNUSED (e);
5203
- #endif
5204
- // return this geometry if union not possible
5205
- return new QgsGeometry (*this );
5206
- }
5126
+ {
5127
+ geos = mGeos ->Union (geometry->mGeos );
5128
+ }
5129
+ CATCH_GEOS ( new QgsGeometry (*this ) ) // return this geometry if union not possible
5130
+
5207
5131
QgsGeometry* g = new QgsGeometry;
5208
5132
g->setGeos (geos);
5209
5133
return g;
@@ -5212,22 +5136,28 @@ QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
5212
5136
QgsGeometry* QgsGeometry::difference (QgsGeometry* geometry)
5213
5137
{
5214
5138
if (geometry == NULL )
5215
- {
5216
- return NULL ;
5217
- }
5139
+ {
5140
+ return NULL ;
5141
+ }
5218
5142
if (mGeos == NULL )
5219
- {
5220
- exportWkbToGeos ();
5221
- }
5143
+ {
5144
+ exportWkbToGeos ();
5145
+ }
5222
5146
if (geometry->mGeos == NULL )
5223
- {
5224
- geometry->exportWkbToGeos ();
5225
- }
5147
+ {
5148
+ geometry->exportWkbToGeos ();
5149
+ }
5226
5150
if (!mGeos || !geometry->mGeos )
5227
- {
5228
- return 0 ;
5229
- }
5230
- GEOS_GEOM::Geometry* geos = mGeos ->difference (geometry->mGeos );
5151
+ {
5152
+ return 0 ;
5153
+ }
5154
+ GEOS_GEOM::Geometry* geos;
5155
+ try
5156
+ {
5157
+ geos = mGeos ->difference (geometry->mGeos );
5158
+ }
5159
+ CATCH_GEOS (0 )
5160
+
5231
5161
QgsGeometry* g = new QgsGeometry;
5232
5162
g->setGeos (geos);
5233
5163
return g;
@@ -5236,22 +5166,29 @@ QgsGeometry* QgsGeometry::difference(QgsGeometry* geometry)
5236
5166
QgsGeometry* QgsGeometry::symDifference (QgsGeometry* geometry)
5237
5167
{
5238
5168
if (geometry == NULL )
5239
- {
5240
- return NULL ;
5241
- }
5169
+ {
5170
+ return NULL ;
5171
+ }
5242
5172
if (mGeos == NULL )
5243
- {
5244
- exportWkbToGeos ();
5245
- }
5173
+ {
5174
+ exportWkbToGeos ();
5175
+ }
5246
5176
if (geometry->mGeos == NULL )
5247
- {
5248
- geometry->exportWkbToGeos ();
5249
- }
5177
+ {
5178
+ geometry->exportWkbToGeos ();
5179
+ }
5250
5180
if (!mGeos || !geometry->mGeos )
5251
- {
5252
- return 0 ;
5253
- }
5254
- GEOS_GEOM::Geometry* geos = mGeos ->symDifference (geometry->mGeos );
5181
+ {
5182
+ return 0 ;
5183
+ }
5184
+
5185
+ GEOS_GEOM::Geometry* geos;
5186
+ try
5187
+ {
5188
+ geos = mGeos ->symDifference (geometry->mGeos );
5189
+ }
5190
+ CATCH_GEOS (0 )
5191
+
5255
5192
QgsGeometry* g = new QgsGeometry;
5256
5193
g->setGeos (geos);
5257
5194
return g;
0 commit comments