Skip to content
Permalink
Browse files
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/qgis@6760 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 4, 2007
1 parent 9834716 commit 70146f393e0e6efab742c11db4cafe0ac6e47f86
Showing with 34 additions and 32 deletions.
  1. +2 −2 python/core/qgsdistancearea.sip
  2. +4 −4 src/app/qgsmeasure.cpp
  3. +1 −2 src/app/qgsmeasure.h
  4. +21 −18 src/core/qgsdistancearea.cpp
  5. +6 −6 src/core/qgsdistancearea.h
@@ -44,13 +44,13 @@ class QgsDistanceArea
double measure(QgsGeometry* geometry);

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

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

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

//! compute bearing - in radians
double getBearing(const QgsPoint& p1, const QgsPoint& p2);
@@ -127,7 +127,7 @@ QgsMeasure::~QgsMeasure()
void QgsMeasure::restart(void )
{
updateProjection();
mPoints.resize(0);
mPoints.clear();
// Set one cell row where to update current distance
// If measuring area, the table doesn't get shown
mTable->setNumRows(1);
@@ -166,7 +166,7 @@ void QgsMeasure::addPoint(QgsPoint &point)
return;

QgsPoint pnt(point);
mPoints.push_back(pnt);
mPoints.append(pnt);

if (mMeasureArea && mPoints.size() > 2)
{
@@ -219,8 +219,8 @@ void QgsMeasure::mouseMove(QgsPoint &point)
// show current distance/area while moving the point
// by creating a temporary copy of point array
// and adding moving point at the end
std::vector<QgsPoint> tmpPoints = mPoints;
tmpPoints.push_back(point);
QList<QgsPoint> tmpPoints = mPoints;
tmpPoints.append(point);
if (mMeasureArea && tmpPoints.size() > 2)
{
double area = mCanvas->mapRender()->distArea()->measurePolygon(tmpPoints);
@@ -20,7 +20,6 @@
#include <QWidget>
#include "qgsmaptool.h"
#include "qgspoint.h"
#include <vector>

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

std::vector<QgsPoint> mPoints;
QList<QgsPoint> mPoints;

double mTotal;

@@ -229,24 +229,25 @@ unsigned char* QgsDistanceArea::measureLine(unsigned char* feature, double* area
unsigned int nPoints = *((int*)ptr);
ptr = feature + 9;

std::vector<QgsPoint> points(nPoints);
QList<QgsPoint> points;
double x,y;

QgsDebugMsg("This feature WKB has " + QString::number(nPoints) + " points");
// Extract the points from the WKB format into the vector
for (unsigned int i = 0; i < nPoints; ++i)
{
QgsPoint& p = points[i];
p.setX(*((double *) ptr));
x = *((double *) ptr);
ptr += sizeof(double);
p.setY(*((double *) ptr));
y = *((double *) ptr);
ptr += sizeof(double);
points.append(QgsPoint(x,y));
}

*area = measureLine(points);
return ptr;
}

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

for (std::vector<QgsPoint>::size_type i = 1; i < points.size(); i++)
for (QList<QgsPoint>::const_iterator i = points.begin(); i != points.end(); ++i)
{
if (mProjectionsEnabled && (mEllipsoid != "NONE"))
{
p2 = mCoordTransform->transform(points[i]);
p2 = mCoordTransform->transform(*i);
total += computeDistanceBearing(p1,p2);
}
else
{
p2 = points[i];
p2 = *i;
total += measureLine(p1,p2);
}

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

std::vector<QgsPoint> points;
QList<QgsPoint> points;
QgsPoint pnt;
double x,y, areaTmp;
*area = 0;

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

// 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
ptr += sizeof(double);
y = *((double *) ptr);
ptr += sizeof(double);

pnt = QgsPoint(x,y);

points[jdx] = QgsPoint(x,y);
if (mProjectionsEnabled && (mEllipsoid != "NONE"))
{
points[jdx] = mCoordTransform->transform(points[jdx]);
pnt = mCoordTransform->transform(pnt);
}
points.append(pnt);
}

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


double QgsDistanceArea::measurePolygon(const std::vector<QgsPoint>& points)
double QgsDistanceArea::measurePolygon(const QList<QgsPoint>& points)
{

try
{
if (mProjectionsEnabled && (mEllipsoid != "NONE"))
{
std::vector<QgsPoint> pts(points.size());
for (std::vector<QgsPoint>::size_type i = 0; i < points.size(); i++)
QList<QgsPoint> pts;
for (QList<QgsPoint>::const_iterator i = points.begin(); i != points.end(); ++i)
{
pts[i] = mCoordTransform->transform(points[i]);
pts.append(mCoordTransform->transform(*i));
}
return computePolygonArea(pts);
}
@@ -540,7 +543,7 @@ void QgsDistanceArea::computeAreaInit()
}


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

double QgsDistanceArea::computePolygonFlatArea(const std::vector<QgsPoint>& points)
double QgsDistanceArea::computePolygonFlatArea(const QList<QgsPoint>& points)
{
// Normal plane area calculations.
double area = 0.0;
@@ -17,7 +17,7 @@
#ifndef QGSDISTANCEAREA_H
#define QGSDISTANCEAREA_H

#include <vector>
#include <QList>
#include "qgscoordinatetransform.h"

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

//! measures line with more segments
double measureLine(const std::vector<QgsPoint>& points);
double measureLine(const QList<QgsPoint>& points);
//! measures line with one segment
double measureLine(const QgsPoint& p1, const QgsPoint& p2);

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

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

double computePolygonFlatArea(const std::vector<QgsPoint>& points);
double computePolygonFlatArea(const QList<QgsPoint>& points);

/**
precalculates some values

0 comments on commit 70146f3

Please sign in to comment.