14
14
***************************************************************************/
15
15
/* $Id$ */
16
16
17
- #include < math.h >
17
+ #include < cmath >
18
18
#include < sqlite3.h>
19
- #include < qdir.h >
20
- #include < qsettings.h >
19
+ #include < QDir >
20
+ #include < QSettings >
21
21
22
22
#include " qgis.h"
23
23
#include " qgspoint.h"
27
27
#include " qgsgeometry.h"
28
28
#include " qgsdistancearea.h"
29
29
#include " qgsapplication.h"
30
+ #include " qgslogger.h"
30
31
31
32
#define DEG2RAD (x ) ((x)*M_PI/180 )
32
33
@@ -264,24 +265,41 @@ double QgsDistanceArea::measureLine(const std::vector<QgsPoint>& points)
264
265
if (points.size () < 2 )
265
266
return 0 ;
266
267
267
- double total = 0 ;
268
- QgsPoint p1, p2;
269
- p1 = mCoordTransform ->transform (points[0 ]);
270
-
271
- for (int i = 1 ; i < points.size (); i++)
268
+ try
272
269
{
273
- p2 = mCoordTransform ->transform (points[i]);
274
- total = computeDistanceBearing (p1,p2);
275
- p1 = p2;
270
+ double total = 0 ;
271
+ QgsPoint p1, p2;
272
+ p1 = mCoordTransform ->transform (points[0 ]);
273
+
274
+ for (int i = 1 ; i < points.size (); i++)
275
+ {
276
+ p2 = mCoordTransform ->transform (points[i]);
277
+ total = computeDistanceBearing (p1,p2);
278
+ p1 = p2;
279
+ }
280
+ return total;
276
281
}
277
- return total;
282
+ catch (QgsCsException &cse)
283
+ {
284
+ QgsLogger::warning (QObject::tr (" Caught a coordinate system exception while trying to transform a point. Unable to calculate line length." ));
285
+ return 0.0 ;
286
+ }
287
+
278
288
}
279
289
280
290
double QgsDistanceArea::measureLine (const QgsPoint& p1, const QgsPoint& p2)
281
291
{
282
- QgsPoint pp1 = mCoordTransform ->transform (p1);
283
- QgsPoint pp2 = mCoordTransform ->transform (p2);
284
- return computeDistanceBearing (pp1, pp2);
292
+ try
293
+ {
294
+ QgsPoint pp1 = mCoordTransform ->transform (p1);
295
+ QgsPoint pp2 = mCoordTransform ->transform (p2);
296
+ return computeDistanceBearing (pp1, pp2);
297
+ }
298
+ catch (QgsCsException &cse)
299
+ {
300
+ QgsLogger::warning (QObject::tr (" Caught a coordinate system exception while trying to transform a point. Unable to calculate line length." ));
301
+ return 0.0 ;
302
+ }
285
303
}
286
304
287
305
@@ -300,46 +318,61 @@ unsigned char* QgsDistanceArea::measurePolygon(unsigned char* feature, double* a
300
318
double x,y, areaTmp;
301
319
*area = 0 ;
302
320
303
- for ( unsigned int idx = 0 ; idx < numRings; idx++)
321
+ try
304
322
{
305
- int nPoints = *((int *)ptr);
306
- points.resize (nPoints);
307
- ptr += 4 ;
308
-
309
- // Extract the points from the WKB and store in a pair of
310
- // vectors.
311
- for (unsigned int jdx = 0 ; jdx < nPoints; jdx++)
323
+ for (unsigned int idx = 0 ; idx < numRings; idx++)
312
324
{
313
- x = *((double *) ptr);
314
- ptr += sizeof (double );
315
- y = *((double *) ptr);
316
- ptr += sizeof (double );
317
-
318
- points[jdx] = mCoordTransform ->transform (QgsPoint (x,y));
319
- }
325
+ int nPoints = *((int *)ptr);
326
+ points.resize (nPoints);
327
+ ptr += 4 ;
320
328
321
- if (points.size () > 2 )
322
- {
323
- areaTmp = computePolygonArea (points);
324
- if (idx == 0 )
325
- *area += areaTmp; // exterior ring
326
- else
327
- *area -= areaTmp; // interior rings
329
+ // Extract the points from the WKB and store in a pair of
330
+ // vectors.
331
+ for (unsigned int jdx = 0 ; jdx < nPoints; jdx++)
332
+ {
333
+ x = *((double *) ptr);
334
+ ptr += sizeof (double );
335
+ y = *((double *) ptr);
336
+ ptr += sizeof (double );
337
+
338
+ points[jdx] = mCoordTransform ->transform (QgsPoint (x,y));
339
+ }
340
+
341
+ if (points.size () > 2 )
342
+ {
343
+ areaTmp = computePolygonArea (points);
344
+ if (idx == 0 )
345
+ *area += areaTmp; // exterior ring
346
+ else
347
+ *area -= areaTmp; // interior rings
348
+ }
328
349
}
329
350
}
351
+ catch (QgsCsException &cse)
352
+ {
353
+ QgsLogger::warning (QObject::tr (" Caught a coordinate system exception while trying to transform a point. Unable to calculate polygon area." ));
354
+ }
330
355
331
356
return ptr;
332
357
}
333
358
334
359
335
360
double QgsDistanceArea::measurePolygon (const std::vector<QgsPoint>& points)
336
361
{
337
- std::vector<QgsPoint> pts (points.size ());
338
- for (std::vector<QgsPoint>::size_type i = 0 ; i < points.size (); i++)
362
+ try
363
+ {
364
+ std::vector<QgsPoint> pts (points.size ());
365
+ for (std::vector<QgsPoint>::size_type i = 0 ; i < points.size (); i++)
366
+ {
367
+ pts[i] = mCoordTransform ->transform (points[i]);
368
+ }
369
+ return computePolygonArea (pts);
370
+ }
371
+ catch (QgsCsException &cse)
339
372
{
340
- pts[i] = mCoordTransform ->transform (points[i]);
373
+ QgsLogger::warning (QObject::tr (" Caught a coordinate system exception while trying to transform a point. Unable to calculate polygon area." ));
374
+ return 0.0 ;
341
375
}
342
- return computePolygonArea (pts);
343
376
}
344
377
345
378
0 commit comments