/src/PROJ/include/proj/common.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: PROJ |
4 | | * Purpose: ISO19111:2019 implementation |
5 | | * Author: Even Rouault <even dot rouault at spatialys dot com> |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 2018, Even Rouault <even dot rouault at spatialys dot com> |
9 | | * |
10 | | * Permission is hereby granted, free of charge, to any person obtaining a |
11 | | * copy of this software and associated documentation files (the "Software"), |
12 | | * to deal in the Software without restriction, including without limitation |
13 | | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
14 | | * and/or sell copies of the Software, and to permit persons to whom the |
15 | | * Software is furnished to do so, subject to the following conditions: |
16 | | * |
17 | | * The above copyright notice and this permission notice shall be included |
18 | | * in all copies or substantial portions of the Software. |
19 | | * |
20 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
21 | | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
23 | | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
24 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
25 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
26 | | * DEALINGS IN THE SOFTWARE. |
27 | | ****************************************************************************/ |
28 | | |
29 | | #ifndef COMMON_HH_INCLUDED |
30 | | #define COMMON_HH_INCLUDED |
31 | | |
32 | | #include <memory> |
33 | | #include <string> |
34 | | #include <vector> |
35 | | |
36 | | #include "io.hpp" |
37 | | #include "metadata.hpp" |
38 | | #include "util.hpp" |
39 | | |
40 | | NS_PROJ_START |
41 | | |
42 | | /** osgeo.proj.common namespace |
43 | | * |
44 | | * \brief Common classes. |
45 | | */ |
46 | | namespace common { |
47 | | |
48 | | // --------------------------------------------------------------------------- |
49 | | |
50 | | class UnitOfMeasure; |
51 | | /** Shared pointer of UnitOfMeasure. */ |
52 | | using UnitOfMeasurePtr = std::shared_ptr<UnitOfMeasure>; |
53 | | /** Non-null shared pointer of UnitOfMeasure. */ |
54 | | using UnitOfMeasureNNPtr = util::nn<UnitOfMeasurePtr>; |
55 | | |
56 | | /** \brief Unit of measure. |
57 | | * |
58 | | * This is a mutable object. |
59 | | */ |
60 | | class PROJ_GCC_DLL UnitOfMeasure : public util::BaseObject { |
61 | | public: |
62 | | /** \brief Type of unit of measure. */ |
63 | | enum class PROJ_MSVC_DLL Type { |
64 | | /** Unknown unit of measure */ |
65 | | UNKNOWN, |
66 | | /** No unit of measure */ |
67 | | NONE, |
68 | | /** Angular unit of measure */ |
69 | | ANGULAR, |
70 | | /** Linear unit of measure */ |
71 | | LINEAR, |
72 | | /** Scale unit of measure */ |
73 | | SCALE, |
74 | | /** Time unit of measure */ |
75 | | TIME, |
76 | | /** Parametric unit of measure */ |
77 | | PARAMETRIC, |
78 | | }; |
79 | | |
80 | | PROJ_DLL explicit UnitOfMeasure( |
81 | | const std::string &nameIn = std::string(), double toSIIn = 1.0, |
82 | | Type typeIn = Type::UNKNOWN, |
83 | | const std::string &codeSpaceIn = std::string(), |
84 | | const std::string &codeIn = std::string()); |
85 | | |
86 | | //! @cond Doxygen_Suppress |
87 | | PROJ_DLL UnitOfMeasure(const UnitOfMeasure &other); |
88 | | PROJ_DLL ~UnitOfMeasure() override; |
89 | | PROJ_DLL UnitOfMeasure &operator=(const UnitOfMeasure &other); |
90 | | PROJ_DLL UnitOfMeasure &operator=(UnitOfMeasure &&other); |
91 | | PROJ_INTERNAL static UnitOfMeasureNNPtr create(const UnitOfMeasure &other); |
92 | | //! @endcond |
93 | | |
94 | | PROJ_DLL const std::string &name() PROJ_PURE_DECL; |
95 | | PROJ_DLL double conversionToSI() PROJ_PURE_DECL; |
96 | | PROJ_DLL Type type() PROJ_PURE_DECL; |
97 | | |
98 | | PROJ_DLL const std::string &codeSpace() PROJ_PURE_DECL; |
99 | | PROJ_DLL const std::string &code() PROJ_PURE_DECL; |
100 | | |
101 | | PROJ_DLL bool operator==(const UnitOfMeasure &other) PROJ_PURE_DECL; |
102 | | PROJ_DLL bool operator!=(const UnitOfMeasure &other) PROJ_PURE_DECL; |
103 | | |
104 | | //! @cond Doxygen_Suppress |
105 | | PROJ_INTERNAL void _exportToWKT(io::WKTFormatter *formatter, |
106 | | const std::string &unitType = std::string()) |
107 | | const; // throw(io::FormattingException) |
108 | | |
109 | | PROJ_INTERNAL void _exportToJSON( |
110 | | io::JSONFormatter *formatter) const; // throw(io::FormattingException) |
111 | | |
112 | | PROJ_INTERNAL std::string exportToPROJString() const; |
113 | | |
114 | | PROJ_INTERNAL bool |
115 | | _isEquivalentTo(const UnitOfMeasure &other, |
116 | | util::IComparable::Criterion criterion = |
117 | | util::IComparable::Criterion::STRICT) const; |
118 | | |
119 | | //! @endcond |
120 | | |
121 | | PROJ_DLL static const UnitOfMeasure NONE; |
122 | | |
123 | | PROJ_DLL static const UnitOfMeasure SCALE_UNITY; |
124 | | PROJ_DLL static const UnitOfMeasure PARTS_PER_MILLION; |
125 | | PROJ_DLL static const UnitOfMeasure PPM_PER_YEAR; |
126 | | |
127 | | PROJ_DLL static const UnitOfMeasure METRE; |
128 | | PROJ_DLL static const UnitOfMeasure METRE_PER_YEAR; |
129 | | PROJ_DLL static const UnitOfMeasure FOOT; |
130 | | PROJ_DLL static const UnitOfMeasure US_FOOT; |
131 | | |
132 | | PROJ_DLL static const UnitOfMeasure RADIAN; |
133 | | PROJ_DLL static const UnitOfMeasure MICRORADIAN; |
134 | | PROJ_DLL static const UnitOfMeasure DEGREE; |
135 | | PROJ_DLL static const UnitOfMeasure ARC_SECOND; |
136 | | PROJ_DLL static const UnitOfMeasure GRAD; |
137 | | PROJ_DLL static const UnitOfMeasure ARC_SECOND_PER_YEAR; |
138 | | |
139 | | PROJ_DLL static const UnitOfMeasure SECOND; |
140 | | PROJ_DLL static const UnitOfMeasure YEAR; |
141 | | |
142 | | private: |
143 | | PROJ_OPAQUE_PRIVATE_DATA |
144 | | }; |
145 | | |
146 | | // --------------------------------------------------------------------------- |
147 | | |
148 | | /** \brief Numeric value associated with a UnitOfMeasure. */ |
149 | | class Measure : public util::BaseObject { |
150 | | public: |
151 | | // cppcheck-suppress noExplicitConstructor |
152 | | PROJ_DLL Measure(double valueIn = 0.0, |
153 | | const UnitOfMeasure &unitIn = UnitOfMeasure()); |
154 | | |
155 | | //! @cond Doxygen_Suppress |
156 | | PROJ_DLL Measure(const Measure &other); |
157 | | PROJ_DLL ~Measure() override; |
158 | | //! @endcond |
159 | | |
160 | | PROJ_DLL const UnitOfMeasure &unit() PROJ_PURE_DECL; |
161 | | PROJ_DLL double getSIValue() PROJ_PURE_DECL; |
162 | | PROJ_DLL double value() PROJ_PURE_DECL; |
163 | | |
164 | | PROJ_DLL double |
165 | | convertToUnit(const UnitOfMeasure &otherUnit) PROJ_PURE_DECL; |
166 | | |
167 | | PROJ_DLL bool operator==(const Measure &other) PROJ_PURE_DECL; |
168 | | |
169 | | /** Default maximum resulative error. */ |
170 | | static constexpr double DEFAULT_MAX_REL_ERROR = 1e-10; |
171 | | |
172 | | PROJ_INTERNAL bool |
173 | | _isEquivalentTo(const Measure &other, |
174 | | util::IComparable::Criterion criterion = |
175 | | util::IComparable::Criterion::STRICT, |
176 | | double maxRelativeError = DEFAULT_MAX_REL_ERROR) const; |
177 | | |
178 | | private: |
179 | | PROJ_OPAQUE_PRIVATE_DATA |
180 | | Measure &operator=(const Measure &) = delete; |
181 | | }; |
182 | | |
183 | | // --------------------------------------------------------------------------- |
184 | | |
185 | | /** \brief Numeric value, without a physical unit of measure. */ |
186 | | class Scale : public Measure { |
187 | | public: |
188 | | PROJ_DLL explicit Scale(double valueIn = 0.0); |
189 | | PROJ_DLL explicit Scale(double valueIn, const UnitOfMeasure &unitIn); |
190 | | |
191 | | //! @cond Doxygen_Suppress |
192 | 0 | explicit Scale(const Measure &other) : Scale(other.value(), other.unit()) {} |
193 | | PROJ_DLL Scale(const Scale &other); |
194 | | PROJ_DLL ~Scale() override; |
195 | | //! @endcond |
196 | | |
197 | | protected: |
198 | | PROJ_FRIEND_OPTIONAL(Scale); |
199 | | Scale &operator=(const Scale &) = delete; |
200 | | }; |
201 | | |
202 | | // --------------------------------------------------------------------------- |
203 | | |
204 | | /** \brief Numeric value, with a angular unit of measure. */ |
205 | | class Angle : public Measure { |
206 | | public: |
207 | | PROJ_DLL explicit Angle(double valueIn = 0.0); |
208 | | PROJ_DLL Angle(double valueIn, const UnitOfMeasure &unitIn); |
209 | | |
210 | | //! @cond Doxygen_Suppress |
211 | 18 | explicit Angle(const Measure &other) : Angle(other.value(), other.unit()) {} |
212 | | PROJ_DLL Angle(const Angle &other); |
213 | | PROJ_DLL ~Angle() override; |
214 | | //! @endcond |
215 | | |
216 | | protected: |
217 | | PROJ_FRIEND_OPTIONAL(Angle); |
218 | | Angle &operator=(const Angle &) = delete; |
219 | | }; |
220 | | |
221 | | // --------------------------------------------------------------------------- |
222 | | |
223 | | /** \brief Numeric value, with a linear unit of measure. */ |
224 | | class Length : public Measure { |
225 | | public: |
226 | | PROJ_DLL explicit Length(double valueIn = 0.0); |
227 | | PROJ_DLL Length(double valueIn, const UnitOfMeasure &unitIn); |
228 | | |
229 | | //! @cond Doxygen_Suppress |
230 | | explicit Length(const Measure &other) |
231 | 19 | : Length(other.value(), other.unit()) {} |
232 | | PROJ_DLL Length(const Length &other); |
233 | | PROJ_DLL ~Length() override; |
234 | | //! @endcond |
235 | | |
236 | | protected: |
237 | | PROJ_FRIEND_OPTIONAL(Length); |
238 | | Length &operator=(const Length &) = delete; |
239 | | }; |
240 | | |
241 | | // --------------------------------------------------------------------------- |
242 | | |
243 | | /** \brief Date-time value, as a ISO:8601 encoded string, or other string |
244 | | * encoding */ |
245 | | class DateTime { |
246 | | public: |
247 | | //! @cond Doxygen_Suppress |
248 | | PROJ_DLL DateTime(const DateTime &other); |
249 | | PROJ_DLL ~DateTime(); |
250 | | //! @endcond |
251 | | |
252 | | PROJ_DLL bool isISO_8601() const; |
253 | | PROJ_DLL std::string toString() const; |
254 | | |
255 | | PROJ_DLL static DateTime |
256 | | create(const std::string &str); // may throw Exception |
257 | | |
258 | | protected: |
259 | | DateTime(); |
260 | | PROJ_FRIEND_OPTIONAL(DateTime); |
261 | | DateTime &operator=(const DateTime &other); |
262 | | |
263 | | private: |
264 | | explicit DateTime(const std::string &str); |
265 | | |
266 | | PROJ_OPAQUE_PRIVATE_DATA |
267 | | }; |
268 | | |
269 | | // --------------------------------------------------------------------------- |
270 | | |
271 | | /** \brief Data epoch */ |
272 | | class DataEpoch { |
273 | | public: |
274 | | //! @cond Doxygen_Suppress |
275 | | PROJ_DLL explicit DataEpoch(const Measure &coordinateEpochIn); |
276 | | PROJ_DLL DataEpoch(const DataEpoch &other); |
277 | | PROJ_DLL ~DataEpoch(); |
278 | | //! @endcond |
279 | | |
280 | | PROJ_DLL const Measure &coordinateEpoch() const; |
281 | | |
282 | | protected: |
283 | | DataEpoch(); |
284 | | PROJ_FRIEND_OPTIONAL(DataEpoch); |
285 | | |
286 | | private: |
287 | | DataEpoch &operator=(const DataEpoch &other) = delete; |
288 | | PROJ_OPAQUE_PRIVATE_DATA |
289 | | }; |
290 | | |
291 | | // --------------------------------------------------------------------------- |
292 | | |
293 | | class IdentifiedObject; |
294 | | /** Shared pointer of IdentifiedObject. */ |
295 | | using IdentifiedObjectPtr = std::shared_ptr<IdentifiedObject>; |
296 | | /** Non-null shared pointer of IdentifiedObject. */ |
297 | | using IdentifiedObjectNNPtr = util::nn<IdentifiedObjectPtr>; |
298 | | |
299 | | /** \brief Abstract class representing a CRS-related object that has an |
300 | | * identification. |
301 | | * |
302 | | * \remark Implements IdentifiedObject from \ref ISO_19111_2019 |
303 | | */ |
304 | | class PROJ_GCC_DLL IdentifiedObject : public util::BaseObject, |
305 | | public util::IComparable, |
306 | | public io::IWKTExportable { |
307 | | public: |
308 | | //! @cond Doxygen_Suppress |
309 | | PROJ_DLL ~IdentifiedObject() override; |
310 | | //! @endcond |
311 | | |
312 | | PROJ_DLL static const std::string NAME_KEY; |
313 | | PROJ_DLL static const std::string IDENTIFIERS_KEY; |
314 | | PROJ_DLL static const std::string ALIAS_KEY; |
315 | | PROJ_DLL static const std::string REMARKS_KEY; |
316 | | PROJ_DLL static const std::string DEPRECATED_KEY; |
317 | | |
318 | | // in practice only name().description() is used |
319 | | PROJ_DLL const metadata::IdentifierNNPtr &name() PROJ_PURE_DECL; |
320 | | PROJ_DLL const std::string &nameStr() PROJ_PURE_DECL; |
321 | | PROJ_DLL const std::vector<metadata::IdentifierNNPtr> & |
322 | | identifiers() PROJ_PURE_DECL; |
323 | | PROJ_DLL const std::vector<util::GenericNameNNPtr> & |
324 | | aliases() PROJ_PURE_DECL; |
325 | | PROJ_DLL const std::string &remarks() PROJ_PURE_DECL; |
326 | | |
327 | | // from Apache SIS AbstractIdentifiedObject |
328 | | PROJ_DLL bool isDeprecated() PROJ_PURE_DECL; |
329 | | |
330 | | // Non-standard |
331 | | PROJ_DLL std::string alias() PROJ_PURE_DECL; |
332 | | PROJ_DLL int getEPSGCode() PROJ_PURE_DECL; |
333 | | |
334 | | PROJ_PRIVATE : |
335 | | //! @cond Doxygen_Suppress |
336 | | void |
337 | | formatID(io::WKTFormatter *formatter) const; |
338 | | |
339 | | PROJ_INTERNAL void formatID(io::JSONFormatter *formatter) const; |
340 | | |
341 | | PROJ_INTERNAL void formatRemarks(io::WKTFormatter *formatter) const; |
342 | | |
343 | | PROJ_INTERNAL void formatRemarks(io::JSONFormatter *formatter) const; |
344 | | |
345 | | PROJ_INTERNAL bool _isEquivalentTo( |
346 | | const util::IComparable *other, |
347 | | util::IComparable::Criterion criterion = |
348 | | util::IComparable::Criterion::STRICT, |
349 | | const io::DatabaseContextPtr &dbContext = nullptr) const override; |
350 | | |
351 | | PROJ_INTERNAL bool _isEquivalentTo( |
352 | | const IdentifiedObject *other, |
353 | | util::IComparable::Criterion criterion = |
354 | | util::IComparable::Criterion::STRICT, |
355 | | const io::DatabaseContextPtr &dbContext = nullptr) PROJ_PURE_DECL; |
356 | | //! @endcond |
357 | | |
358 | | protected: |
359 | | PROJ_FRIEND_OPTIONAL(IdentifiedObject); |
360 | | INLINED_MAKE_SHARED |
361 | | IdentifiedObject(); |
362 | | IdentifiedObject(const IdentifiedObject &other); |
363 | | |
364 | | void setProperties(const util::PropertyMap |
365 | | &properties); // throw(InvalidValueTypeException) |
366 | | |
367 | | virtual bool hasEquivalentNameToUsingAlias( |
368 | | const IdentifiedObject *other, |
369 | | const io::DatabaseContextPtr &dbContext) const; |
370 | | |
371 | | private: |
372 | | PROJ_OPAQUE_PRIVATE_DATA |
373 | | IdentifiedObject &operator=(const IdentifiedObject &other) = delete; |
374 | | }; |
375 | | |
376 | | // --------------------------------------------------------------------------- |
377 | | |
378 | | class ObjectDomain; |
379 | | /** Shared pointer of ObjectDomain. */ |
380 | | using ObjectDomainPtr = std::shared_ptr<ObjectDomain>; |
381 | | /** Non-null shared pointer of ObjectDomain. */ |
382 | | using ObjectDomainNNPtr = util::nn<ObjectDomainPtr>; |
383 | | |
384 | | /** \brief The scope and validity of a CRS-related object. |
385 | | * |
386 | | * \remark Implements ObjectDomain from \ref ISO_19111_2019 |
387 | | */ |
388 | | class PROJ_GCC_DLL ObjectDomain : public util::BaseObject, |
389 | | public util::IComparable { |
390 | | public: |
391 | | //! @cond Doxygen_Suppress |
392 | | PROJ_DLL ~ObjectDomain() override; |
393 | | //! @endcond |
394 | | |
395 | | // In ISO_19111:2018, scope and domain are compulsory, but in WKT2:2015, |
396 | | // they |
397 | | // are not necessarily both specified |
398 | | PROJ_DLL const util::optional<std::string> &scope() PROJ_PURE_DECL; |
399 | | PROJ_DLL const metadata::ExtentPtr &domainOfValidity() PROJ_PURE_DECL; |
400 | | |
401 | | PROJ_DLL static ObjectDomainNNPtr |
402 | | create(const util::optional<std::string> &scopeIn, |
403 | | const metadata::ExtentPtr &extent); |
404 | | |
405 | | PROJ_PRIVATE : |
406 | | //! @cond Doxygen_Suppress |
407 | | void |
408 | | _exportToWKT(io::WKTFormatter *formatter) |
409 | | const; // throw(io::FormattingException) |
410 | | |
411 | | PROJ_INTERNAL void _exportToJSON( |
412 | | io::JSONFormatter *formatter) const; // throw(FormattingException) |
413 | | |
414 | | bool _isEquivalentTo( |
415 | | const util::IComparable *other, |
416 | | util::IComparable::Criterion criterion = |
417 | | util::IComparable::Criterion::STRICT, |
418 | | const io::DatabaseContextPtr &dbContext = nullptr) const override; |
419 | | //! @endcond |
420 | | |
421 | | protected: |
422 | | //! @cond Doxygen_Suppress |
423 | | ObjectDomain(const util::optional<std::string> &scopeIn, |
424 | | const metadata::ExtentPtr &extent); |
425 | | //! @endcond |
426 | | |
427 | | ObjectDomain(const ObjectDomain &other); |
428 | | INLINED_MAKE_SHARED |
429 | | |
430 | | private: |
431 | | PROJ_OPAQUE_PRIVATE_DATA |
432 | | ObjectDomain &operator=(const ObjectDomain &other) = delete; |
433 | | }; |
434 | | |
435 | | // --------------------------------------------------------------------------- |
436 | | |
437 | | class ObjectUsage; |
438 | | /** Shared pointer of ObjectUsage. */ |
439 | | using ObjectUsagePtr = std::shared_ptr<ObjectUsage>; |
440 | | /** Non-null shared pointer of ObjectUsage. */ |
441 | | using ObjectUsageNNPtr = util::nn<ObjectUsagePtr>; |
442 | | |
443 | | /** \brief Abstract class of a CRS-related object that has usages. |
444 | | * |
445 | | * \remark Implements ObjectUsage from \ref ISO_19111_2019 |
446 | | */ |
447 | | class PROJ_GCC_DLL ObjectUsage : public IdentifiedObject { |
448 | | public: |
449 | | //! @cond Doxygen_Suppress |
450 | | PROJ_DLL ~ObjectUsage() override; |
451 | | //! @endcond |
452 | | |
453 | | PROJ_DLL const std::vector<ObjectDomainNNPtr> &domains() PROJ_PURE_DECL; |
454 | | |
455 | | PROJ_DLL static const std::string SCOPE_KEY; |
456 | | PROJ_DLL static const std::string DOMAIN_OF_VALIDITY_KEY; |
457 | | |
458 | | PROJ_DLL static const std::string OBJECT_DOMAIN_KEY; |
459 | | |
460 | | //! @cond Doxygen_Suppress |
461 | | bool _isEquivalentTo( |
462 | | const util::IComparable *other, |
463 | | util::IComparable::Criterion criterion = |
464 | | util::IComparable::Criterion::STRICT, |
465 | | const io::DatabaseContextPtr &dbContext = nullptr) const override; |
466 | | //! @endcond |
467 | | |
468 | | protected: |
469 | | ObjectUsage(); |
470 | | ObjectUsage(const ObjectUsage &other); |
471 | | void setProperties(const util::PropertyMap |
472 | | &properties); // throw(InvalidValueTypeException) |
473 | | |
474 | | void baseExportToWKT( |
475 | | io::WKTFormatter *formatter) const; // throw(io::FormattingException) |
476 | | |
477 | | void baseExportToJSON( |
478 | | io::JSONFormatter *formatter) const; // throw(io::FormattingException) |
479 | | |
480 | | private: |
481 | | PROJ_OPAQUE_PRIVATE_DATA |
482 | | ObjectUsage &operator=(const ObjectUsage &other) = delete; |
483 | | }; |
484 | | |
485 | | } // namespace common |
486 | | |
487 | | NS_PROJ_END |
488 | | |
489 | | #endif // COMMON_HH_INCLUDED |