QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsdistancearea.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdistancearea.h - Distance and area calculations on the ellipsoid
3 ---------------------------------------------------------------------------
4 Date : September 2005
5 Copyright : (C) 2005 by Martin Dobias
6 email : won.der at centrum.sk
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSDISTANCEAREA_H
17#define QGSDISTANCEAREA_H
18
19#include "qgis_core.h"
20#include <QVector>
21#include <QReadWriteLock>
23#include "qgis.h"
24#include "qgsellipsoidutils.h"
25
26class QgsGeometry;
28class QgsCurve;
29struct geod_geodesic;
30
52class CORE_EXPORT QgsDistanceArea
53{
54 public:
55
58
59 QgsDistanceArea( const QgsDistanceArea &other );
60 QgsDistanceArea &operator=( const QgsDistanceArea &other );
61
67 bool willUseEllipsoid() const;
68
73 void setSourceCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
74
80 QgsCoordinateReferenceSystem sourceCrs() const { return mCoordTransform.sourceCrs(); }
81
88 QgsCoordinateReferenceSystem ellipsoidCrs() const { return mCoordTransform.destinationCrs(); }
89
98 bool setEllipsoid( const QString &ellipsoid );
99
107 bool setEllipsoid( double semiMajor, double semiMinor );
108
116 QString ellipsoid() const { return mEllipsoid; }
117
124 double ellipsoidSemiMajor() const { return mSemiMajor; }
125
132 double ellipsoidSemiMinor() const { return mSemiMinor; }
133
141 double ellipsoidInverseFlattening() const { return mInvFlattening; }
142
153 double measureArea( const QgsGeometry &geometry ) const SIP_THROW( QgsCsException );
154
165 double measureLength( const QgsGeometry &geometry ) const SIP_THROW( QgsCsException );
166
177 double measurePerimeter( const QgsGeometry &geometry ) const SIP_THROW( QgsCsException );
178
186 double measureLine( const QVector<QgsPointXY> &points ) const SIP_THROW( QgsCsException );
187
196 double measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const SIP_THROW( QgsCsException );
197
211 double measureLineProjected( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2, QgsPointXY *projectedPoint SIP_OUT = nullptr ) const;
212
217 Qgis::DistanceUnit lengthUnits() const;
218
223 Qgis::AreaUnit areaUnits() const;
224
230 double measurePolygon( const QVector<QgsPointXY> &points ) const SIP_THROW( QgsCsException );
231
237 double bearing( const QgsPointXY &p1, const QgsPointXY &p2 ) const SIP_THROW( QgsCsException );
238
249 static QString formatDistance( double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit = false );
250
261 static QString formatArea( double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit = false );
262
272 double convertLengthMeasurement( double length, Qgis::DistanceUnit toUnits ) const;
273
283 double convertAreaMeasurement( double area, Qgis::AreaUnit toUnits ) const;
284
295 QgsPointXY computeSpheroidProject( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2 ) const;
296
316 QVector<QVector<QgsPointXY> > geodesicLine( const QgsPointXY &p1, const QgsPointXY &p2, double interval, bool breakLine = false ) const;
317
336 double latitudeGeodesicCrossesAntimeridian( const QgsPointXY &p1, const QgsPointXY &p2, double &fractionAlongLine SIP_OUT ) const;
337
359 QgsGeometry splitGeometryAtAntimeridian( const QgsGeometry &geometry ) const;
360
361 private:
362
367 double computePolygonArea( const QVector<QgsPointXY> &points ) const;
368
369 double computePolygonFlatArea( const QVector<QgsPointXY> &points ) const;
370
375 void computeAreaInit() const;
376
377 void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
378
379 enum MeasureType
380 {
381 Default,
382 Area,
383 Length
384 };
385
387 QgsCoordinateTransform mCoordTransform;
388
390 QString mEllipsoid;
391
393 double mSemiMajor, mSemiMinor, mInvFlattening;
394
395 mutable std::unique_ptr< geod_geodesic > mGeod;
396
397 // utility functions for polygon area measurement
398
399 double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
400 double measureLine( const QgsCurve *curve ) const;
401 double measurePolygon( const QgsCurve *curve ) const;
402
403};
404
405#endif
406
DistanceUnit
Units of distance.
Definition qgis.h:4722
AreaUnit
Units of area.
Definition qgis.h:4799
Abstract base class for all geometries.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:35
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
QgsCoordinateReferenceSystem ellipsoidCrs() const
Returns the ellipsoid (destination) spatial reference system.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source spatial reference system.
double ellipsoidInverseFlattening() const
Returns ellipsoid's inverse flattening.
QString ellipsoid() const
Returns ellipsoid's acronym.
double ellipsoidSemiMajor() const
Returns the ellipsoid's semi major axis.
double ellipsoidSemiMinor() const
Returns ellipsoid's semi minor axis.
A geometry is the spatial representation of a feature.
A class to represent a 2D point.
Definition qgspointxy.h:60
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
const QgsCoordinateReferenceSystem & crs
Contains parameters for an ellipsoid.