double QgsDistanceArea::measurePolygon( const QList<QgsPoint>& points ) const { try { if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { QList<QgsPoint> pts; for ( QList<QgsPoint>::const_iterator i = points.begin(); i != points.end(); ++i ) { pts.append( mCoordTransform->transform( *i ) ); } return computePolygonArea( pts ); } else { return computePolygonArea( points ); } } catch ( QgsCsException &cse ) { Q_UNUSED( cse ); QgsMessageLog::logMessage( QObject::tr( "Caught a coordinate system exception while trying to transform a point. Unable to calculate polygon area." ) ); return 0.0; } }
double QgsDistanceArea::measurePolygon( const QgsCurveV2* curve ) const { if ( !curve ) { return 0.0; } QList<QgsPointV2> linePointsV2; curve->points( linePointsV2 ); QList<QgsPoint> linePoints; QList<QgsPointV2>::const_iterator ptIt = linePointsV2.constBegin(); for ( ; ptIt != linePointsV2.constEnd(); ++ptIt ) { linePoints.append( mCoordTransform->transform( QgsPoint( ptIt->x(), ptIt->y() ) ) ); } return computePolygonArea( linePoints ); }
const unsigned char *QgsDistanceArea::measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr ) const { if ( !feature ) { QgsDebugMsg( "no feature to measure" ); return nullptr; } QgsConstWkbPtr wkbPtr( feature + 1 + sizeof( int ) ); // get number of rings in the polygon int numRings; wkbPtr >> numRings; if ( numRings == 0 ) { QgsDebugMsg( "no rings to measure" ); return nullptr; } // Set pointer to the first ring QList<QgsPoint> points; QgsPoint pnt; double x, y; if ( area ) *area = 0; if ( perimeter ) *perimeter = 0; try { for ( int idx = 0; idx < numRings; idx++ ) { int nPoints; wkbPtr >> nPoints; // Extract the points from the WKB and store in a pair of // vectors. for ( int jdx = 0; jdx < nPoints; jdx++ ) { wkbPtr >> x >> y; if ( hasZptr ) { // totally ignore Z value wkbPtr += sizeof( double ); } pnt = QgsPoint( x, y ); if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { pnt = mCoordTransform->transform( pnt ); } points.append( pnt ); } if ( points.size() > 2 ) { if ( area ) { double areaTmp = computePolygonArea( points ); if ( idx == 0 ) { // exterior ring *area += areaTmp; } else { *area -= areaTmp; // interior rings } } if ( perimeter ) { if ( idx == 0 ) { // exterior ring *perimeter += computeDistance( points ); } } } points.clear(); } } catch ( QgsCsException &cse ) { Q_UNUSED( cse ); QgsMessageLog::logMessage( QObject::tr( "Caught a coordinate system exception while trying to transform a point. Unable to calculate polygon area or perimeter." ) ); } return wkbPtr; }
unsigned char* QgsDistanceArea::measurePolygon( unsigned char* feature, double* area, double* perimeter, bool hasZptr ) { // get number of rings in the polygon unsigned int numRings = *(( int* )( feature + 1 + sizeof( int ) ) ); if ( numRings == 0 ) return 0; // Set pointer to the first ring unsigned char* ptr = feature + 1 + 2 * sizeof( int ); QList<QgsPoint> points; QgsPoint pnt; double x, y; if ( area ) *area = 0; if ( perimeter ) *perimeter = 0; try { for ( unsigned int idx = 0; idx < numRings; idx++ ) { int nPoints = *(( int* )ptr ); ptr += 4; // Extract the points from the WKB and store in a pair of // vectors. for ( int jdx = 0; jdx < nPoints; jdx++ ) { x = *(( double * ) ptr ); ptr += sizeof( double ); y = *(( double * ) ptr ); ptr += sizeof( double ); if ( hasZptr ) { // totally ignore Z value ptr += sizeof( double ); } pnt = QgsPoint( x, y ); if ( mProjectionsEnabled && ( mEllipsoid != "NONE" ) ) { pnt = mCoordTransform->transform( pnt ); } points.append( pnt ); } if ( points.size() > 2 ) { if ( area ) { double areaTmp = computePolygonArea( points ); if ( idx == 0 ) { // exterior ring *area += areaTmp; } else { *area -= areaTmp; // interior rings } } if ( perimeter ) { *perimeter += measureLine( points ); } } points.clear(); if ( !area ) { break; } } } catch ( QgsCsException &cse ) { Q_UNUSED( cse ); QgsMessageLog::logMessage( QObject::tr( "Caught a coordinate system exception while trying to transform a point. Unable to calculate polygon area or perimeter." ) ); } return ptr; }