Skip to content

Commit e863ecc

Browse files
author
wonder
committedMar 4, 2007
Changed usage of std::vector to QList in QgsDistance area.
Added the modified functions to Python bindings. git-svn-id: http://svn.osgeo.org/qgis/trunk@6760 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1746d7d commit e863ecc

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed
 

‎python/core/qgsdistancearea.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ class QgsDistanceArea
4444
double measure(QgsGeometry* geometry);
4545

4646
//! measures line with more segments
47-
// TODO wrap double measureLine(const std::vector<QgsPoint>& points);
47+
double measureLine(const QList<QgsPoint>& points);
4848

4949
//! measures line with one segment
5050
double measureLine(const QgsPoint& p1, const QgsPoint& p2);
5151

5252
//! measures polygon area
53-
// TODO wrap double measurePolygon(const std::vector<QgsPoint>& points);
53+
double measurePolygon(const QList<QgsPoint>& points);
5454

5555
//! compute bearing - in radians
5656
double getBearing(const QgsPoint& p1, const QgsPoint& p2);

‎src/app/qgsmeasure.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ QgsMeasure::~QgsMeasure()
127127
void QgsMeasure::restart(void )
128128
{
129129
updateProjection();
130-
mPoints.resize(0);
130+
mPoints.clear();
131131
// Set one cell row where to update current distance
132132
// If measuring area, the table doesn't get shown
133133
mTable->setNumRows(1);
@@ -166,7 +166,7 @@ void QgsMeasure::addPoint(QgsPoint &point)
166166
return;
167167

168168
QgsPoint pnt(point);
169-
mPoints.push_back(pnt);
169+
mPoints.append(pnt);
170170

171171
if (mMeasureArea && mPoints.size() > 2)
172172
{
@@ -219,8 +219,8 @@ void QgsMeasure::mouseMove(QgsPoint &point)
219219
// show current distance/area while moving the point
220220
// by creating a temporary copy of point array
221221
// and adding moving point at the end
222-
std::vector<QgsPoint> tmpPoints = mPoints;
223-
tmpPoints.push_back(point);
222+
QList<QgsPoint> tmpPoints = mPoints;
223+
tmpPoints.append(point);
224224
if (mMeasureArea && tmpPoints.size() > 2)
225225
{
226226
double area = mCanvas->mapRender()->distArea()->measurePolygon(tmpPoints);

‎src/app/qgsmeasure.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <QWidget>
2121
#include "qgsmaptool.h"
2222
#include "qgspoint.h"
23-
#include <vector>
2423

2524
class QgsDistanceArea;
2625
class QgsMapCanvas;
@@ -113,7 +112,7 @@ public slots:
113112
//! distance/area calculator
114113
//QgsDistanceArea* mCalc;
115114

116-
std::vector<QgsPoint> mPoints;
115+
QList<QgsPoint> mPoints;
117116

118117
double mTotal;
119118

‎src/core/qgsdistancearea.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,25 @@ unsigned char* QgsDistanceArea::measureLine(unsigned char* feature, double* area
229229
unsigned int nPoints = *((int*)ptr);
230230
ptr = feature + 9;
231231

232-
std::vector<QgsPoint> points(nPoints);
232+
QList<QgsPoint> points;
233+
double x,y;
233234

234235
QgsDebugMsg("This feature WKB has " + QString::number(nPoints) + " points");
235236
// Extract the points from the WKB format into the vector
236237
for (unsigned int i = 0; i < nPoints; ++i)
237238
{
238-
QgsPoint& p = points[i];
239-
p.setX(*((double *) ptr));
239+
x = *((double *) ptr);
240240
ptr += sizeof(double);
241-
p.setY(*((double *) ptr));
241+
y = *((double *) ptr);
242242
ptr += sizeof(double);
243+
points.append(QgsPoint(x,y));
243244
}
244245

245246
*area = measureLine(points);
246247
return ptr;
247248
}
248249

249-
double QgsDistanceArea::measureLine(const std::vector<QgsPoint>& points)
250+
double QgsDistanceArea::measureLine(const QList<QgsPoint>& points)
250251
{
251252
if (points.size() < 2)
252253
return 0;
@@ -261,16 +262,16 @@ double QgsDistanceArea::measureLine(const std::vector<QgsPoint>& points)
261262
else
262263
p1 = points[0];
263264

264-
for (std::vector<QgsPoint>::size_type i = 1; i < points.size(); i++)
265+
for (QList<QgsPoint>::const_iterator i = points.begin(); i != points.end(); ++i)
265266
{
266267
if (mProjectionsEnabled && (mEllipsoid != "NONE"))
267268
{
268-
p2 = mCoordTransform->transform(points[i]);
269+
p2 = mCoordTransform->transform(*i);
269270
total += computeDistanceBearing(p1,p2);
270271
}
271272
else
272273
{
273-
p2 = points[i];
274+
p2 = *i;
274275
total += measureLine(p1,p2);
275276
}
276277

@@ -322,7 +323,8 @@ unsigned char* QgsDistanceArea::measurePolygon(unsigned char* feature, double* a
322323
// Set pointer to the first ring
323324
unsigned char* ptr = feature + 1 + 2 * sizeof(int);
324325

325-
std::vector<QgsPoint> points;
326+
QList<QgsPoint> points;
327+
QgsPoint pnt;
326328
double x,y, areaTmp;
327329
*area = 0;
328330

@@ -331,7 +333,6 @@ unsigned char* QgsDistanceArea::measurePolygon(unsigned char* feature, double* a
331333
for (unsigned int idx = 0; idx < numRings; idx++)
332334
{
333335
int nPoints = *((int*)ptr);
334-
points.resize(nPoints);
335336
ptr += 4;
336337

337338
// Extract the points from the WKB and store in a pair of
@@ -342,12 +343,14 @@ unsigned char* QgsDistanceArea::measurePolygon(unsigned char* feature, double* a
342343
ptr += sizeof(double);
343344
y = *((double *) ptr);
344345
ptr += sizeof(double);
346+
347+
pnt = QgsPoint(x,y);
345348

346-
points[jdx] = QgsPoint(x,y);
347349
if (mProjectionsEnabled && (mEllipsoid != "NONE"))
348350
{
349-
points[jdx] = mCoordTransform->transform(points[jdx]);
351+
pnt = mCoordTransform->transform(pnt);
350352
}
353+
points.append(pnt);
351354
}
352355

353356
if (points.size() > 2)
@@ -369,17 +372,17 @@ unsigned char* QgsDistanceArea::measurePolygon(unsigned char* feature, double* a
369372
}
370373

371374

372-
double QgsDistanceArea::measurePolygon(const std::vector<QgsPoint>& points)
375+
double QgsDistanceArea::measurePolygon(const QList<QgsPoint>& points)
373376
{
374377

375378
try
376379
{
377380
if (mProjectionsEnabled && (mEllipsoid != "NONE"))
378381
{
379-
std::vector<QgsPoint> pts(points.size());
380-
for (std::vector<QgsPoint>::size_type i = 0; i < points.size(); i++)
382+
QList<QgsPoint> pts;
383+
for (QList<QgsPoint>::const_iterator i = points.begin(); i != points.end(); ++i)
381384
{
382-
pts[i] = mCoordTransform->transform(points[i]);
385+
pts.append(mCoordTransform->transform(*i));
383386
}
384387
return computePolygonArea(pts);
385388
}
@@ -540,7 +543,7 @@ void QgsDistanceArea::computeAreaInit()
540543
}
541544

542545

543-
double QgsDistanceArea::computePolygonArea(const std::vector<QgsPoint>& points)
546+
double QgsDistanceArea::computePolygonArea(const QList<QgsPoint>& points)
544547
{
545548
double x1,y1,x2,y2,dx,dy;
546549
double Qbar1, Qbar2;
@@ -595,7 +598,7 @@ double QgsDistanceArea::computePolygonArea(const std::vector<QgsPoint>& points)
595598
return area;
596599
}
597600

598-
double QgsDistanceArea::computePolygonFlatArea(const std::vector<QgsPoint>& points)
601+
double QgsDistanceArea::computePolygonFlatArea(const QList<QgsPoint>& points)
599602
{
600603
// Normal plane area calculations.
601604
double area = 0.0;

‎src/core/qgsdistancearea.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef QGSDISTANCEAREA_H
1818
#define QGSDISTANCEAREA_H
1919

20-
#include <vector>
20+
#include <QList>
2121
#include "qgscoordinatetransform.h"
2222

2323
class QgsGeometry;
@@ -28,7 +28,7 @@ General purpose distance and area calculator
2828
- it's possible to pass points/features in any SRS, coordinates are transformed
2929
- two options how to use it
3030
+ use measure() takes QgsGeometry as a parameter and calculates distance or area
31-
+ use directly measureLine(), measurePolygon() which take vector of QgsPoints
31+
+ use directly measureLine(), measurePolygon() which take list of QgsPoints
3232
(both cases transform the coordinates from source SRS to the ellipse coords)
3333
- returned values are in meters resp. square meters
3434
*/
@@ -74,12 +74,12 @@ class CORE_EXPORT QgsDistanceArea
7474
double measure(QgsGeometry* geometry);
7575

7676
//! measures line with more segments
77-
double measureLine(const std::vector<QgsPoint>& points);
77+
double measureLine(const QList<QgsPoint>& points);
7878
//! measures line with one segment
7979
double measureLine(const QgsPoint& p1, const QgsPoint& p2);
8080

8181
//! measures polygon area
82-
double measurePolygon(const std::vector<QgsPoint>& points);
82+
double measurePolygon(const QList<QgsPoint>& points);
8383

8484
//! compute bearing - in radians
8585
double getBearing(const QgsPoint& p1, const QgsPoint& p2);
@@ -112,9 +112,9 @@ class CORE_EXPORT QgsDistanceArea
112112
algorithm has been taken from GRASS: gis/area_poly1.c
113113
114114
*/
115-
double computePolygonArea(const std::vector<QgsPoint>& points);
115+
double computePolygonArea(const QList<QgsPoint>& points);
116116

117-
double computePolygonFlatArea(const std::vector<QgsPoint>& points);
117+
double computePolygonFlatArea(const QList<QgsPoint>& points);
118118

119119
/**
120120
precalculates some values

0 commit comments

Comments
 (0)
Please sign in to comment.