1 /***************************************************************************
2 qgsreferencedgeometry.h
3 ----------------------
4 begin : June 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #ifndef QGSREFERENCEDGEOMETRY_H
19 #define QGSREFERENCEDGEOMETRY_H
20
21 #include "qgis_sip.h"
22 #include "qgis_core.h"
23 #include "qgscoordinatereferencesystem.h"
24 #include "qgsrectangle.h"
25 #include "qgsgeometry.h"
26
27 /**
28 * \class QgsReferencedGeometryBase
29 * \ingroup core
30 * \brief A base class for geometry primitives which are stored with an associated reference system.
31 *
32 * QgsReferencedGeometryBase classes represent some form of geometry primitive
33 * (such as rectangles) which have an optional coordinate reference system
34 * associated with them.
35 *
36 * \see QgsReferencedRectangle
37 * \since QGIS 3.0
38 */
39 class CORE_EXPORT QgsReferencedGeometryBase
40 {
41 public:
42
43 /**
44 * Constructor for QgsReferencedGeometryBase, with the specified \a crs.
45 */
46 QgsReferencedGeometryBase( const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
47
48 /**
49 * Returns the associated coordinate reference system, or an invalid CRS if
50 * no reference system is set.
51 * \see setCrs()
52 */
crs()53 QgsCoordinateReferenceSystem crs() const { return mCrs; }
54
55 /**
56 * Sets the associated \a crs. Set to an invalid CRS if
57 * no reference system is required.
58 * \see crs()
59 */
setCrs(const QgsCoordinateReferenceSystem & crs)60 void setCrs( const QgsCoordinateReferenceSystem &crs ) { mCrs = crs; }
61
62 private:
63
64 QgsCoordinateReferenceSystem mCrs;
65
66 };
67
68 /**
69 * \ingroup core
70 * \brief A QgsRectangle with associated coordinate reference system.
71 * \since QGIS 3.0
72 */
73 class CORE_EXPORT QgsReferencedRectangle : public QgsRectangle, public QgsReferencedGeometryBase
74 {
75 public:
76
77 /**
78 * Constructor for QgsReferencedRectangle, with the specified initial \a rectangle
79 * and \a crs.
80 */
81 QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );
82
83 /**
84 * Constructor for QgsReferencedRectangle.
85 */
86 QgsReferencedRectangle() = default;
87
88 //! Allows direct construction of QVariants from rectangle.
QVariant()89 operator QVariant() const
90 {
91 return QVariant::fromValue( *this );
92 }
93
94 bool operator==( const QgsReferencedRectangle &other ) const;
95 bool operator!=( const QgsReferencedRectangle &other ) const;
96
97 #ifdef SIP_RUN
98 SIP_PYOBJECT __repr__();
99 % MethodCode
100 QString str = QStringLiteral( "<QgsReferencedRectangle: %1 (%2)>" ).arg( sipCpp->asWktCoordinates(), sipCpp->crs().authid() );
101 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
102 % End
103 #endif
104
105 };
106
Q_DECLARE_METATYPE(QgsReferencedRectangle)107 Q_DECLARE_METATYPE( QgsReferencedRectangle )
108
109 /**
110 * \ingroup core
111 * \brief A QgsPointXY with associated coordinate reference system.
112 * \since QGIS 3.0
113 */
114 class CORE_EXPORT QgsReferencedPointXY : public QgsPointXY, public QgsReferencedGeometryBase
115 {
116 public:
117
118 /**
119 * Constructor for QgsReferencedPointXY, with the specified initial \a point
120 * and \a crs.
121 */
122 QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );
123
124 /**
125 * Constructor for QgsReferencedPointXY.
126 */
127 QgsReferencedPointXY() = default;
128
129 //! Allows direct construction of QVariants from point.
130 operator QVariant() const
131 {
132 return QVariant::fromValue( *this );
133 }
134
135 bool operator==( const QgsReferencedPointXY &other );
136 bool operator!=( const QgsReferencedPointXY &other );
137
138 #ifdef SIP_RUN
139 SIP_PYOBJECT __repr__();
140 % MethodCode
141 QString str = QStringLiteral( "<QgsReferencedPointXY: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
142 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
143 % End
144 #endif
145
146 };
147
Q_DECLARE_METATYPE(QgsReferencedPointXY)148 Q_DECLARE_METATYPE( QgsReferencedPointXY )
149
150 /**
151 * \ingroup core
152 * \brief A QgsGeometry with associated coordinate reference system.
153 * \since QGIS 3.16
154 */
155 class CORE_EXPORT QgsReferencedGeometry : public QgsGeometry, public QgsReferencedGeometryBase
156 {
157 public:
158
159 /**
160 * Constructor for QgsReferencedGeometry, with the specified initial \a geometry
161 * and \a crs.
162 */
163 QgsReferencedGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs );
164
165 /**
166 * Constructor for QgsReferencedGeometry.
167 */
168 QgsReferencedGeometry() = default;
169
170 //! Allows direct construction of QVariants from geometry.
171 operator QVariant() const
172 {
173 return QVariant::fromValue( *this );
174 }
175
176 /**
177 * Construct a new QgsReferencedGeometry from referenced \a point
178 */
179 static QgsReferencedGeometry fromReferencedPointXY( const QgsReferencedPointXY &point );
180
181 /**
182 * Construct a new QgsReferencedGeometry from referenced \a rectangle
183 */
184 static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );
185
186
187 #ifdef SIP_RUN
188 SIP_PYOBJECT __repr__();
189 % MethodCode
190 QString str = QStringLiteral( "<QgsReferencedGeometry: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
191 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
192 % End
193 #endif
194
195 };
196
197 Q_DECLARE_METATYPE( QgsReferencedGeometry )
198
199 #endif // QGSREFERENCEDGEOMETRY_H
200