SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
spatialreferencesystem.h
Go to the documentation of this file.
1
10#ifndef SPATIALREFERENCESYSTEM_H
11#define SPATIALREFERENCESYSTEM_H
12
13#include <QObject>
14#include <QString>
15
16// Forward-declare GDAL types to avoid polluting headers
17class OGRSpatialReference;
18class OGRCoordinateTransformation;
19
27class SpatialReferenceSystem : public QObject
28{
29 Q_OBJECT
30 Q_PROPERTY(QString authName READ authName NOTIFY propertyChanged)
31 Q_PROPERTY(int code READ code NOTIFY propertyChanged)
32 Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY propertyChanged)
33 Q_PROPERTY(QString wkt READ toWkt NOTIFY propertyChanged)
34 Q_PROPERTY(QString proj4 READ toProj4 NOTIFY propertyChanged)
35 Q_PROPERTY(bool isGeographic READ isGeographic NOTIFY propertyChanged)
36 Q_PROPERTY(bool isProjected READ isProjected NOTIFY propertyChanged)
37 Q_PROPERTY(QString linearUnits READ linearUnitsName NOTIFY propertyChanged)
38
39public:
40
47 explicit SpatialReferenceSystem(const QString &authName = "EPSG",
48 int code = 4326,
49 QObject *parent = nullptr);
50
56 explicit SpatialReferenceSystem(const QString &wktOrProj,
57 QObject *parent = nullptr);
58
63 QObject *parent = nullptr);
64
65 virtual ~SpatialReferenceSystem();
66
67 // ----- Identity --------------------------------------------------------
68
72 [[nodiscard]] QString authName() const;
73
77 [[nodiscard]] int code() const;
78
82 [[nodiscard]] QString description() const;
83
87 void setDescription(const QString &description);
88
89 // ----- Serialization ---------------------------------------------------
90
95 [[nodiscard]] QString toWkt() const;
96
101 [[nodiscard]] QString toProj4() const;
102
106 [[nodiscard]] QString toAuthority() const;
107
108 // ----- Type predicates -------------------------------------------------
109
113 [[nodiscard]] bool isGeographic() const;
114
118 [[nodiscard]] bool isProjected() const;
119
123 [[nodiscard]] bool equals(const SpatialReferenceSystem &other) const;
124
125 // ----- Units -----------------------------------------------------------
126
131 [[nodiscard]] QString linearUnitsName() const;
132
137 [[nodiscard]] double linearUnitsToMetres() const;
138
143 [[nodiscard]] QString angularUnitsName() const;
144
154 {
155 double metresPerUnit = 1.0;
156 QString name;
157 bool usable = false;
158 };
159
165 [[nodiscard]] LinearUnitInfo planarLinearUnit() const;
166
167 // ----- GDAL interop ----------------------------------------------------
168
173 [[nodiscard]] OGRSpatialReference *ogrSpatialReference() const;
174
182 [[nodiscard]] OGRCoordinateTransformation *
184
185 // ----- Factory methods -------------------------------------------------
186
193 [[nodiscard]] static SpatialReferenceSystem *fromWktOrProj(const QString &wktOrProj,
194 QObject *parent = nullptr);
195
203 [[nodiscard]] static SpatialReferenceSystem *fromAuthCode(const QString &authName,
204 int code,
205 QObject *parent = nullptr);
206
211 [[nodiscard]] static SpatialReferenceSystem *untitled(QObject *parent = nullptr);
212
220 [[nodiscard]] static SpatialReferenceSystem *localFromMapUnits(const QString &mapUnits,
221 QObject *parent = nullptr);
222
223 // ----- Local-CS predicate ----------------------------------------------
224
226 [[nodiscard]] bool isLocal() const;
227
228signals:
233 void propertyChanged(const QString &propertyName);
234
235private:
236 SpatialReferenceSystem(QObject *parent, Qt::Initialization); // null-init for factory use
237 void initFromAuthCode(const QString &authName, int code);
238 void initFromWktOrProj(const QString &wktOrProj);
239
240 OGRSpatialReference *m_ogrSRS = nullptr;
241 QString m_authName;
242 int m_code = -1;
243 QString m_description;
244};
245
246#endif // SPATIALREFERENCESYSTEM_H
Represents a coordinate reference system backed by a GDAL OGRSpatialReference.
Definition spatialreferencesystem.h:28
OGRCoordinateTransformation * createTransformationTo(const SpatialReferenceSystem &target) const
Creates a new OGRCoordinateTransformation from this CRS to target.
Definition spatialreferencesystem.cpp:238
QString linearUnitsName() const
Returns the name of the linear unit (e.g. "metre", "US survey foot"). Returns an empty string for geo...
Definition spatialreferencesystem.cpp:187
bool isLocal() const
Definition spatialreferencesystem.cpp:162
static SpatialReferenceSystem * fromWktOrProj(const QString &wktOrProj, QObject *parent=nullptr)
Creates a SpatialReferenceSystem from a WKT or PROJ string.
Definition spatialreferencesystem.cpp:248
bool isProjected
Definition spatialreferencesystem.h:36
static SpatialReferenceSystem * localFromMapUnits(const QString &mapUnits, QObject *parent=nullptr)
Creates a local CRS with linear units derived from the SWMM [MAP] section Units field (e....
Definition spatialreferencesystem.cpp:281
QString toProj4() const
Exports this CRS as a legacy PROJ.4 string.
Definition spatialreferencesystem.cpp:141
void propertyChanged(const QString &propertyName)
Emitted when any property changes.
int code
Definition spatialreferencesystem.h:31
static SpatialReferenceSystem * untitled(QObject *parent=nullptr)
Creates a local / untitled CRS for models with no coordinate system defined. Coordinates are treated ...
Definition spatialreferencesystem.cpp:270
QString description
Definition spatialreferencesystem.h:32
LinearUnitInfo planarLinearUnit() const
Returns a LinearUnitInfo describing the planar linear unit.
Definition spatialreferencesystem.cpp:210
QString wkt
Definition spatialreferencesystem.h:33
QString toWkt() const
Exports this CRS as a WKT2 string.
Definition spatialreferencesystem.cpp:131
double linearUnitsToMetres() const
Returns the conversion factor from the linear unit to metres. Returns 1.0 for geographic CRSes.
Definition spatialreferencesystem.cpp:195
QString toAuthority() const
Returns the "AUTHORITY:CODE" string, e.g. "EPSG:4326".
Definition spatialreferencesystem.cpp:151
static SpatialReferenceSystem * fromAuthCode(const QString &authName, int code, QObject *parent=nullptr)
Creates a SpatialReferenceSystem from an authority code.
Definition spatialreferencesystem.cpp:256
bool equals(const SpatialReferenceSystem &other) const
Returns true when this CRS equals other (within GDAL tolerance).
Definition spatialreferencesystem.cpp:177
QString authName
Definition spatialreferencesystem.h:30
QString proj4
Definition spatialreferencesystem.h:34
void setDescription(const QString &description)
Sets a custom description for this CRS.
Definition spatialreferencesystem.cpp:118
bool isGeographic
Definition spatialreferencesystem.h:35
QString linearUnits
Definition spatialreferencesystem.h:37
QString angularUnitsName() const
Returns the name of the angular unit (e.g. "degree"). Returns an empty string for projected CRSes.
Definition spatialreferencesystem.cpp:201
OGRSpatialReference * ogrSpatialReference() const
Returns a non-owning pointer to the underlying OGRSpatialReference.
Definition spatialreferencesystem.cpp:232
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
Planar linear-unit information used by the 2D mesh writer.
Definition spatialreferencesystem.h:154
QString name
Definition spatialreferencesystem.h:156