Skip to content

Commit 792f21d

Browse files
author
mhugent
committedFeb 20, 2008
Modified geos exception catching. It seems that geos2 throws exceptions as pointers and geos3 as objects
git-svn-id: http://svn.osgeo.org/qgis/trunk@8171 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4674f43 commit 792f21d

File tree

1 file changed

+86
-30
lines changed

1 file changed

+86
-30
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 86 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ email : morb at ozemail dot com dot au
3434
#define GEOS_UTIL geos
3535
#define GEOS_SIZE_T int
3636
#define COORD_SEQ_FACTORY DefaultCoordinateSequenceFactory
37+
#define GEOS_EXCEPTION GEOS_UTIL::GEOSException*
3738
#else
3839
#include <geos/geom/CoordinateArraySequence.h>
3940
#include <geos/geom/CoordinateArraySequenceFactory.h>
@@ -54,6 +55,7 @@ email : morb at ozemail dot com dot au
5455
#define GEOS_UTIL geos::util
5556
#define GEOS_SIZE_T size_t
5657
#define COORD_SEQ_FACTORY CoordinateArraySequenceFactory
58+
#define GEOS_EXCEPTION GEOS_UTIL::GEOSException&
5759
#endif
5860

5961
// Set up static GEOS geometry factory
@@ -144,9 +146,12 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
144146
{
145147
geom = geosGeometryFactory->createPoint(coord);
146148
}
147-
catch(GEOS_UTIL::GEOSException* e)
149+
catch(GEOS_EXCEPTION e)
148150
{
149-
delete e; return 0;
151+
#if GEOS_VERSION_MAJOR < 3
152+
delete e;
153+
#endif
154+
return 0;
150155
}
151156
QgsGeometry* g = new QgsGeometry;
152157
g->setGeos(geom);
@@ -166,9 +171,12 @@ QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
166171
{
167172
(*pointVector)[i] = geosGeometryFactory->createPoint(currentCoord);
168173
}
169-
catch(GEOS_UTIL::GEOSException* e)
174+
catch(GEOS_EXCEPTION e)
170175
{
171-
delete e; delete pointVector; return 0;
176+
#if GEOS_VERSION_MAJOR < 3
177+
delete e;
178+
#endif
179+
delete pointVector; return 0;
172180
}
173181
}
174182

@@ -177,9 +185,12 @@ QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
177185
{
178186
geom = geosGeometryFactory->createMultiPoint(pointVector);
179187
}
180-
catch(GEOS_UTIL::GEOSException* e)
188+
catch(GEOS_EXCEPTION e)
181189
{
182-
delete e; return 0;
190+
#if GEOS_VERSION_MAJOR < 3
191+
delete e;
192+
#endif
193+
return 0;
183194
}
184195

185196
QgsGeometry* g = new QgsGeometry;
@@ -205,9 +216,12 @@ QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
205216
{
206217
geom = geosGeometryFactory->createLineString(seq);
207218
}
208-
catch(GEOS_UTIL::GEOSException* e)
219+
catch(GEOS_EXCEPTION e)
209220
{
210-
delete e; delete seq;
221+
#if GEOS_VERSION_MAJOR < 3
222+
delete e;
223+
#endif
224+
delete seq;
211225
return 0;
212226
}
213227
QgsGeometry* g = new QgsGeometry;
@@ -233,9 +247,12 @@ QgsGeometry* QgsGeometry::fromMultiPolyline(const QgsMultiPolyline& multiline)
233247
{
234248
currentLineString = geosGeometryFactory->createLineString(seq);
235249
}
236-
catch(GEOS_UTIL::GEOSException* e)
250+
catch(GEOS_EXCEPTION e)
237251
{
238-
delete lineVector; delete seq; delete e;
252+
#if GEOS_VERSION_MAJOR < 3
253+
delete e;
254+
#endif
255+
delete lineVector; delete seq;
239256
return 0;
240257
}
241258
(*lineVector)[i] = currentLineString;
@@ -246,9 +263,12 @@ QgsGeometry* QgsGeometry::fromMultiPolyline(const QgsMultiPolyline& multiline)
246263
{
247264
geom = geosGeometryFactory->createMultiLineString(lineVector);
248265
}
249-
catch(GEOS_UTIL::GEOSException* e)
266+
catch(GEOS_EXCEPTION e)
250267
{
251-
delete e; return 0;
268+
#if GEOS_VERSION_MAJOR < 3
269+
delete e;
270+
#endif
271+
return 0;
252272
}
253273
QgsGeometry* g = new QgsGeometry;
254274
g->setGeos(geom);
@@ -280,9 +300,12 @@ static GEOS_GEOM::LinearRing* _createGeosLinearRing(const QgsPolyline& ring)
280300
{
281301
linRing = geosGeometryFactory->createLinearRing(seq);
282302
}
283-
catch(GEOS_UTIL::GEOSException* e)
303+
catch(GEOS_EXCEPTION e)
284304
{
285-
delete e; return 0;
305+
#if GEOS_VERSION_MAJOR < 3
306+
delete e;
307+
#endif
308+
return 0;
286309
}
287310

288311
return linRing;
@@ -311,9 +334,12 @@ QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
311334
{
312335
geom = geosGeometryFactory->createPolygon(outerRing, holes);
313336
}
314-
catch(GEOS_UTIL::GEOSException* e)
337+
catch(GEOS_EXCEPTION e)
315338
{
316-
delete e; return 0;
339+
#if GEOS_VERSION_MAJOR < 3
340+
delete e;
341+
#endif
342+
return 0;
317343
}
318344
QgsGeometry* g = new QgsGeometry;
319345
g->setGeos(geom);
@@ -344,9 +370,12 @@ QgsGeometry* QgsGeometry::fromMultiPolygon(const QgsMultiPolygon& multipoly)
344370
{
345371
currentPolygon = geosGeometryFactory->createPolygon(currentOuterRing, currentHoles);
346372
}
347-
catch(GEOS_UTIL::GEOSException* e)
373+
catch(GEOS_EXCEPTION e)
348374
{
349-
delete e; delete polygons; return 0;
375+
#if GEOS_VERSION_MAJOR < 3
376+
delete e;
377+
#endif
378+
delete polygons; return 0;
350379
}
351380
(*polygons)[i] = currentPolygon;
352381
}
@@ -356,9 +385,12 @@ QgsGeometry* QgsGeometry::fromMultiPolygon(const QgsMultiPolygon& multipoly)
356385
{
357386
geom = geosGeometryFactory->createMultiPolygon(polygons);
358387
}
359-
catch(GEOS_UTIL::GEOSException* e)
388+
catch(GEOS_EXCEPTION e)
360389
{
361-
delete e; return 0;
390+
#if GEOS_VERSION_MAJOR < 3
391+
delete e;
392+
#endif
393+
return 0;
362394
}
363395
QgsGeometry* g = new QgsGeometry;
364396
g->setGeos(geom);
@@ -2553,10 +2585,12 @@ int QgsGeometry::addRing(const QList<QgsPoint>& ring)
25532585
{
25542586
newRing = geosGeometryFactory->createLinearRing(newSequence);
25552587
}
2556-
catch(GEOS_UTIL::IllegalArgumentException* e)
2588+
catch(GEOS_EXCEPTION e)
25572589
{
2558-
delete newSequence;
2590+
#if GEOS_VERSION_MAJOR < 3
25592591
delete e;
2592+
#endif
2593+
delete newSequence;
25602594
return 3;
25612595
}
25622596
std::vector<GEOS_GEOM::Geometry*> dummyVector;
@@ -2743,9 +2777,11 @@ int QgsGeometry::addIsland(const QList<QgsPoint>& ring)
27432777
{
27442778
newRing = geosGeometryFactory->createLinearRing(newSequence);
27452779
}
2746-
catch(GEOS_UTIL::IllegalArgumentException* e)
2780+
catch(GEOS_EXCEPTION e)
27472781
{
2782+
#if GEOS_VERSION_MAJOR < 3
27482783
delete e;
2784+
#endif
27492785
delete newSequence;
27502786
return 2;
27512787
}
@@ -2982,9 +3018,12 @@ int QgsGeometry::splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeomet
29823018
return 1;
29833019
}
29843020
}
2985-
catch(GEOS_UTIL::GEOSException* e)
3021+
catch(GEOS_EXCEPTION e)
29863022
{
2987-
delete e; return 2;
3023+
#if GEOS_VERSION_MAJOR < 3
3024+
delete e;
3025+
#endif
3026+
return 2;
29883027
}
29893028
return returnCode;
29903029
}
@@ -3035,9 +3074,11 @@ int QgsGeometry::makeDifference(QgsGeometry* other)
30353074
return 0; //nothing to do
30363075
}
30373076
}
3038-
catch(GEOS_UTIL::GEOSException* e)
3077+
catch(GEOS_EXCEPTION e)
30393078
{
3079+
#if GEOS_VERSION_MAJOR < 3
30403080
delete e;
3081+
#endif
30413082
return 5;
30423083
}
30433084

@@ -3355,10 +3396,11 @@ bool QgsGeometry::intersects(QgsGeometry* geometry)
33553396

33563397
return mGeos->intersects(geometry->mGeos);
33573398
}
3358-
catch (GEOS_UTIL::GEOSException &e)
3399+
catch (GEOS_EXCEPTION e)
33593400
{
33603401
#if GEOS_VERSION_MAJOR < 3
3361-
QString error = e.toString().c_str();
3402+
QString error = e->toString().c_str();
3403+
delete e;
33623404
#else
33633405
QString error = e.what();
33643406
#endif
@@ -3927,9 +3969,11 @@ bool QgsGeometry::exportWkbToGeos()
39273969
return FALSE;
39283970
}
39293971
}
3930-
catch(GEOS_UTIL::GEOSException* e)
3972+
catch(GEOS_EXCEPTION e)
39313973
{
3974+
#if GEOS_VERSION_MAJOR < 3
39323975
delete e;
3976+
#endif
39333977
return FALSE;
39343978
}
39353979
return TRUE;
@@ -5115,7 +5159,19 @@ QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
51155159
{
51165160
return 0;
51175161
}
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+
}
51195175
QgsGeometry* g = new QgsGeometry;
51205176
g->setGeos(geos);
51215177
return g;

0 commit comments

Comments
 (0)
Please sign in to comment.