Skip to content

Commit 35a950d

Browse files

File tree

1 file changed

+752
-815
lines changed

1 file changed

+752
-815
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 752 additions & 815 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ email : morb at ozemail dot com dot au
3535
#define GEOS_SIZE_T int
3636
#define COORD_SEQ_FACTORY DefaultCoordinateSequenceFactory
3737
#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+
}
3847
#else
3948
#include <geos/geom/CoordinateArraySequence.h>
4049
#include <geos/geom/CoordinateArraySequenceFactory.h>
@@ -56,6 +65,13 @@ email : morb at ozemail dot com dot au
5665
#define GEOS_SIZE_T size_t
5766
#define COORD_SEQ_FACTORY CoordinateArraySequenceFactory
5867
#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+
}
5975
#endif
6076

6177
// Set up static GEOS geometry factory
@@ -77,12 +93,9 @@ mDirtyGeos(FALSE)
7793
QgsGeometry::QgsGeometry( QgsGeometry const & rhs )
7894
: mGeometry(0),
7995
mGeometrySize( rhs.mGeometrySize ),
80-
8196
mDirtyWkb( rhs.mDirtyWkb ),
82-
mDirtyGeos( rhs.mDirtyGeos )
83-
{
84-
85-
97+
mDirtyGeos( rhs.mDirtyGeos )
98+
{
8699
if ( mGeometrySize && rhs.mGeometry )
87100
{
88101
mGeometry = new unsigned char[mGeometrySize];
@@ -93,40 +106,40 @@ mDirtyGeos( rhs.mDirtyGeos )
93106
if (rhs.mGeos)
94107
{
95108
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)
96112
{
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);
107119
}
120+
}
108121
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)
109125
{
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);
120132
}
133+
}
121134
else
122-
{
123-
mGeos = rhs.mGeos->clone();
124-
}
135+
{
136+
mGeos = rhs.mGeos->clone();
137+
}
125138
}
126139
else
127140
{
128141
mGeos = 0;
129-
}
142+
}
130143
}
131144

132145
QgsGeometry* QgsGeometry::fromWkt(QString wkt)
@@ -143,18 +156,11 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
143156
GEOS_GEOM::Coordinate coord = GEOS_GEOM::Coordinate(point.x(), point.y());
144157
GEOS_GEOM::Geometry* geom = 0;
145158
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+
158164
QgsGeometry* g = new QgsGeometry;
159165
g->setGeos(geom);
160166
return g;
@@ -164,41 +170,27 @@ QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
164170
{
165171
std::vector<GEOS_GEOM::Geometry*>* pointVector = new std::vector<GEOS_GEOM::Geometry*>(multipoint.size());
166172
GEOS_GEOM::Coordinate currentCoord;
173+
std::auto_ptr< std::vector<GEOS_GEOM::Geometry*> > owner(pointVector);
167174

168175
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);
185182
}
183+
CATCH_GEOS(0)
184+
}
186185

187186
GEOS_GEOM::Geometry* geom = 0;
188187
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+
202194
QgsGeometry* g = new QgsGeometry;
203195
g->setGeos(geom);
204196
return g;
@@ -208,6 +200,7 @@ QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
208200
{
209201
const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance();
210202
GEOS_GEOM::CoordinateSequence* seq = seqFactory->create(polyline.count(), 2);
203+
std::auto_ptr< GEOS_GEOM::CoordinateSequence > owner(seq);
211204

212205
QgsPolyline::const_iterator it;
213206
int i = 0;
@@ -221,17 +214,10 @@ QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
221214
try
222215
{
223216
geom = geosGeometryFactory->createLineString(seq);
217+
owner.release();
224218
}
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+
235221
QgsGeometry* g = new QgsGeometry;
236222
g->setGeos(geom);
237223
return g;
@@ -242,46 +228,36 @@ QgsGeometry* QgsGeometry::fromMultiPolyline(const QgsMultiPolyline& multiline)
242228
const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance();
243229
std::vector<GEOS_GEOM::Geometry*>* lineVector = new std::vector<GEOS_GEOM::Geometry*>(multiline.count());
244230
GEOS_GEOM::LineString* currentLineString = 0;
245-
231+
std::auto_ptr< std::vector<GEOS_GEOM::Geometry*> > owner(lineVector);
232+
246233
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)
247240
{
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);
275242
}
276-
catch(GEOS_EXCEPTION e)
243+
try
277244
{
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();
284247
}
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+
285261
QgsGeometry* g = new QgsGeometry;
286262
g->setGeos(geom);
287263
return g;
@@ -301,40 +277,32 @@ static GEOS_GEOM::LinearRing* _createGeosLinearRing(const QgsPolyline& ring)
301277
{
302278
seq->setAt(GEOS_GEOM::Coordinate(it->x(), it->y()), i++);
303279
}
304-
280+
305281
// add the first point to close the ring if needed
306282
if (needRepeatLastPnt)
307283
seq->setAt(GEOS_GEOM::Coordinate(ring[0].x(), ring[0].y()), ring.count());
308-
284+
309285
// ring takes ownership of the sequence
310286
GEOS_GEOM::LinearRing* linRing = 0;
311287
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+
325293
return linRing;
326294
}
327295

328296
QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
329297
{
330298
if (polygon.count() == 0)
331299
return NULL;
332-
300+
333301
const QgsPolyline& ring0 = polygon[0];
334-
302+
335303
// outer ring
336304
GEOS_GEOM::LinearRing* outerRing = _createGeosLinearRing(ring0);
337-
305+
338306
// holes
339307
std::vector<GEOS_GEOM::Geometry*>* holes = new std::vector<GEOS_GEOM::Geometry*> (polygon.count()-1);
340308
for (int i = 1; i < polygon.count(); i++)
@@ -345,18 +313,11 @@ QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
345313
// new geometry takes ownership of outerRing and vector of holes
346314
GEOS_GEOM::Geometry* geom = 0;
347315
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+
360321
QgsGeometry* g = new QgsGeometry;
361322
g->setGeos(geom);
362323
return g;
@@ -365,53 +326,41 @@ QgsGeometry* QgsGeometry::fromPolygon(const QgsPolygon& polygon)
365326
QgsGeometry* QgsGeometry::fromMultiPolygon(const QgsMultiPolygon& multipoly)
366327
{
367328
if(multipoly.count() == 0)
368-
{
369-
return 0;
370-
}
329+
{
330+
return 0;
331+
}
371332

372333
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);
373335
GEOS_GEOM::Polygon* currentPolygon = 0;
374336
GEOS_GEOM::LinearRing* currentOuterRing = 0;
375337
std::vector<GEOS_GEOM::Geometry*>* currentHoles = 0;
376338

377339
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)
378344
{
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);
399350
}
351+
CATCH_GEOS(0)
352+
353+
(*polygons)[i] = currentPolygon;
354+
}
400355

401356
GEOS_GEOM::Geometry* geom = 0;
402357
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+
415364
QgsGeometry* g = new QgsGeometry;
416365
g->setGeos(geom);
417366
return g;
@@ -452,35 +401,35 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
452401
if (rhs.mGeos)
453402
{
454403
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)
455407
{
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);
466414
}
415+
}
467416
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)
468420
{
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);
479427
}
428+
}
480429
else
481-
{
482-
mGeos = rhs.mGeos->clone();
483-
}
430+
{
431+
mGeos = rhs.mGeos->clone();
432+
}
484433
}
485434
else
486435
{
@@ -534,7 +483,6 @@ void QgsGeometry::setWkbAndOwnership(unsigned char * wkb, size_t length)
534483

535484
mDirtyWkb = FALSE;
536485
mDirtyGeos = TRUE;
537-
538486
}
539487

540488
unsigned char * QgsGeometry::wkbBuffer()
@@ -563,15 +511,15 @@ QGis::WKBTYPE QgsGeometry::wkbType()
563511
{
564512
unsigned char *geom = wkbBuffer(); // ensure that wkb representation exists
565513
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+
}
571519
else
572-
{
573-
return QGis::WKBUnknown;
574-
}
520+
{
521+
return QGis::WKBUnknown;
522+
}
575523
}
576524

577525

@@ -2541,308 +2489,294 @@ int QgsGeometry::addRing(const QList<QgsPoint>& ring)
25412489
{
25422490
//bail out if this geometry is not polygon/multipolygon
25432491
if(vectorType() != QGis::Polygon)
2544-
{
2545-
return 1;
2546-
}
2492+
{
2493+
return 1;
2494+
}
25472495

25482496
//test for invalid geometries
25492497
if(ring.size() < 4)
2550-
{
2551-
return 3;
2552-
}
2498+
{
2499+
return 3;
2500+
}
25532501

25542502
//ring must be closed
25552503
if(ring.first() != ring.last())
2556-
{
2557-
return 2;
2558-
}
2559-
2504+
{
2505+
return 2;
2506+
}
2507+
25602508
//create geos geometry from wkb if not already there
25612509
if(!mGeos || mDirtyGeos)
2562-
{
2563-
exportWkbToGeos();
2564-
}
2565-
2510+
{
2511+
exportWkbToGeos();
2512+
}
2513+
25662514
//Fill GEOS Polygons of the feature into list
25672515
std::list<GEOS_GEOM::Polygon*> polygonList; //list of polygon pointers (only one for polygon geometries)
25682516
GEOS_GEOM::Polygon* thisPolygon = 0;
25692517
GEOS_GEOM::MultiPolygon* thisMultiPolygon = 0;
25702518

25712519
if(this->wkbType() == QGis::WKBPolygon)
2520+
{
2521+
thisPolygon = dynamic_cast<GEOS_GEOM::Polygon*>(mGeos);
2522+
if(!thisPolygon)
25722523
{
2573-
thisPolygon = dynamic_cast<GEOS_GEOM::Polygon*>(mGeos);
2574-
if(!thisPolygon)
2575-
{
2576-
return 1;
2577-
}
2578-
polygonList.push_back(thisPolygon);
2524+
return 1;
25792525
}
2526+
polygonList.push_back(thisPolygon);
2527+
}
25802528
else if(this->wkbType() == QGis::WKBMultiPolygon)
2529+
{
2530+
thisMultiPolygon = dynamic_cast<GEOS_GEOM::MultiPolygon*>(mGeos);
2531+
if(!thisMultiPolygon)
25812532
{
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)));
25922539
}
2540+
}
25932541

25942542
//create new ring
25952543
GEOS_GEOM::DefaultCoordinateSequence* newSequence=new GEOS_GEOM::DefaultCoordinateSequence();
2544+
std::auto_ptr< GEOS_GEOM::DefaultCoordinateSequence > owner(newSequence);
25962545
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+
26022550
//create new ring
26032551
GEOS_GEOM::LinearRing* newRing = 0;
26042552
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+
26182559
std::vector<GEOS_GEOM::Geometry*> dummyVector;
26192560

26202561
//create polygon from new ring because there is a problem with geos operations and linear rings
26212562
GEOS_GEOM::Polygon* newRingPolygon = geosGeometryFactory->createPolygon(*newRing, dummyVector);
26222563
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
26312572
std::vector<GEOS_GEOM::Geometry*>* inner = 0; //vector of inner rings. The existing rings and the new one will be added
26322573
int numberOfPolyContainingRing = 0; //for multipolygons: store index of the polygon where the ring is
26332574
bool foundPoly = false; //set to true as soon we found a polygon containing the ring
26342575

26352576
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)
26362584
{
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+
26482589
//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+
}
26742609

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+
}
26792615

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+
}
26892630

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
26922635
{
2693-
if( (*it) != newRing) //we need newRing for later polygons
2694-
{
2695-
delete *it;
2696-
}
2636+
delete *it;
26972637
}
2698-
delete inner;
2699-
delete outerRing;
2700-
delete outerRingPolygon;
2701-
2702-
++numberOfPolyContainingRing;
27032638
}
2639+
delete inner;
2640+
delete outerRing;
2641+
delete outerRingPolygon;
2642+
2643+
++numberOfPolyContainingRing;
2644+
}
27042645

27052646
delete newRingPolygon;
2706-
2647+
27072648
if(foundPoly)
2649+
{
2650+
GEOS_GEOM::Polygon* newPolygon = geosGeometryFactory->createPolygon(outerRing,inner);
2651+
if(this->wkbType() == QGis::WKBPolygon)
27082652
{
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;
27382655
}
2739-
else
2656+
else if(this->wkbType() == QGis::WKBMultiPolygon)
27402657
{
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);
27432675
}
2676+
mDirtyWkb = true;
2677+
mDirtyGeos = false;
2678+
return 0;
2679+
}
2680+
else
2681+
{
2682+
delete newRing;
2683+
return 5;
2684+
}
27442685
}
27452686

27462687
int QgsGeometry::addIsland(const QList<QgsPoint>& ring)
27472688
{
27482689
//Ring needs to have at least three points and must be closed
27492690
if(ring.size() < 4)
2750-
{
2751-
return 2;
2752-
}
2691+
{
2692+
return 2;
2693+
}
27532694

27542695
//ring must be closed
27552696
if(ring.first() != ring.last())
2756-
{
2757-
return 2;
2758-
}
2697+
{
2698+
return 2;
2699+
}
27592700

27602701
if(wkbType() == QGis::WKBPolygon || wkbType() == QGis::WKBPolygon25D)
2702+
{
2703+
if(!convertToMultiType())
27612704
{
2762-
if(!convertToMultiType())
2763-
{
2764-
return 1;
2765-
}
2705+
return 1;
27662706
}
2707+
}
27672708

27682709
//bail out if wkbtype is not multipolygon
27692710
if(wkbType() != QGis::WKBMultiPolygon && wkbType() != QGis::WKBMultiPolygon25D)
2770-
{
2771-
return 1;
2772-
}
2711+
{
2712+
return 1;
2713+
}
27732714

27742715
//create geos geometry from wkb if not already there
27752716
if(!mGeos || mDirtyGeos)
2776-
{
2777-
exportWkbToGeos();
2778-
}
2717+
{
2718+
exportWkbToGeos();
2719+
}
27792720

27802721
//this multipolygon
27812722
GEOS_GEOM::MultiPolygon* thisMultiPolygon = dynamic_cast<GEOS_GEOM::MultiPolygon*>(mGeos);
27822723
if(!thisMultiPolygon)
2783-
{
2784-
return 1;
2785-
}
2724+
{
2725+
return 1;
2726+
}
27862727

27872728
//create new polygon from ring
27882729

27892730
//coordinate sequence first
27902731
GEOS_GEOM::DefaultCoordinateSequence* newSequence=new GEOS_GEOM::DefaultCoordinateSequence();
2732+
std::auto_ptr< GEOS_GEOM::DefaultCoordinateSequence > owner(newSequence);
27912733
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+
27962738
//then linear ring
27972739
GEOS_GEOM::LinearRing* newRing = 0;
27982740
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)
28122746

28132747
//finally the polygon
28142748
std::vector<GEOS_GEOM::Geometry*> dummyVector;
28152749
GEOS_GEOM::Polygon* newPolygon = geosGeometryFactory->createPolygon(*newRing, dummyVector);
28162750
delete newRing;
28172751

28182752
if(!newPolygon || !newPolygon->isValid())
2819-
{
2820-
delete newPolygon;
2821-
return 2;
2822-
}
2753+
{
2754+
delete newPolygon;
2755+
return 2;
2756+
}
28232757

28242758
//create new multipolygon
28252759
std::vector<GEOS_GEOM::Geometry*>* newMultiPolygonVector = new std::vector<GEOS_GEOM::Geometry*>();
28262760
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))
28272766
{
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;
28422774
}
2775+
newMultiPolygonVector->push_back(polygonN->clone());
2776+
}
28432777
newMultiPolygonVector->push_back(newPolygon);
28442778
GEOS_GEOM::MultiPolygon* newMultiPolygon = geosGeometryFactory->createMultiPolygon(newMultiPolygonVector);
2845-
2779+
28462780
delete mGeos;
28472781
mGeos = newMultiPolygon;
28482782

@@ -2983,138 +2917,123 @@ int QgsGeometry::splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeomet
29832917

29842918
//return if this type is point/multipoint
29852919
if(vectorType() == QGis::Point)
2986-
{
2987-
return 1; //cannot split points
2988-
}
2920+
{
2921+
return 1; //cannot split points
2922+
}
29892923

29902924
//make sure, mGeos and mWkb are there and up-to-date
29912925
if(mDirtyWkb)
2992-
{
2993-
exportGeosToWkb();
2994-
}
2926+
{
2927+
exportGeosToWkb();
2928+
}
29952929
if(!mGeos || mDirtyGeos)
2996-
{
2997-
exportWkbToGeos();
2998-
}
2930+
{
2931+
exportWkbToGeos();
2932+
}
29992933

30002934
//make sure splitLine is valid
30012935
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)
30022952
{
2953+
delete splitLineCoords;
30032954
return 1;
30042955
}
30052956

3006-
newGeometries.clear();
2957+
if(!splitLineGeos->isValid() || !splitLineGeos->isSimple())
2958+
{
2959+
delete splitLineGeos;
2960+
return 1;
2961+
}
30072962

3008-
try
2963+
//for line/multiline: call splitLinearGeometry
2964+
if(vectorType() == QGis::Line)
30092965
{
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;
30442968
}
3045-
catch(GEOS_EXCEPTION e)
2969+
else if(vectorType() == QGis::Polygon)
30462970
{
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;
30532977
}
2978+
}
2979+
CATCH_GEOS(2)
2980+
30542981
return returnCode;
30552982
}
30562983

30572984
int QgsGeometry::makeDifference(QgsGeometry* other)
30582985
{
30592986
//make sure geos geometry is up to date
30602987
if(!mGeos || mDirtyGeos)
3061-
{
3062-
exportWkbToGeos();
3063-
}
2988+
{
2989+
exportWkbToGeos();
2990+
}
30642991

30652992
if(!mGeos)
3066-
{
3067-
return 1;
3068-
}
2993+
{
2994+
return 1;
2995+
}
30692996

30702997
if(!mGeos->isValid())
3071-
{
3072-
return 2;
3073-
}
2998+
{
2999+
return 2;
3000+
}
30743001

30753002
if(!mGeos->isSimple())
3076-
{
3077-
return 3;
3078-
}
3003+
{
3004+
return 3;
3005+
}
30793006

30803007
//convert other geometry to geos
30813008
if(!other->mGeos || other->mDirtyGeos)
3082-
{
3083-
other->exportWkbToGeos();
3084-
}
3085-
3009+
{
3010+
other->exportWkbToGeos();
3011+
}
3012+
30863013
if(!other->mGeos)
3087-
{
3088-
return 4;
3089-
}
3014+
{
3015+
return 4;
3016+
}
30903017

30913018
//make geometry::difference
30923019
try
3020+
{
3021+
if(mGeos->intersects(other->mGeos))
30933022
{
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);
31023024
}
3103-
catch(GEOS_EXCEPTION e)
3025+
else
31043026
{
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
31113028
}
3112-
3029+
}
3030+
CATCH_GEOS(5)
3031+
31133032
if(!mGeos)
3114-
{
3115-
mDirtyGeos = true;
3116-
return 6;
3117-
}
3033+
{
3034+
mDirtyGeos = true;
3035+
return 6;
3036+
}
31183037

31193038
//set wkb dirty to true
31203039
mDirtyWkb = true;
@@ -3424,17 +3343,7 @@ bool QgsGeometry::intersects(QgsGeometry* geometry)
34243343

34253344
return mGeos->intersects(geometry->mGeos);
34263345
}
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)
34383347
}
34393348

34403349

@@ -3449,10 +3358,15 @@ bool QgsGeometry::contains(QgsPoint* p)
34493358
}
34503359

34513360
GEOS_GEOM::Point* geosPoint = geosGeometryFactory->createPoint(GEOS_GEOM::Coordinate(p->x(), p->y()));
3361+
std::auto_ptr< GEOS_GEOM::Point > owner(geosPoint);
34523362

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)
34563370

34573371
return returnval;
34583372
}
@@ -3779,233 +3693,227 @@ bool QgsGeometry::exportWkbToGeos()
37793693
//wkbtype = (mGeometry[0] == 1) ? mGeometry[1] : mGeometry[4];
37803694
memcpy(&wkbtype, &(mGeometry[1]), sizeof(int));
37813695

3782-
try{ //try-catch block for geos exceptions
3696+
try
3697+
{
37833698
switch(wkbtype)
3699+
{
3700+
case QGis::WKBPoint25D:
3701+
case QGis::WKBPoint:
37843702
{
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));
37903705

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+
}
38483797

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;
39043819
ptr += 4;
39053820
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+
}
39183833
GEOS_GEOM::LinearRing* ring=geosGeometryFactory->createLinearRing(sequence);
39193834
if(idx==0)
3920-
{
3921-
outer=ring;
3922-
}
3835+
{
3836+
outer=ring;
3837+
}
39233838
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;
39983846
}
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:
40073912
return FALSE;
40083913
}
3914+
}
3915+
CATCH_GEOS(FALSE)
3916+
40093917
return TRUE;
40103918
}
40113919

@@ -5111,21 +5019,31 @@ double QgsGeometry::distance(QgsGeometry& geom)
51115019
geom.exportWkbToGeos();
51125020
}
51135021

5114-
return mGeos->distance(geom.mGeos);
5022+
try
5023+
{
5024+
return mGeos->distance(geom.mGeos);
5025+
}
5026+
CATCH_GEOS(-1.0)
51155027
}
51165028

51175029

51185030
QgsGeometry* QgsGeometry::buffer(double distance, int segments)
51195031
{
51205032
if (mGeos == NULL)
5121-
{
5122-
exportWkbToGeos();
5123-
}
5033+
{
5034+
exportWkbToGeos();
5035+
}
51245036
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+
51295047
QgsGeometry* g = new QgsGeometry;
51305048
g->setGeos(geos);
51315049
return g;
@@ -5134,14 +5052,21 @@ QgsGeometry* QgsGeometry::buffer(double distance, int segments)
51345052
QgsGeometry* QgsGeometry::convexHull()
51355053
{
51365054
if (mGeos == NULL)
5137-
{
5138-
exportWkbToGeos();
5139-
}
5055+
{
5056+
exportWkbToGeos();
5057+
}
51405058
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+
51455070
QgsGeometry* g = new QgsGeometry;
51465071
g->setGeos(geos);
51475072
return g;
@@ -5150,22 +5075,29 @@ QgsGeometry* QgsGeometry::convexHull()
51505075
QgsGeometry* QgsGeometry::intersection(QgsGeometry* geometry)
51515076
{
51525077
if (geometry == NULL)
5153-
{
5154-
return NULL;
5155-
}
5078+
{
5079+
return NULL;
5080+
}
51565081
if (mGeos == NULL)
5157-
{
5158-
exportWkbToGeos();
5159-
}
5082+
{
5083+
exportWkbToGeos();
5084+
}
51605085
if (geometry->mGeos == NULL)
5161-
{
5162-
geometry->exportWkbToGeos();
5163-
}
5086+
{
5087+
geometry->exportWkbToGeos();
5088+
}
51645089
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+
51695101
QgsGeometry* g = new QgsGeometry;
51705102
g->setGeos(geos);
51715103
return g;
@@ -5174,36 +5106,28 @@ QgsGeometry* QgsGeometry::intersection(QgsGeometry* geometry)
51745106
QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
51755107
{
51765108
if (geometry == NULL)
5177-
{
5178-
return NULL;
5179-
}
5109+
{
5110+
return NULL;
5111+
}
51805112
if (mGeos == NULL)
5181-
{
5182-
exportWkbToGeos();
5183-
}
5113+
{
5114+
exportWkbToGeos();
5115+
}
51845116
if (geometry->mGeos == NULL)
5185-
{
5186-
geometry->exportWkbToGeos();
5187-
}
5117+
{
5118+
geometry->exportWkbToGeos();
5119+
}
51885120
if(!mGeos || !geometry->mGeos)
5189-
{
5190-
return 0;
5191-
}
5121+
{
5122+
return 0;
5123+
}
51925124
GEOS_GEOM::Geometry* geos = 0;
51935125
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+
52075131
QgsGeometry* g = new QgsGeometry;
52085132
g->setGeos(geos);
52095133
return g;
@@ -5212,22 +5136,28 @@ QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
52125136
QgsGeometry* QgsGeometry::difference(QgsGeometry* geometry)
52135137
{
52145138
if (geometry == NULL)
5215-
{
5216-
return NULL;
5217-
}
5139+
{
5140+
return NULL;
5141+
}
52185142
if (mGeos == NULL)
5219-
{
5220-
exportWkbToGeos();
5221-
}
5143+
{
5144+
exportWkbToGeos();
5145+
}
52225146
if (geometry->mGeos == NULL)
5223-
{
5224-
geometry->exportWkbToGeos();
5225-
}
5147+
{
5148+
geometry->exportWkbToGeos();
5149+
}
52265150
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+
52315161
QgsGeometry* g = new QgsGeometry;
52325162
g->setGeos(geos);
52335163
return g;
@@ -5236,22 +5166,29 @@ QgsGeometry* QgsGeometry::difference(QgsGeometry* geometry)
52365166
QgsGeometry* QgsGeometry::symDifference(QgsGeometry* geometry)
52375167
{
52385168
if (geometry == NULL)
5239-
{
5240-
return NULL;
5241-
}
5169+
{
5170+
return NULL;
5171+
}
52425172
if (mGeos == NULL)
5243-
{
5244-
exportWkbToGeos();
5245-
}
5173+
{
5174+
exportWkbToGeos();
5175+
}
52465176
if (geometry->mGeos == NULL)
5247-
{
5248-
geometry->exportWkbToGeos();
5249-
}
5177+
{
5178+
geometry->exportWkbToGeos();
5179+
}
52505180
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+
52555192
QgsGeometry* g = new QgsGeometry;
52565193
g->setGeos(geos);
52575194
return g;

0 commit comments

Comments
 (0)
Please sign in to comment.