QGIS API Documentation 3.38.0-Grenoble (exported)
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
59
61 QgsDistanceArea( const QgsDistanceArea &other );
62 QgsDistanceArea &operator=( const QgsDistanceArea &other );
63
69 bool willUseEllipsoid() const;
70
75 void setSourceCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
76
82 QgsCoordinateReferenceSystem sourceCrs() const { return mCoordTransform.sourceCrs(); }
83
90 QgsCoordinateReferenceSystem ellipsoidCrs() const { return mCoordTransform.destinationCrs(); }
91
100 bool setEllipsoid( const QString &ellipsoid );
101
109 bool setEllipsoid( double semiMajor, double semiMinor );
110
118 QString ellipsoid() const { return mEllipsoid; }
119
126 double ellipsoidSemiMajor() const { return mSemiMajor; }
127
134 double ellipsoidSemiMinor() const { return mSemiMinor; }
135
143 double ellipsoidInverseFlattening() const { return mInvFlattening; }
144
154 double measureArea( const QgsGeometry &geometry ) const;
155
165 double measureLength( const QgsGeometry &geometry ) const;
166
176 double measurePerimeter( const QgsGeometry &geometry ) const;
177
184 double measureLine( const QVector<QgsPointXY> &points ) const;
185
193 double measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const;
194
208 double measureLineProjected( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2, QgsPointXY *projectedPoint SIP_OUT = nullptr ) const;
209
214 Qgis::DistanceUnit lengthUnits() const;
215
220 Qgis::AreaUnit areaUnits() const;
221
225 double measurePolygon( const QVector<QgsPointXY> &points ) const;
226
232 double bearing( const QgsPointXY &p1, const QgsPointXY &p2 ) const SIP_THROW( QgsCsException );
233
244 static QString formatDistance( double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit = false );
245
256 static QString formatArea( double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit = false );
257
267 double convertLengthMeasurement( double length, Qgis::DistanceUnit toUnits ) const;
268
278 double convertAreaMeasurement( double area, Qgis::AreaUnit toUnits ) const;
279
290 QgsPointXY computeSpheroidProject( const QgsPointXY &p1, double distance = 1, double azimuth = M_PI_2 ) const;
291
311 QVector<QVector<QgsPointXY> > geodesicLine( const QgsPointXY &p1, const QgsPointXY &p2, double interval, bool breakLine = false ) const;
312
331 double latitudeGeodesicCrossesAntimeridian( const QgsPointXY &p1, const QgsPointXY &p2, double &fractionAlongLine SIP_OUT ) const;
332
354 QgsGeometry splitGeometryAtAntimeridian( const QgsGeometry &geometry ) const;
355
356 private:
357
362 double computePolygonArea( const QVector<QgsPointXY> &points ) const;
363
364 double computePolygonFlatArea( const QVector<QgsPointXY> &points ) const;
365
370 void computeAreaInit() const;
371
372 void setFromParams( const QgsEllipsoidUtils::EllipsoidParameters &params );
373
374 enum MeasureType
375 {
376 Default,
377 Area,
378 Length
379 };
380
382 QgsCoordinateTransform mCoordTransform;
383
385 QString mEllipsoid;
386
388 double mSemiMajor, mSemiMinor, mInvFlattening;
389
390 mutable std::unique_ptr< geod_geodesic > mGeod;
391
392 // utility functions for polygon area measurement
393
394 double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
395 double measureLine( const QgsCurve *curve ) const;
396 double measurePolygon( const QgsCurve *curve ) const;
397
398};
399
400#endif
401
DistanceUnit
Units of distance.
Definition qgis.h:4358
AreaUnit
Units of area.
Definition qgis.h:4396
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.