@@ -34,6 +34,7 @@ email : morb at ozemail dot com dot au
34
34
#define GEOS_UTIL geos
35
35
#define GEOS_SIZE_T int
36
36
#define COORD_SEQ_FACTORY DefaultCoordinateSequenceFactory
37
+ #define GEOS_EXCEPTION GEOS_UTIL::GEOSException*
37
38
#else
38
39
#include < geos/geom/CoordinateArraySequence.h>
39
40
#include < geos/geom/CoordinateArraySequenceFactory.h>
@@ -54,6 +55,7 @@ email : morb at ozemail dot com dot au
54
55
#define GEOS_UTIL geos::util
55
56
#define GEOS_SIZE_T size_t
56
57
#define COORD_SEQ_FACTORY CoordinateArraySequenceFactory
58
+ #define GEOS_EXCEPTION GEOS_UTIL::GEOSException&
57
59
#endif
58
60
59
61
// Set up static GEOS geometry factory
@@ -144,9 +146,12 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
144
146
{
145
147
geom = geosGeometryFactory->createPoint (coord);
146
148
}
147
- catch (GEOS_UTIL::GEOSException* e)
149
+ catch (GEOS_EXCEPTION e)
148
150
{
149
- delete e; return 0 ;
151
+ #if GEOS_VERSION_MAJOR < 3
152
+ delete e;
153
+ #endif
154
+ return 0 ;
150
155
}
151
156
QgsGeometry* g = new QgsGeometry;
152
157
g->setGeos (geom);
@@ -166,9 +171,12 @@ QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
166
171
{
167
172
(*pointVector)[i] = geosGeometryFactory->createPoint (currentCoord);
168
173
}
169
- catch (GEOS_UTIL::GEOSException* e)
174
+ catch (GEOS_EXCEPTION e)
170
175
{
171
- delete e; delete pointVector; return 0 ;
176
+ #if GEOS_VERSION_MAJOR < 3
177
+ delete e;
178
+ #endif
179
+ delete pointVector; return 0 ;
172
180
}
173
181
}
174
182
@@ -177,9 +185,12 @@ QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
177
185
{
178
186
geom = geosGeometryFactory->createMultiPoint (pointVector);
179
187
}
180
- catch (GEOS_UTIL::GEOSException* e)
188
+ catch (GEOS_EXCEPTION e)
181
189
{
182
- delete e; return 0 ;
190
+ #if GEOS_VERSION_MAJOR < 3
191
+ delete e;
192
+ #endif
193
+ return 0 ;
183
194
}
184
195
185
196
QgsGeometry* g = new QgsGeometry;
@@ -205,9 +216,12 @@ QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
205
216
{
206
217
geom = geosGeometryFactory->createLineString (seq);
207
218
}
208
- catch (GEOS_UTIL::GEOSException* e)
219
+ catch (GEOS_EXCEPTION e)
209
220
{
210
- delete e; delete seq;
221
+ #if GEOS_VERSION_MAJOR < 3
222
+ delete e;
223
+ #endif
224
+ delete seq;
211
225
return 0 ;
212
226
}
213
227
QgsGeometry* g = new QgsGeometry;
@@ -233,9 +247,12 @@ QgsGeometry* QgsGeometry::fromMultiPolyline(const QgsMultiPolyline& multiline)
233
247
{
234
248
currentLineString = geosGeometryFactory->createLineString (seq);
235
249
}
236
- catch (GEOS_UTIL::GEOSException* e)
250
+ catch (GEOS_EXCEPTION e)
237
251
{
238
- delete lineVector; delete seq; delete e;
252
+ #if GEOS_VERSION_MAJOR < 3
253
+ delete e;
254
+ #endif
255
+ delete lineVector; delete seq;
239
256
return 0 ;
240
257
}
241
258
(*lineVector)[i] = currentLineString;
@@ -246,9 +263,12 @@ QgsGeometry* QgsGeometry::fromMultiPolyline(const QgsMultiPolyline& multiline)
246
263
{
247
264
geom = geosGeometryFactory->createMultiLineString (lineVector);
248
265
}
249
- catch (GEOS_UTIL::GEOSException* e)
266
+ catch (GEOS_EXCEPTION e)
250
267
{
251
- delete e; return 0 ;
268
+ #if GEOS_VERSION_MAJOR < 3
269
+ delete e;
270
+ #endif
271
+ return 0 ;
252
272
}
253
273
QgsGeometry* g = new QgsGeometry;
254
274
g->setGeos (geom);
@@ -280,9 +300,12 @@ static GEOS_GEOM::LinearRing* _createGeosLinearRing(const QgsPolyline& ring)
280
300
{
281
301
linRing = geosGeometryFactory->createLinearRing (seq);
282
302
}
283
- catch (GEOS_UTIL::GEOSException* e)
303
+ catch (GEOS_EXCEPTION e)
284
304
{
285
- delete e; return 0 ;
305
+ #if GEOS_VERSION_MAJOR < 3
306
+ delete e;
307
+ #endif
308
+ return 0 ;
286
309
}
287
310
288
311
return linRing;
@@ -311,9 +334,12 @@ QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
311
334
{
312
335
geom = geosGeometryFactory->createPolygon (outerRing, holes);
313
336
}
314
- catch (GEOS_UTIL::GEOSException* e)
337
+ catch (GEOS_EXCEPTION e)
315
338
{
316
- delete e; return 0 ;
339
+ #if GEOS_VERSION_MAJOR < 3
340
+ delete e;
341
+ #endif
342
+ return 0 ;
317
343
}
318
344
QgsGeometry* g = new QgsGeometry;
319
345
g->setGeos (geom);
@@ -344,9 +370,12 @@ QgsGeometry* QgsGeometry::fromMultiPolygon(const QgsMultiPolygon& multipoly)
344
370
{
345
371
currentPolygon = geosGeometryFactory->createPolygon (currentOuterRing, currentHoles);
346
372
}
347
- catch (GEOS_UTIL::GEOSException* e)
373
+ catch (GEOS_EXCEPTION e)
348
374
{
349
- delete e; delete polygons; return 0 ;
375
+ #if GEOS_VERSION_MAJOR < 3
376
+ delete e;
377
+ #endif
378
+ delete polygons; return 0 ;
350
379
}
351
380
(*polygons)[i] = currentPolygon;
352
381
}
@@ -356,9 +385,12 @@ QgsGeometry* QgsGeometry::fromMultiPolygon(const QgsMultiPolygon& multipoly)
356
385
{
357
386
geom = geosGeometryFactory->createMultiPolygon (polygons);
358
387
}
359
- catch (GEOS_UTIL::GEOSException* e)
388
+ catch (GEOS_EXCEPTION e)
360
389
{
361
- delete e; return 0 ;
390
+ #if GEOS_VERSION_MAJOR < 3
391
+ delete e;
392
+ #endif
393
+ return 0 ;
362
394
}
363
395
QgsGeometry* g = new QgsGeometry;
364
396
g->setGeos (geom);
@@ -2553,10 +2585,12 @@ int QgsGeometry::addRing(const QList<QgsPoint>& ring)
2553
2585
{
2554
2586
newRing = geosGeometryFactory->createLinearRing (newSequence);
2555
2587
}
2556
- catch (GEOS_UTIL::IllegalArgumentException* e)
2588
+ catch (GEOS_EXCEPTION e)
2557
2589
{
2558
- delete newSequence;
2590
+ # if GEOS_VERSION_MAJOR < 3
2559
2591
delete e;
2592
+ #endif
2593
+ delete newSequence;
2560
2594
return 3 ;
2561
2595
}
2562
2596
std::vector<GEOS_GEOM::Geometry*> dummyVector;
@@ -2743,9 +2777,11 @@ int QgsGeometry::addIsland(const QList<QgsPoint>& ring)
2743
2777
{
2744
2778
newRing = geosGeometryFactory->createLinearRing (newSequence);
2745
2779
}
2746
- catch (GEOS_UTIL::IllegalArgumentException* e)
2780
+ catch (GEOS_EXCEPTION e)
2747
2781
{
2782
+ #if GEOS_VERSION_MAJOR < 3
2748
2783
delete e;
2784
+ #endif
2749
2785
delete newSequence;
2750
2786
return 2 ;
2751
2787
}
@@ -2982,9 +3018,12 @@ int QgsGeometry::splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeomet
2982
3018
return 1 ;
2983
3019
}
2984
3020
}
2985
- catch (GEOS_UTIL::GEOSException* e)
3021
+ catch (GEOS_EXCEPTION e)
2986
3022
{
2987
- delete e; return 2 ;
3023
+ #if GEOS_VERSION_MAJOR < 3
3024
+ delete e;
3025
+ #endif
3026
+ return 2 ;
2988
3027
}
2989
3028
return returnCode;
2990
3029
}
@@ -3035,9 +3074,11 @@ int QgsGeometry::makeDifference(QgsGeometry* other)
3035
3074
return 0 ; // nothing to do
3036
3075
}
3037
3076
}
3038
- catch (GEOS_UTIL::GEOSException* e)
3077
+ catch (GEOS_EXCEPTION e)
3039
3078
{
3079
+ #if GEOS_VERSION_MAJOR < 3
3040
3080
delete e;
3081
+ #endif
3041
3082
return 5 ;
3042
3083
}
3043
3084
@@ -3355,10 +3396,11 @@ bool QgsGeometry::intersects(QgsGeometry* geometry)
3355
3396
3356
3397
return mGeos ->intersects (geometry->mGeos );
3357
3398
}
3358
- catch (GEOS_UTIL::GEOSException & e)
3399
+ catch (GEOS_EXCEPTION e)
3359
3400
{
3360
3401
#if GEOS_VERSION_MAJOR < 3
3361
- QString error = e.toString ().c_str ();
3402
+ QString error = e->toString ().c_str ();
3403
+ delete e;
3362
3404
#else
3363
3405
QString error = e.what ();
3364
3406
#endif
@@ -3927,9 +3969,11 @@ bool QgsGeometry::exportWkbToGeos()
3927
3969
return FALSE ;
3928
3970
}
3929
3971
}
3930
- catch (GEOS_UTIL::GEOSException* e)
3972
+ catch (GEOS_EXCEPTION e)
3931
3973
{
3974
+ #if GEOS_VERSION_MAJOR < 3
3932
3975
delete e;
3976
+ #endif
3933
3977
return FALSE ;
3934
3978
}
3935
3979
return TRUE ;
@@ -5115,7 +5159,19 @@ QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
5115
5159
{
5116
5160
return 0 ;
5117
5161
}
5118
- GEOS_GEOM::Geometry* geos = mGeos ->Union (geometry->mGeos );
5162
+ GEOS_GEOM::Geometry* geos = 0 ;
5163
+ try
5164
+ {
5165
+ geos = mGeos ->Union (geometry->mGeos );
5166
+ }
5167
+ catch (GEOS_EXCEPTION e)
5168
+ {
5169
+ #if GEOS_VERSION_MAJOR < 3
5170
+ delete e;
5171
+ #endif
5172
+ // return this geometry if union not possible
5173
+ return new QgsGeometry (*this );
5174
+ }
5119
5175
QgsGeometry* g = new QgsGeometry;
5120
5176
g->setGeos (geos);
5121
5177
return g;
0 commit comments