PROJ C++ API
common.hpp
1 /******************************************************************************
2  *
3  * Project: PROJ
4  * Purpose: ISO19111:2018 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 
46 namespace common {
47 
48 // ---------------------------------------------------------------------------
49 
50 class UnitOfMeasure;
52 using UnitOfMeasurePtr = std::shared_ptr<UnitOfMeasure>;
54 using UnitOfMeasureNNPtr = util::nn<UnitOfMeasurePtr>;
55 
61  public:
63  enum class PROJ_DLL Type {
65  UNKNOWN,
67  NONE,
69  ANGULAR,
71  LINEAR,
73  SCALE,
75  TIME,
77  PARAMETRIC,
78  };
79 
80  PROJ_DLL UnitOfMeasure(const std::string &nameIn = std::string(),
81  double toSIIn = 1.0, Type typeIn = Type::UNKNOWN,
82  const std::string &codeSpaceIn = std::string(),
83  const std::string &codeIn = std::string());
84 
86  PROJ_DLL UnitOfMeasure(const UnitOfMeasure &other);
87  PROJ_DLL ~UnitOfMeasure() override;
88  PROJ_DLL UnitOfMeasure &operator=(const UnitOfMeasure &other);
89  static UnitOfMeasureNNPtr create(const UnitOfMeasure &other);
91 
92  PROJ_DLL const std::string &name() PROJ_PURE_DECL;
93  PROJ_DLL double conversionToSI() PROJ_PURE_DECL;
94  PROJ_DLL Type type() PROJ_PURE_DECL;
95 
96  PROJ_DLL const std::string &codeSpace() PROJ_PURE_DECL;
97  PROJ_DLL const std::string &code() PROJ_PURE_DECL;
98 
99  PROJ_DLL bool operator==(const UnitOfMeasure &other) PROJ_PURE_DECL;
100  PROJ_DLL bool operator!=(const UnitOfMeasure &other) PROJ_PURE_DECL;
101 
103  void _exportToWKT(io::WKTFormatter *formatter,
104  const std::string &unitType = std::string())
105  const; // throw(io::FormattingException)
106 
107  std::string exportToPROJString() const;
109 
110  PROJ_DLL static const UnitOfMeasure NONE;
111 
112  PROJ_DLL static const UnitOfMeasure SCALE_UNITY;
113  PROJ_DLL static const UnitOfMeasure PARTS_PER_MILLION;
114  PROJ_DLL static const UnitOfMeasure PPM_PER_YEAR;
115 
116  PROJ_DLL static const UnitOfMeasure METRE;
117  PROJ_DLL static const UnitOfMeasure METRE_PER_YEAR;
118 
119  PROJ_DLL static const UnitOfMeasure RADIAN;
120  PROJ_DLL static const UnitOfMeasure MICRORADIAN;
121  PROJ_DLL static const UnitOfMeasure DEGREE;
122  PROJ_DLL static const UnitOfMeasure ARC_SECOND;
123  PROJ_DLL static const UnitOfMeasure GRAD;
124  PROJ_DLL static const UnitOfMeasure ARC_SECOND_PER_YEAR;
125 
126  PROJ_DLL static const UnitOfMeasure SECOND;
127  PROJ_DLL static const UnitOfMeasure YEAR;
128 
129  private:
130  PROJ_OPAQUE_PRIVATE_DATA
131 };
132 
133 // ---------------------------------------------------------------------------
134 
136 class Measure : public util::BaseObject {
137  public:
138  PROJ_DLL Measure(double valueIn = 0.0,
139  const UnitOfMeasure &unitIn = UnitOfMeasure());
140 
142  PROJ_DLL Measure(const Measure &other);
143  PROJ_DLL ~Measure();
145 
146  PROJ_DLL const UnitOfMeasure &unit() PROJ_CONST_DECL;
147  PROJ_DLL double getSIValue() PROJ_CONST_DECL;
148  PROJ_DLL double value() PROJ_CONST_DECL;
149 
150  PROJ_DLL double
151  convertToUnit(const UnitOfMeasure &otherUnit) PROJ_CONST_DECL;
152 
153  PROJ_DLL bool operator==(const Measure &other) PROJ_CONST_DECL;
154 
155  PROJ_DLL bool
156  isEquivalentTo(const Measure &other,
157  util::IComparable::Criterion criterion =
158  util::IComparable::Criterion::STRICT) const;
159 
160  private:
161  PROJ_OPAQUE_PRIVATE_DATA
162  Measure &operator=(const Measure &) = delete;
163 };
164 
165 // ---------------------------------------------------------------------------
166 
168 class Scale : public Measure {
169  public:
170  PROJ_DLL explicit Scale(double valueIn = 0.0);
171  PROJ_DLL explicit Scale(double valueIn, const UnitOfMeasure &unitIn);
172 
174  PROJ_DLL Scale(const Scale &other);
175  PROJ_DLL ~Scale() override;
177 
178  protected:
179  PROJ_FRIEND_OPTIONAL(Scale);
180  Scale &operator=(const Scale &) = delete;
181 };
182 
183 // ---------------------------------------------------------------------------
184 
186 class Angle : public Measure {
187  public:
188  PROJ_DLL explicit Angle(double valueIn = 0.0);
189  PROJ_DLL Angle(double valueIn, const UnitOfMeasure &unitIn);
190 
192  PROJ_DLL Angle(const Angle &other);
193  PROJ_DLL ~Angle() override;
195 
196  protected:
197  PROJ_FRIEND_OPTIONAL(Angle);
198  Angle &operator=(const Angle &) = delete;
199 };
200 
201 // ---------------------------------------------------------------------------
202 
204 class Length : public Measure {
205  public:
206  PROJ_DLL explicit Length(double valueIn = 0.0);
207  PROJ_DLL Length(double valueIn, const UnitOfMeasure &unitIn);
208 
210  PROJ_DLL Length(const Length &other);
211  PROJ_DLL ~Length() override;
213 
214  protected:
215  PROJ_FRIEND_OPTIONAL(Length);
216  Length &operator=(const Length &) = delete;
217 };
218 
219 // ---------------------------------------------------------------------------
220 
223 class DateTime {
224  public:
226  PROJ_DLL DateTime(const DateTime &other);
227  PROJ_DLL ~DateTime();
229 
230  PROJ_DLL bool isISO_8601() const;
231  PROJ_DLL std::string toString() const;
232 
233  PROJ_DLL static DateTime
234  create(const std::string &str); // may throw Exception
235 
236  protected:
237  DateTime();
238  PROJ_FRIEND_OPTIONAL(DateTime);
239 
240  private:
241  explicit DateTime(const std::string &str);
242  DateTime &operator=(const DateTime &other) = delete;
243 
244  PROJ_OPAQUE_PRIVATE_DATA
245 };
246 
247 // ---------------------------------------------------------------------------
248 
250 class DataEpoch {
251  // FIXME
252  public:
254  Measure coordinateEpoch{};
255 };
256 
257 // ---------------------------------------------------------------------------
258 
259 class IdentifiedObject;
261 using IdentifiedObjectPtr = std::shared_ptr<IdentifiedObject>;
263 using IdentifiedObjectNNPtr = util::nn<IdentifiedObjectPtr>;
264 
270  public:
272  PROJ_DLL ~IdentifiedObject() override;
274 
275  PROJ_DLL static IdentifiedObjectNNPtr
276  create(const util::PropertyMap
277  &properties); // throw(InvalidValueTypeException)
278 
279  PROJ_DLL static const std::string NAME_KEY;
280  PROJ_DLL static const std::string IDENTIFIERS_KEY;
281  PROJ_DLL static const std::string ALIAS_KEY;
282  PROJ_DLL static const std::string REMARKS_KEY;
283  PROJ_DLL static const std::string DEPRECATED_KEY;
284 
285  // in practice only name().description() is used
286  PROJ_DLL const metadata::IdentifierNNPtr &name() PROJ_CONST_DECL;
287  PROJ_DLL const std::string &nameStr() PROJ_CONST_DECL;
288  PROJ_DLL const std::vector<metadata::IdentifierNNPtr> &
289  identifiers() PROJ_CONST_DECL;
290  PROJ_DLL const std::vector<util::GenericNameNNPtr> &
291  aliases() PROJ_CONST_DECL;
292  PROJ_DLL const std::string &remarks() PROJ_CONST_DECL;
293 
294  // from Apache SIS AbstractIdentifiedObject
295  PROJ_DLL bool isDeprecated() PROJ_CONST_DECL;
296 
297  // Non-standard
298  PROJ_DLL std::string alias() PROJ_CONST_DECL;
299  PROJ_DLL int getEPSGCode() PROJ_CONST_DECL;
300  PROJ_DLL bool isEPSG(int code) PROJ_CONST_DECL;
301 
302  PROJ_PRIVATE :
304  void
305  formatID(io::WKTFormatter *formatter) const;
306  void formatRemarks(io::WKTFormatter *formatter) const;
307 
308  bool
309  isEquivalentTo(const util::IComparable *other,
310  util::IComparable::Criterion criterion =
311  util::IComparable::Criterion::STRICT) const override;
312 
313  bool
314  isEquivalentTo(const IdentifiedObject *other,
315  util::IComparable::Criterion criterion =
316  util::IComparable::Criterion::STRICT) PROJ_CONST_DECL;
318 
319  protected:
320  PROJ_FRIEND_OPTIONAL(IdentifiedObject);
321  INLINED_MAKE_SHARED
322  IdentifiedObject();
323  IdentifiedObject(const IdentifiedObject &other);
324 
325  void setProperties(const util::PropertyMap
326  &properties); // throw(InvalidValueTypeException)
327 
328  private:
329  PROJ_OPAQUE_PRIVATE_DATA
330  IdentifiedObject &operator=(const IdentifiedObject &other) = delete;
331 };
332 
333 // ---------------------------------------------------------------------------
334 
335 class ObjectDomain;
337 using ObjectDomainPtr = std::shared_ptr<ObjectDomain>;
340 
345 class ObjectDomain : public util::BaseObject, public util::IComparable {
346  public:
348  PROJ_DLL ~ObjectDomain() override;
350 
351  // In ISO_19111:2018, scope and domain are compulsory, but in WKT2:2015,
352  // they
353  // are not necessarily both specified
354  PROJ_DLL const util::optional<std::string> &scope() PROJ_CONST_DECL;
355  PROJ_DLL const metadata::ExtentPtr &domainOfValidity() PROJ_CONST_DECL;
356 
357  PROJ_DLL static ObjectDomainNNPtr
358  create(const util::optional<std::string> &scopeIn,
359  const metadata::ExtentPtr &extent);
360 
361  PROJ_DLL bool
362  isEquivalentTo(const util::IComparable *other,
363  util::IComparable::Criterion criterion =
364  util::IComparable::Criterion::STRICT) const override;
365 
366  PROJ_PRIVATE :
368  void
369  _exportToWKT(io::WKTFormatter *formatter)
370  const; // throw(io::FormattingException)
372 
373  protected:
375  ObjectDomain(const util::optional<std::string> &scopeIn,
376  const metadata::ExtentPtr &extent);
378 
379  ObjectDomain(const ObjectDomain &other);
380  INLINED_MAKE_SHARED
381 
382  private:
383  PROJ_OPAQUE_PRIVATE_DATA
384  ObjectDomain &operator=(const ObjectDomain &other) = delete;
385 };
386 
387 // ---------------------------------------------------------------------------
388 
389 class ObjectUsage;
391 using ObjectUsagePtr = std::shared_ptr<ObjectUsage>;
393 using ObjectUsageNNPtr = util::nn<ObjectUsagePtr>;
394 
400  public:
402  PROJ_DLL ~ObjectUsage() override;
404 
405  PROJ_DLL const std::vector<ObjectDomainNNPtr> &domains() PROJ_CONST_DECL;
406 
407  PROJ_DLL static const std::string SCOPE_KEY;
408  PROJ_DLL static const std::string DOMAIN_OF_VALIDITY_KEY;
409 
410  PROJ_DLL static const std::string OBJECT_DOMAIN_KEY;
411 
412  bool
413  isEquivalentTo(const util::IComparable *other,
414  util::IComparable::Criterion criterion =
415  util::IComparable::Criterion::STRICT) const override;
416 
417  protected:
418  ObjectUsage();
419  ObjectUsage(const ObjectUsage &other);
420  void setProperties(const util::PropertyMap
421  &properties); // throw(InvalidValueTypeException)
422 
423  void baseExportToWKT(
424  io::WKTFormatter *formatter) const; // throw(io::FormattingException)
425 
426  private:
427  PROJ_OPAQUE_PRIVATE_DATA
428  ObjectUsage &operator=(const ObjectUsage &other) = delete;
429 };
430 
431 } // namespace common
432 
433 NS_PROJ_END
434 
435 #endif // COMMON_HH_INCLUDED
util::nn< UnitOfMeasurePtr > UnitOfMeasureNNPtr
Definition: common.hpp:54
static const std::string SCOPE_KEY
Key to set the scope of a common::ObjectUsage.
Definition: common.hpp:407
static const UnitOfMeasure PARTS_PER_MILLION
Parts-per-million, unit of measure of type SCALE.
Definition: common.hpp:113
Interface for an object that can be compared to another.
Definition: util.hpp:292
static const UnitOfMeasure YEAR
Year, unit of measure of type TIME.
Definition: common.hpp:127
static const UnitOfMeasure DEGREE
Degree, unit of measure of type ANGULAR.
Definition: common.hpp:121
static const UnitOfMeasure SCALE_UNITY
Scale unity, unit of measure of type SCALE.
Definition: common.hpp:112
std::shared_ptr< ObjectDomain > ObjectDomainPtr
Definition: common.hpp:337
static const UnitOfMeasure METRE
Metre, unit of measure of type LINEAR (SI unit).
Definition: common.hpp:116
static const UnitOfMeasure PPM_PER_YEAR
Part-sper-million per year, unit of measure of type SCALE.
Definition: common.hpp:114
Data epoch.
Definition: common.hpp:250
Numeric value associated with a UnitOfMeasure.
Definition: common.hpp:136
static const std::string OBJECT_DOMAIN_KEY
Key to set the object domain(s) of a common::ObjectUsage.
Definition: common.hpp:410
Usage of a CRS-related object.
Definition: common.hpp:399
static const UnitOfMeasure MICRORADIAN
Microradian, unit of measure of type ANGULAR.
Definition: common.hpp:120
util::nn< IdentifierPtr > IdentifierNNPtr
Definition: metadata.hpp:339
static const std::string IDENTIFIERS_KEY
Key to set the identifier(s) of a common::IdentifiedObject.
Definition: common.hpp:280
Numeric value, with a linear unit of measure.
Definition: common.hpp:204
Criterion
Comparison criterion.
Definition: util.hpp:299
std::shared_ptr< Extent > ExtentPtr
Definition: io.hpp:56
Date-time value, as a ISO:8601 encoded string, or other string encoding.
Definition: common.hpp:223
static const UnitOfMeasure SECOND
Second, unit of measure of type TIME (SI unit).
Definition: common.hpp:126
static const UnitOfMeasure GRAD
Grad, unit of measure of type ANGULAR.
Definition: common.hpp:123
static const std::string DEPRECATED_KEY
Key to set the deprecation flag of a common::IdentifiedObject.
Definition: common.hpp:283
static const UnitOfMeasure ARC_SECOND
Arc-second, unit of measure of type ANGULAR.
Definition: common.hpp:122
static const std::string ALIAS_KEY
Key to set the alias(es) of a common::IdentifiedObject.
Definition: common.hpp:281
static const std::string NAME_KEY
Key to set the name of a common::IdentifiedObject.
Definition: common.hpp:279
std::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
Definition: common.hpp:52
Wrapper of a std::map<std::string, BaseObjectNNPtr>
Definition: util.hpp:410
The scope and validity of a CRS-related object.
Definition: common.hpp:345
Class that can be derived from, to emulate Java&#39;s Object behaviour.
Definition: util.hpp:268
util::nn< ObjectUsagePtr > ObjectUsageNNPtr
Definition: common.hpp:393
util::nn< IdentifiedObjectPtr > IdentifiedObjectNNPtr
Definition: common.hpp:263
static const std::string DOMAIN_OF_VALIDITY_KEY
Key to set the domain of validity of a common::ObjectUsage.
Definition: common.hpp:408
static const std::string REMARKS_KEY
Key to set the remarks of a common::IdentifiedObject.
Definition: common.hpp:282
Numeric value, with a angular unit of measure.
Definition: common.hpp:186
std::shared_ptr< IdentifiedObject > IdentifiedObjectPtr
Definition: common.hpp:261
static const UnitOfMeasure METRE_PER_YEAR
Metre per year, unit of measure of type LINEAR.
Definition: common.hpp:117
static const UnitOfMeasure RADIAN
Radian, unit of measure of type ANGULAR (SI unit).
Definition: common.hpp:119
Numeric value, without a physical unit of measure.
Definition: common.hpp:168
Unit of measure.
Definition: common.hpp:60
Type
Type of unit of measure.
Definition: common.hpp:63
util::nn< ObjectDomainPtr > ObjectDomainNNPtr
Definition: common.hpp:339
Formatter to WKT strings.
Definition: io.hpp:143
Loose transposition of std::optional available from C++17.
Definition: util.hpp:178
static const UnitOfMeasure NONE
"Empty"/"None", unit of measure of type NONE.
Definition: common.hpp:110
static const UnitOfMeasure ARC_SECOND_PER_YEAR
Arc-second per year, unit of measure of type ANGULAR.
Definition: common.hpp:124
std::shared_ptr< ObjectUsage > ObjectUsagePtr
Definition: common.hpp:391
Identifications of a CRS-related object.
Definition: common.hpp:269