Coverage Report

Created: 2024-02-25 06:14

/src/PROJ/include/proj/io.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 IO_HH_INCLUDED
30
#define IO_HH_INCLUDED
31
32
#include <list>
33
#include <memory>
34
#include <set>
35
#include <string>
36
#include <utility>
37
#include <vector>
38
39
#include "proj.h"
40
41
#include "util.hpp"
42
43
NS_PROJ_START
44
45
class CPLJSonStreamingWriter;
46
47
namespace common {
48
class UnitOfMeasure;
49
using UnitOfMeasurePtr = std::shared_ptr<UnitOfMeasure>;
50
using UnitOfMeasureNNPtr = util::nn<UnitOfMeasurePtr>;
51
52
class IdentifiedObject;
53
using IdentifiedObjectPtr = std::shared_ptr<IdentifiedObject>;
54
using IdentifiedObjectNNPtr = util::nn<IdentifiedObjectPtr>;
55
} // namespace common
56
57
namespace cs {
58
class CoordinateSystem;
59
using CoordinateSystemPtr = std::shared_ptr<CoordinateSystem>;
60
using CoordinateSystemNNPtr = util::nn<CoordinateSystemPtr>;
61
} // namespace cs
62
63
namespace metadata {
64
class Extent;
65
using ExtentPtr = std::shared_ptr<Extent>;
66
using ExtentNNPtr = util::nn<ExtentPtr>;
67
} // namespace metadata
68
69
namespace datum {
70
class Datum;
71
using DatumPtr = std::shared_ptr<Datum>;
72
using DatumNNPtr = util::nn<DatumPtr>;
73
74
class DatumEnsemble;
75
using DatumEnsemblePtr = std::shared_ptr<DatumEnsemble>;
76
using DatumEnsembleNNPtr = util::nn<DatumEnsemblePtr>;
77
78
class Ellipsoid;
79
using EllipsoidPtr = std::shared_ptr<Ellipsoid>;
80
using EllipsoidNNPtr = util::nn<EllipsoidPtr>;
81
82
class PrimeMeridian;
83
using PrimeMeridianPtr = std::shared_ptr<PrimeMeridian>;
84
using PrimeMeridianNNPtr = util::nn<PrimeMeridianPtr>;
85
86
class GeodeticReferenceFrame;
87
using GeodeticReferenceFramePtr = std::shared_ptr<GeodeticReferenceFrame>;
88
using GeodeticReferenceFrameNNPtr = util::nn<GeodeticReferenceFramePtr>;
89
90
class VerticalReferenceFrame;
91
using VerticalReferenceFramePtr = std::shared_ptr<VerticalReferenceFrame>;
92
using VerticalReferenceFrameNNPtr = util::nn<VerticalReferenceFramePtr>;
93
} // namespace datum
94
95
namespace crs {
96
class CRS;
97
using CRSPtr = std::shared_ptr<CRS>;
98
using CRSNNPtr = util::nn<CRSPtr>;
99
100
class GeodeticCRS;
101
using GeodeticCRSPtr = std::shared_ptr<GeodeticCRS>;
102
using GeodeticCRSNNPtr = util::nn<GeodeticCRSPtr>;
103
104
class GeographicCRS;
105
using GeographicCRSPtr = std::shared_ptr<GeographicCRS>;
106
using GeographicCRSNNPtr = util::nn<GeographicCRSPtr>;
107
108
class VerticalCRS;
109
using VerticalCRSPtr = std::shared_ptr<VerticalCRS>;
110
using VerticalCRSNNPtr = util::nn<VerticalCRSPtr>;
111
112
class ProjectedCRS;
113
using ProjectedCRSPtr = std::shared_ptr<ProjectedCRS>;
114
using ProjectedCRSNNPtr = util::nn<ProjectedCRSPtr>;
115
116
class CompoundCRS;
117
using CompoundCRSPtr = std::shared_ptr<CompoundCRS>;
118
using CompoundCRSNNPtr = util::nn<CompoundCRSPtr>;
119
} // namespace crs
120
121
namespace coordinates {
122
class CoordinateMetadata;
123
/** Shared pointer of CoordinateMetadata */
124
using CoordinateMetadataPtr = std::shared_ptr<CoordinateMetadata>;
125
/** Non-null shared pointer of CoordinateMetadata */
126
using CoordinateMetadataNNPtr = util::nn<CoordinateMetadataPtr>;
127
} // namespace coordinates
128
129
namespace operation {
130
class Conversion;
131
using ConversionPtr = std::shared_ptr<Conversion>;
132
using ConversionNNPtr = util::nn<ConversionPtr>;
133
134
class CoordinateOperation;
135
using CoordinateOperationPtr = std::shared_ptr<CoordinateOperation>;
136
using CoordinateOperationNNPtr = util::nn<CoordinateOperationPtr>;
137
138
class PointMotionOperation;
139
using PointMotionOperationPtr = std::shared_ptr<PointMotionOperation>;
140
using PointMotionOperationNNPtr = util::nn<PointMotionOperationPtr>;
141
} // namespace operation
142
143
/** osgeo.proj.io namespace.
144
 *
145
 * \brief I/O classes
146
 */
147
namespace io {
148
149
class DatabaseContext;
150
/** Shared pointer of DatabaseContext. */
151
using DatabaseContextPtr = std::shared_ptr<DatabaseContext>;
152
/** Non-null shared pointer of DatabaseContext. */
153
using DatabaseContextNNPtr = util::nn<DatabaseContextPtr>;
154
155
// ---------------------------------------------------------------------------
156
157
class WKTNode;
158
/** Unique pointer of WKTNode. */
159
using WKTNodePtr = std::unique_ptr<WKTNode>;
160
/** Non-null unique pointer of WKTNode. */
161
using WKTNodeNNPtr = util::nn<WKTNodePtr>;
162
163
// ---------------------------------------------------------------------------
164
165
class WKTFormatter;
166
/** WKTFormatter unique pointer. */
167
using WKTFormatterPtr = std::unique_ptr<WKTFormatter>;
168
/** Non-null WKTFormatter unique pointer. */
169
using WKTFormatterNNPtr = util::nn<WKTFormatterPtr>;
170
171
/** \brief Formatter to WKT strings.
172
 *
173
 * An instance of this class can only be used by a single
174
 * thread at a time.
175
 */
176
class PROJ_GCC_DLL WKTFormatter {
177
  public:
178
    /** WKT variant. */
179
    enum class PROJ_MSVC_DLL Convention {
180
        /** Full WKT2 string, conforming to ISO 19162:2015(E) / OGC 12-063r5
181
         * (\ref WKT2_2015) with all possible nodes and new keyword names.
182
         */
183
        WKT2,
184
        WKT2_2015 = WKT2,
185
186
        /** Same as WKT2 with the following exceptions:
187
         * <ul>
188
         *      <li>UNIT keyword used.</li>
189
         *      <li>ID node only on top element.</li>
190
         *      <li>No ORDER element in AXIS element.</li>
191
         *      <li>PRIMEM node omitted if it is Greenwich.</li>
192
         *      <li>ELLIPSOID.UNIT node omitted if it is
193
         * UnitOfMeasure::METRE.</li>
194
         *      <li>PARAMETER.UNIT / PRIMEM.UNIT omitted if same as AXIS.</li>
195
         *      <li>AXIS.UNIT omitted and replaced by a common GEODCRS.UNIT if
196
         * they are all the same on all axis.</li>
197
         * </ul>
198
         */
199
        WKT2_SIMPLIFIED,
200
        WKT2_2015_SIMPLIFIED = WKT2_SIMPLIFIED,
201
202
        /** Full WKT2 string, conforming to ISO 19162:2019 / OGC 18-010, with
203
         * (\ref WKT2_2019) all possible nodes and new keyword names.
204
         * Non-normative list of differences:
205
         * <ul>
206
         *      <li>WKT2_2019 uses GEOGCRS / BASEGEOGCRS keywords for
207
         * GeographicCRS.</li>
208
         * </ul>
209
         */
210
        WKT2_2019,
211
212
        /** Deprecated alias for WKT2_2019 */
213
        WKT2_2018 = WKT2_2019,
214
215
        /** WKT2_2019 with the simplification rule of WKT2_SIMPLIFIED */
216
        WKT2_2019_SIMPLIFIED,
217
218
        /** Deprecated alias for WKT2_2019_SIMPLIFIED */
219
        WKT2_2018_SIMPLIFIED = WKT2_2019_SIMPLIFIED,
220
221
        /** WKT1 as traditionally output by GDAL, deriving from OGC 01-009.
222
            A notable departure from WKT1_GDAL with respect to OGC 01-009 is
223
            that in WKT1_GDAL, the unit of the PRIMEM value is always degrees.
224
           */
225
        WKT1_GDAL,
226
227
        /** WKT1 as traditionally output by ESRI software,
228
         * deriving from OGC 99-049. */
229
        WKT1_ESRI,
230
    };
231
232
    PROJ_DLL static WKTFormatterNNPtr
233
    create(Convention convention = Convention::WKT2,
234
           DatabaseContextPtr dbContext = nullptr);
235
    PROJ_DLL static WKTFormatterNNPtr create(const WKTFormatterNNPtr &other);
236
    //! @cond Doxygen_Suppress
237
    PROJ_DLL ~WKTFormatter();
238
    //! @endcond
239
240
    PROJ_DLL WKTFormatter &setMultiLine(bool multiLine) noexcept;
241
    PROJ_DLL WKTFormatter &setIndentationWidth(int width) noexcept;
242
243
    /** Rule for output AXIS nodes */
244
    enum class OutputAxisRule {
245
        /** Always include AXIS nodes */
246
        YES,
247
        /** Never include AXIS nodes */
248
        NO,
249
        /** Includes them only on PROJCS node if it uses Easting/Northing
250
         *ordering. Typically used for WKT1_GDAL */
251
        WKT1_GDAL_EPSG_STYLE,
252
    };
253
254
    PROJ_DLL WKTFormatter &setOutputAxis(OutputAxisRule outputAxis) noexcept;
255
    PROJ_DLL WKTFormatter &setStrict(bool strict) noexcept;
256
    PROJ_DLL bool isStrict() const noexcept;
257
258
    PROJ_DLL WKTFormatter &
259
    setAllowEllipsoidalHeightAsVerticalCRS(bool allow) noexcept;
260
    PROJ_DLL bool isAllowedEllipsoidalHeightAsVerticalCRS() const noexcept;
261
262
    PROJ_DLL WKTFormatter &setAllowLINUNITNode(bool allow) noexcept;
263
    PROJ_DLL bool isAllowedLINUNITNode() const noexcept;
264
265
    PROJ_DLL const std::string &toString() const;
266
267
    PROJ_PRIVATE :
268
        //! @cond Doxygen_Suppress
269
        PROJ_DLL WKTFormatter &
270
        setOutputId(bool outputIdIn);
271
272
    PROJ_INTERNAL void enter();
273
    PROJ_INTERNAL void leave();
274
275
    PROJ_INTERNAL void startNode(const std::string &keyword, bool hasId);
276
    PROJ_INTERNAL void endNode();
277
278
    PROJ_INTERNAL bool isAtTopLevel() const;
279
280
    PROJ_DLL WKTFormatter &simulCurNodeHasId();
281
282
    PROJ_INTERNAL void addQuotedString(const char *str);
283
    PROJ_INTERNAL void addQuotedString(const std::string &str);
284
    PROJ_INTERNAL void add(const std::string &str);
285
    PROJ_INTERNAL void add(int number);
286
    PROJ_INTERNAL void add(size_t number) = delete;
287
    PROJ_INTERNAL void add(double number, int precision = 15);
288
289
    PROJ_INTERNAL void pushOutputUnit(bool outputUnitIn);
290
    PROJ_INTERNAL void popOutputUnit();
291
    PROJ_INTERNAL bool outputUnit() const;
292
293
    PROJ_INTERNAL void pushOutputId(bool outputIdIn);
294
    PROJ_INTERNAL void popOutputId();
295
    PROJ_INTERNAL bool outputId() const;
296
297
    PROJ_INTERNAL void pushHasId(bool hasId);
298
    PROJ_INTERNAL void popHasId();
299
300
    PROJ_INTERNAL void pushDisableUsage();
301
    PROJ_INTERNAL void popDisableUsage();
302
    PROJ_INTERNAL bool outputUsage() const;
303
304
    PROJ_INTERNAL void
305
    pushAxisLinearUnit(const common::UnitOfMeasureNNPtr &unit);
306
    PROJ_INTERNAL void popAxisLinearUnit();
307
    PROJ_INTERNAL const common::UnitOfMeasureNNPtr &axisLinearUnit() const;
308
309
    PROJ_INTERNAL void
310
    pushAxisAngularUnit(const common::UnitOfMeasureNNPtr &unit);
311
    PROJ_INTERNAL void popAxisAngularUnit();
312
    PROJ_INTERNAL const common::UnitOfMeasureNNPtr &axisAngularUnit() const;
313
314
    PROJ_INTERNAL void setAbridgedTransformation(bool abriged);
315
    PROJ_INTERNAL bool abridgedTransformation() const;
316
317
    PROJ_INTERNAL void setUseDerivingConversion(bool useDerivingConversionIn);
318
    PROJ_INTERNAL bool useDerivingConversion() const;
319
320
    PROJ_INTERNAL void setTOWGS84Parameters(const std::vector<double> &params);
321
    PROJ_INTERNAL const std::vector<double> &getTOWGS84Parameters() const;
322
323
    PROJ_INTERNAL void setVDatumExtension(const std::string &filename);
324
    PROJ_INTERNAL const std::string &getVDatumExtension() const;
325
326
    PROJ_INTERNAL void setHDatumExtension(const std::string &filename);
327
    PROJ_INTERNAL const std::string &getHDatumExtension() const;
328
329
    PROJ_INTERNAL void
330
    setGeogCRSOfCompoundCRS(const crs::GeographicCRSPtr &crs);
331
    PROJ_INTERNAL const crs::GeographicCRSPtr &getGeogCRSOfCompoundCRS() const;
332
333
    PROJ_INTERNAL static std::string morphNameToESRI(const std::string &name);
334
335
#ifdef unused
336
    PROJ_INTERNAL void startInversion();
337
    PROJ_INTERNAL void stopInversion();
338
    PROJ_INTERNAL bool isInverted() const;
339
#endif
340
341
    PROJ_INTERNAL OutputAxisRule outputAxis() const;
342
    PROJ_INTERNAL bool outputAxisOrder() const;
343
    PROJ_INTERNAL bool primeMeridianOmittedIfGreenwich() const;
344
    PROJ_INTERNAL bool ellipsoidUnitOmittedIfMetre() const;
345
    PROJ_INTERNAL bool forceUNITKeyword() const;
346
    PROJ_INTERNAL bool primeMeridianOrParameterUnitOmittedIfSameAsAxis() const;
347
    PROJ_INTERNAL bool primeMeridianInDegree() const;
348
    PROJ_INTERNAL bool outputCSUnitOnlyOnceIfSame() const;
349
    PROJ_INTERNAL bool idOnTopLevelOnly() const;
350
    PROJ_INTERNAL bool topLevelHasId() const;
351
352
    /** WKT version. */
353
    enum class Version {
354
        /** WKT1 */
355
        WKT1,
356
        /** WKT2 / ISO 19162 */
357
        WKT2
358
    };
359
360
    PROJ_INTERNAL Version version() const;
361
    PROJ_INTERNAL bool use2019Keywords() const;
362
    PROJ_INTERNAL bool useESRIDialect() const;
363
364
    PROJ_INTERNAL const DatabaseContextPtr &databaseContext() const;
365
366
    PROJ_INTERNAL void ingestWKTNode(const WKTNodeNNPtr &node);
367
368
    //! @endcond
369
370
  protected:
371
    //! @cond Doxygen_Suppress
372
    PROJ_INTERNAL explicit WKTFormatter(Convention convention);
373
    WKTFormatter(const WKTFormatter &other) = delete;
374
375
    INLINED_MAKE_UNIQUE
376
    //! @endcond
377
378
  private:
379
    PROJ_OPAQUE_PRIVATE_DATA
380
};
381
382
// ---------------------------------------------------------------------------
383
384
class PROJStringFormatter;
385
/** PROJStringFormatter unique pointer. */
386
using PROJStringFormatterPtr = std::unique_ptr<PROJStringFormatter>;
387
/** Non-null PROJStringFormatter unique pointer. */
388
using PROJStringFormatterNNPtr = util::nn<PROJStringFormatterPtr>;
389
390
/** \brief Formatter to PROJ strings.
391
 *
392
 * An instance of this class can only be used by a single
393
 * thread at a time.
394
 */
395
class PROJ_GCC_DLL PROJStringFormatter {
396
  public:
397
    /** PROJ variant. */
398
    enum class PROJ_MSVC_DLL Convention {
399
        /** PROJ v5 (or later versions) string. */
400
        PROJ_5,
401
402
        /** PROJ v4 string as output by GDAL exportToProj4() */
403
        PROJ_4
404
    };
405
406
    PROJ_DLL static PROJStringFormatterNNPtr
407
    create(Convention conventionIn = Convention::PROJ_5,
408
           DatabaseContextPtr dbContext = nullptr);
409
    //! @cond Doxygen_Suppress
410
    PROJ_DLL ~PROJStringFormatter();
411
    //! @endcond
412
413
    PROJ_DLL PROJStringFormatter &setMultiLine(bool multiLine) noexcept;
414
    PROJ_DLL PROJStringFormatter &setIndentationWidth(int width) noexcept;
415
    PROJ_DLL PROJStringFormatter &setMaxLineLength(int maxLineLength) noexcept;
416
417
    PROJ_DLL void setUseApproxTMerc(bool flag);
418
419
    PROJ_DLL const std::string &toString() const;
420
421
    PROJ_PRIVATE :
422
        //! @cond Doxygen_Suppress
423
424
        PROJ_DLL void
425
        setCRSExport(bool b);
426
    PROJ_INTERNAL bool getCRSExport() const;
427
    PROJ_DLL void startInversion();
428
    PROJ_DLL void stopInversion();
429
    PROJ_INTERNAL bool isInverted() const;
430
    PROJ_INTERNAL bool getUseApproxTMerc() const;
431
    PROJ_INTERNAL void setCoordinateOperationOptimizations(bool enable);
432
433
    PROJ_DLL void
434
    ingestPROJString(const std::string &str); // throw ParsingException
435
436
    PROJ_DLL void addStep(const char *step);
437
    PROJ_DLL void addStep(const std::string &step);
438
    PROJ_DLL void setCurrentStepInverted(bool inverted);
439
    PROJ_DLL void addParam(const std::string &paramName);
440
    PROJ_DLL void addParam(const char *paramName, double val);
441
    PROJ_DLL void addParam(const std::string &paramName, double val);
442
    PROJ_DLL void addParam(const char *paramName, int val);
443
    PROJ_DLL void addParam(const std::string &paramName, int val);
444
    PROJ_DLL void addParam(const char *paramName, const char *val);
445
    PROJ_DLL void addParam(const char *paramName, const std::string &val);
446
    PROJ_DLL void addParam(const std::string &paramName, const char *val);
447
    PROJ_DLL void addParam(const std::string &paramName,
448
                           const std::string &val);
449
    PROJ_DLL void addParam(const char *paramName,
450
                           const std::vector<double> &vals);
451
452
    PROJ_INTERNAL bool hasParam(const char *paramName) const;
453
454
    PROJ_INTERNAL void addNoDefs(bool b);
455
    PROJ_INTERNAL bool getAddNoDefs() const;
456
457
    PROJ_INTERNAL std::set<std::string> getUsedGridNames() const;
458
459
    PROJ_INTERNAL void setTOWGS84Parameters(const std::vector<double> &params);
460
    PROJ_INTERNAL const std::vector<double> &getTOWGS84Parameters() const;
461
462
    PROJ_INTERNAL void setVDatumExtension(const std::string &filename,
463
                                          const std::string &geoidCRSValue);
464
    PROJ_INTERNAL const std::string &getVDatumExtension() const;
465
    PROJ_INTERNAL const std::string &getGeoidCRSValue() const;
466
467
    PROJ_INTERNAL void setHDatumExtension(const std::string &filename);
468
    PROJ_INTERNAL const std::string &getHDatumExtension() const;
469
470
    PROJ_INTERNAL void
471
    setGeogCRSOfCompoundCRS(const crs::GeographicCRSPtr &crs);
472
    PROJ_INTERNAL const crs::GeographicCRSPtr &getGeogCRSOfCompoundCRS() const;
473
474
    PROJ_INTERNAL void setOmitProjLongLatIfPossible(bool omit);
475
    PROJ_INTERNAL bool omitProjLongLatIfPossible() const;
476
477
    PROJ_INTERNAL void pushOmitZUnitConversion();
478
    PROJ_INTERNAL void popOmitZUnitConversion();
479
    PROJ_INTERNAL bool omitZUnitConversion() const;
480
481
    PROJ_INTERNAL void pushOmitHorizontalConversionInVertTransformation();
482
    PROJ_INTERNAL void popOmitHorizontalConversionInVertTransformation();
483
    PROJ_INTERNAL bool omitHorizontalConversionInVertTransformation() const;
484
485
    PROJ_INTERNAL void setLegacyCRSToCRSContext(bool legacyContext);
486
    PROJ_INTERNAL bool getLegacyCRSToCRSContext() const;
487
488
    PROJ_INTERNAL PROJStringFormatter &setNormalizeOutput();
489
490
    PROJ_INTERNAL const DatabaseContextPtr &databaseContext() const;
491
492
    PROJ_INTERNAL Convention convention() const;
493
494
    PROJ_INTERNAL size_t getStepCount() const;
495
496
    //! @endcond
497
498
  protected:
499
    //! @cond Doxygen_Suppress
500
    PROJ_INTERNAL explicit PROJStringFormatter(
501
        Convention conventionIn, const DatabaseContextPtr &dbContext);
502
    PROJStringFormatter(const PROJStringFormatter &other) = delete;
503
504
    INLINED_MAKE_UNIQUE
505
    //! @endcond
506
507
  private:
508
    PROJ_OPAQUE_PRIVATE_DATA
509
};
510
511
// ---------------------------------------------------------------------------
512
513
class JSONFormatter;
514
/** JSONFormatter unique pointer. */
515
using JSONFormatterPtr = std::unique_ptr<JSONFormatter>;
516
/** Non-null JSONFormatter unique pointer. */
517
using JSONFormatterNNPtr = util::nn<JSONFormatterPtr>;
518
519
/** \brief Formatter to JSON strings.
520
 *
521
 * An instance of this class can only be used by a single
522
 * thread at a time.
523
 */
524
class PROJ_GCC_DLL JSONFormatter {
525
  public:
526
    PROJ_DLL static JSONFormatterNNPtr
527
    create(DatabaseContextPtr dbContext = nullptr);
528
    //! @cond Doxygen_Suppress
529
    PROJ_DLL ~JSONFormatter();
530
    //! @endcond
531
532
    PROJ_DLL JSONFormatter &setMultiLine(bool multiLine) noexcept;
533
    PROJ_DLL JSONFormatter &setIndentationWidth(int width) noexcept;
534
    PROJ_DLL JSONFormatter &setSchema(const std::string &schema) noexcept;
535
536
    PROJ_DLL const std::string &toString() const;
537
538
    PROJ_PRIVATE :
539
540
        //! @cond Doxygen_Suppress
541
        PROJ_INTERNAL CPLJSonStreamingWriter *
542
        writer() const;
543
544
    PROJ_INTERNAL const DatabaseContextPtr &databaseContext() const;
545
546
    struct ObjectContext {
547
        JSONFormatter &m_formatter;
548
549
        ObjectContext(const ObjectContext &) = delete;
550
        ObjectContext(ObjectContext &&) = default;
551
552
        explicit ObjectContext(JSONFormatter &formatter, const char *objectType,
553
                               bool hasId);
554
        ~ObjectContext();
555
    };
556
    PROJ_INTERNAL inline ObjectContext MakeObjectContext(const char *objectType,
557
0
                                                         bool hasId) {
558
0
        return ObjectContext(*this, objectType, hasId);
559
0
    }
560
561
    PROJ_INTERNAL void setAllowIDInImmediateChild();
562
563
    PROJ_INTERNAL void setOmitTypeInImmediateChild();
564
565
    PROJ_INTERNAL void setAbridgedTransformation(bool abriged);
566
    PROJ_INTERNAL bool abridgedTransformation() const;
567
568
    PROJ_INTERNAL void setAbridgedTransformationWriteSourceCRS(bool writeCRS);
569
    PROJ_INTERNAL bool abridgedTransformationWriteSourceCRS() const;
570
571
    // cppcheck-suppress functionStatic
572
    PROJ_INTERNAL bool outputId() const;
573
574
    PROJ_INTERNAL bool
575
    outputUsage(bool calledBeforeObjectContext = false) const;
576
577
    PROJ_INTERNAL static const char *PROJJSON_v0_7;
578
579
    //! @endcond
580
581
  protected:
582
    //! @cond Doxygen_Suppress
583
    PROJ_INTERNAL explicit JSONFormatter();
584
    JSONFormatter(const JSONFormatter &other) = delete;
585
586
    INLINED_MAKE_UNIQUE
587
    //! @endcond
588
589
  private:
590
    PROJ_OPAQUE_PRIVATE_DATA
591
};
592
593
// ---------------------------------------------------------------------------
594
595
/** \brief Interface for an object that can be exported to JSON. */
596
class PROJ_GCC_DLL IJSONExportable {
597
  public:
598
    //! @cond Doxygen_Suppress
599
    PROJ_DLL virtual ~IJSONExportable();
600
    //! @endcond
601
602
    /** Builds a JSON representation. May throw a FormattingException */
603
    PROJ_DLL std::string
604
    exportToJSON(JSONFormatter *formatter) const; // throw(FormattingException)
605
606
    PROJ_PRIVATE :
607
608
        //! @cond Doxygen_Suppress
609
        PROJ_INTERNAL virtual void
610
        _exportToJSON(
611
            JSONFormatter *formatter) const = 0; // throw(FormattingException)
612
                                                 //! @endcond
613
};
614
615
// ---------------------------------------------------------------------------
616
617
/** \brief Exception possibly thrown by IWKTExportable::exportToWKT() or
618
 * IPROJStringExportable::exportToPROJString(). */
619
class PROJ_GCC_DLL FormattingException : public util::Exception {
620
  public:
621
    //! @cond Doxygen_Suppress
622
    PROJ_INTERNAL explicit FormattingException(const char *message);
623
    PROJ_INTERNAL explicit FormattingException(const std::string &message);
624
    PROJ_DLL FormattingException(const FormattingException &other);
625
    PROJ_DLL virtual ~FormattingException() override;
626
627
    PROJ_INTERNAL static void Throw(const char *msg) PROJ_NO_RETURN;
628
    PROJ_INTERNAL static void Throw(const std::string &msg) PROJ_NO_RETURN;
629
    //! @endcond
630
};
631
632
// ---------------------------------------------------------------------------
633
634
/** \brief Exception possibly thrown by WKTNode::createFrom() or
635
 * WKTParser::createFromWKT(). */
636
class PROJ_GCC_DLL ParsingException : public util::Exception {
637
  public:
638
    //! @cond Doxygen_Suppress
639
    PROJ_INTERNAL explicit ParsingException(const char *message);
640
    PROJ_INTERNAL explicit ParsingException(const std::string &message);
641
    PROJ_DLL ParsingException(const ParsingException &other);
642
    PROJ_DLL virtual ~ParsingException() override;
643
    //! @endcond
644
};
645
646
// ---------------------------------------------------------------------------
647
648
/** \brief Interface for an object that can be exported to WKT. */
649
class PROJ_GCC_DLL IWKTExportable {
650
  public:
651
    //! @cond Doxygen_Suppress
652
    PROJ_DLL virtual ~IWKTExportable();
653
    //! @endcond
654
655
    /** Builds a WKT representation. May throw a FormattingException */
656
    PROJ_DLL std::string
657
    exportToWKT(WKTFormatter *formatter) const; // throw(FormattingException)
658
659
    PROJ_PRIVATE :
660
661
        //! @cond Doxygen_Suppress
662
        PROJ_INTERNAL virtual void
663
        _exportToWKT(
664
            WKTFormatter *formatter) const = 0; // throw(FormattingException)
665
                                                //! @endcond
666
};
667
668
// ---------------------------------------------------------------------------
669
670
class IPROJStringExportable;
671
/** Shared pointer of IPROJStringExportable. */
672
using IPROJStringExportablePtr = std::shared_ptr<IPROJStringExportable>;
673
/** Non-null shared pointer of IPROJStringExportable. */
674
using IPROJStringExportableNNPtr = util::nn<IPROJStringExportablePtr>;
675
676
/** \brief Interface for an object that can be exported to a PROJ string. */
677
class PROJ_GCC_DLL IPROJStringExportable {
678
  public:
679
    //! @cond Doxygen_Suppress
680
    PROJ_DLL virtual ~IPROJStringExportable();
681
    //! @endcond
682
683
    /** \brief Builds a PROJ string representation.
684
     *
685
     * <ul>
686
     * <li>For PROJStringFormatter::Convention::PROJ_5 (the default),
687
     * <ul>
688
     * <li>For a crs::CRS, returns the same as
689
     * PROJStringFormatter::Convention::PROJ_4. It should be noted that the
690
     * export of a CRS as a PROJ string may cause loss of many important aspects
691
     * of a CRS definition. Consequently it is discouraged to use it for
692
     * interoperability in newer projects. The choice of a WKT representation
693
     * will be a better option.</li>
694
     * <li>For operation::CoordinateOperation, returns a PROJ
695
     * pipeline.</li>
696
     * </ul>
697
     *
698
     * <li>For PROJStringFormatter::Convention::PROJ_4, format a string
699
     * compatible with the OGRSpatialReference::exportToProj4() of GDAL
700
     * &lt;=2.3. It is only compatible of a few CRS objects. The PROJ string
701
     * will also contain a +type=crs parameter to disambiguate the nature of
702
     * the string from a CoordinateOperation.
703
     * <ul>
704
     * <li>For a crs::GeographicCRS, returns a proj=longlat string, with
705
     * ellipsoid / datum / prime meridian information, ignoring axis order
706
     * and unit information.</li>
707
     * <li>For a geocentric crs::GeodeticCRS, returns the transformation from
708
     * geographic coordinates into geocentric coordinates.</li>
709
     * <li>For a crs::ProjectedCRS, returns the projection method, ignoring
710
     * axis order.</li>
711
     * <li>For a crs::BoundCRS, returns the PROJ string of its source/base CRS,
712
     * amended with towgs84 / nadgrids parameter when the deriving conversion
713
     * can be expressed in that way.</li>
714
     * </ul>
715
     * </li>
716
     *
717
     * </ul>
718
     *
719
     * @param formatter PROJ string formatter.
720
     * @return a PROJ string.
721
     * @throw FormattingException */
722
    PROJ_DLL std::string exportToPROJString(
723
        PROJStringFormatter *formatter) const; // throw(FormattingException)
724
725
    PROJ_PRIVATE :
726
727
        //! @cond Doxygen_Suppress
728
        PROJ_INTERNAL virtual void
729
        _exportToPROJString(PROJStringFormatter *formatter)
730
            const = 0; // throw(FormattingException)
731
                       //! @endcond
732
};
733
734
// ---------------------------------------------------------------------------
735
736
/** \brief Node in the tree-splitted WKT representation.
737
 */
738
class PROJ_GCC_DLL WKTNode {
739
  public:
740
    PROJ_DLL explicit WKTNode(const std::string &valueIn);
741
    //! @cond Doxygen_Suppress
742
    PROJ_DLL ~WKTNode();
743
    //! @endcond
744
745
    PROJ_DLL const std::string &value() const;
746
    PROJ_DLL const std::vector<WKTNodeNNPtr> &children() const;
747
748
    PROJ_DLL void addChild(WKTNodeNNPtr &&child);
749
    PROJ_DLL const WKTNodePtr &lookForChild(const std::string &childName,
750
                                            int occurrence = 0) const noexcept;
751
    PROJ_DLL int
752
    countChildrenOfName(const std::string &childName) const noexcept;
753
754
    PROJ_DLL std::string toString() const;
755
756
    PROJ_DLL static WKTNodeNNPtr createFrom(const std::string &wkt,
757
                                            size_t indexStart = 0);
758
759
  protected:
760
    PROJ_INTERNAL static WKTNodeNNPtr
761
    createFrom(const std::string &wkt, size_t indexStart, int recLevel,
762
               size_t &indexEnd); // throw(ParsingException)
763
764
  private:
765
    friend class WKTParser;
766
    PROJ_OPAQUE_PRIVATE_DATA
767
};
768
769
// ---------------------------------------------------------------------------
770
771
PROJ_DLL util::BaseObjectNNPtr
772
createFromUserInput(const std::string &text,
773
                    const DatabaseContextPtr &dbContext,
774
                    bool usePROJ4InitRules = false);
775
776
PROJ_DLL util::BaseObjectNNPtr createFromUserInput(const std::string &text,
777
                                                   PJ_CONTEXT *ctx);
778
779
// ---------------------------------------------------------------------------
780
781
/** \brief Parse a WKT string into the appropriate subclass of util::BaseObject.
782
 */
783
class PROJ_GCC_DLL WKTParser {
784
  public:
785
    PROJ_DLL WKTParser();
786
    //! @cond Doxygen_Suppress
787
    PROJ_DLL ~WKTParser();
788
    //! @endcond
789
790
    PROJ_DLL WKTParser &
791
    attachDatabaseContext(const DatabaseContextPtr &dbContext);
792
793
    PROJ_DLL WKTParser &setStrict(bool strict);
794
    PROJ_DLL std::list<std::string> warningList() const;
795
796
    PROJ_DLL WKTParser &setUnsetIdentifiersIfIncompatibleDef(bool unset);
797
798
    PROJ_DLL util::BaseObjectNNPtr
799
    createFromWKT(const std::string &wkt); // throw(ParsingException)
800
801
    /** Guessed WKT "dialect" */
802
    enum class PROJ_MSVC_DLL WKTGuessedDialect {
803
        /** \ref WKT2_2019 */
804
        WKT2_2019,
805
        /** Deprecated alias for WKT2_2019 */
806
        WKT2_2018 = WKT2_2019,
807
        /** \ref WKT2_2015 */
808
        WKT2_2015,
809
        /** \ref WKT1 */
810
        WKT1_GDAL,
811
        /** ESRI variant of WKT1 */
812
        WKT1_ESRI,
813
        /** Not WKT / unrecognized */
814
        NOT_WKT
815
    };
816
817
    // cppcheck-suppress functionStatic
818
    PROJ_DLL WKTGuessedDialect guessDialect(const std::string &wkt) noexcept;
819
820
  private:
821
    PROJ_OPAQUE_PRIVATE_DATA
822
};
823
824
// ---------------------------------------------------------------------------
825
826
/** \brief Parse a PROJ string into the appropriate subclass of
827
 * util::BaseObject.
828
 */
829
class PROJ_GCC_DLL PROJStringParser {
830
  public:
831
    PROJ_DLL PROJStringParser();
832
    //! @cond Doxygen_Suppress
833
    PROJ_DLL ~PROJStringParser();
834
    //! @endcond
835
836
    PROJ_DLL PROJStringParser &
837
    attachDatabaseContext(const DatabaseContextPtr &dbContext);
838
839
    PROJ_DLL PROJStringParser &setUsePROJ4InitRules(bool enable);
840
841
    PROJ_DLL std::vector<std::string> warningList() const;
842
843
    PROJ_DLL util::BaseObjectNNPtr createFromPROJString(
844
        const std::string &projString); // throw(ParsingException)
845
846
    PROJ_PRIVATE :
847
        //! @cond Doxygen_Suppress
848
        PROJStringParser &
849
        attachContext(PJ_CONTEXT *ctx);
850
    //! @endcond
851
  private:
852
    PROJ_OPAQUE_PRIVATE_DATA
853
};
854
855
// ---------------------------------------------------------------------------
856
857
/** \brief Database context.
858
 *
859
 * A database context should be used only by one thread at a time.
860
 */
861
class PROJ_GCC_DLL DatabaseContext {
862
  public:
863
    //! @cond Doxygen_Suppress
864
    PROJ_DLL ~DatabaseContext();
865
    //! @endcond
866
867
    PROJ_DLL static DatabaseContextNNPtr
868
    create(const std::string &databasePath = std::string(),
869
           const std::vector<std::string> &auxiliaryDatabasePaths =
870
               std::vector<std::string>(),
871
           PJ_CONTEXT *ctx = nullptr);
872
873
    PROJ_DLL const std::string &getPath() const;
874
875
    PROJ_DLL const char *getMetadata(const char *key) const;
876
877
    PROJ_DLL std::set<std::string> getAuthorities() const;
878
879
    PROJ_DLL std::vector<std::string> getDatabaseStructure() const;
880
881
    PROJ_DLL void startInsertStatementsSession();
882
883
    PROJ_DLL std::string
884
    suggestsCodeFor(const common::IdentifiedObjectNNPtr &object,
885
                    const std::string &authName, bool numericCode);
886
887
    PROJ_DLL std::vector<std::string> getInsertStatementsFor(
888
        const common::IdentifiedObjectNNPtr &object,
889
        const std::string &authName, const std::string &code, bool numericCode,
890
        const std::vector<std::string> &allowedAuthorities = {"EPSG", "PROJ"});
891
892
    PROJ_DLL void stopInsertStatementsSession();
893
894
    PROJ_PRIVATE :
895
        //! @cond Doxygen_Suppress
896
        PROJ_DLL void *
897
        getSqliteHandle() const;
898
899
    PROJ_DLL static DatabaseContextNNPtr create(void *sqlite_handle);
900
901
    PROJ_INTERNAL bool lookForGridAlternative(const std::string &officialName,
902
                                              std::string &projFilename,
903
                                              std::string &projFormat,
904
                                              bool &inverse) const;
905
906
    PROJ_DLL bool lookForGridInfo(const std::string &projFilename,
907
                                  bool considerKnownGridsAsAvailable,
908
                                  std::string &fullFilename,
909
                                  std::string &packageName, std::string &url,
910
                                  bool &directDownload, bool &openLicense,
911
                                  bool &gridAvailable) const;
912
913
    PROJ_INTERNAL std::string
914
    getProjGridName(const std::string &oldProjGridName);
915
916
    PROJ_INTERNAL std::string getOldProjGridName(const std::string &gridName);
917
918
    PROJ_INTERNAL std::string
919
    getAliasFromOfficialName(const std::string &officialName,
920
                             const std::string &tableName,
921
                             const std::string &source) const;
922
923
    PROJ_INTERNAL std::list<std::string>
924
    getAliases(const std::string &authName, const std::string &code,
925
               const std::string &officialName, const std::string &tableName,
926
               const std::string &source) const;
927
928
    PROJ_INTERNAL bool isKnownName(const std::string &name,
929
                                   const std::string &tableName) const;
930
931
    PROJ_INTERNAL std::string getName(const std::string &tableName,
932
                                      const std::string &authName,
933
                                      const std::string &code) const;
934
935
    PROJ_INTERNAL std::string getTextDefinition(const std::string &tableName,
936
                                                const std::string &authName,
937
                                                const std::string &code) const;
938
939
    PROJ_INTERNAL std::vector<std::string>
940
    getAllowedAuthorities(const std::string &sourceAuthName,
941
                          const std::string &targetAuthName) const;
942
943
    PROJ_INTERNAL std::list<std::pair<std::string, std::string>>
944
    getNonDeprecated(const std::string &tableName, const std::string &authName,
945
                     const std::string &code) const;
946
947
    PROJ_INTERNAL static std::vector<operation::CoordinateOperationNNPtr>
948
    getTransformationsForGridName(const DatabaseContextNNPtr &databaseContext,
949
                                  const std::string &gridName);
950
951
    PROJ_INTERNAL bool
952
    getAuthorityAndVersion(const std::string &versionedAuthName,
953
                           std::string &authNameOut, std::string &versionOut);
954
955
    PROJ_INTERNAL bool getVersionedAuthority(const std::string &authName,
956
                                             const std::string &version,
957
                                             std::string &versionedAuthNameOut);
958
959
    PROJ_DLL std::vector<std::string>
960
    getVersionedAuthoritiesFromName(const std::string &authName);
961
962
    //! @endcond
963
964
  protected:
965
    PROJ_INTERNAL DatabaseContext();
966
    INLINED_MAKE_SHARED
967
    PROJ_FRIEND(AuthorityFactory);
968
969
  private:
970
    PROJ_OPAQUE_PRIVATE_DATA
971
    DatabaseContext(const DatabaseContext &) = delete;
972
    DatabaseContext &operator=(const DatabaseContext &other) = delete;
973
};
974
975
// ---------------------------------------------------------------------------
976
977
class AuthorityFactory;
978
/** Shared pointer of AuthorityFactory. */
979
using AuthorityFactoryPtr = std::shared_ptr<AuthorityFactory>;
980
/** Non-null shared pointer of AuthorityFactory. */
981
using AuthorityFactoryNNPtr = util::nn<AuthorityFactoryPtr>;
982
983
/** \brief Builds object from an authority database.
984
 *
985
 * A AuthorityFactory should be used only by one thread at a time.
986
 *
987
 * \remark Implements [AuthorityFactory]
988
 * (http://www.geoapi.org/3.0/javadoc/org.opengis.geoapi/org/opengis/referencing/AuthorityFactory.html)
989
 * from \ref GeoAPI
990
 */
991
class PROJ_GCC_DLL AuthorityFactory {
992
  public:
993
    //! @cond Doxygen_Suppress
994
    PROJ_DLL ~AuthorityFactory();
995
    //! @endcond
996
997
    PROJ_DLL util::BaseObjectNNPtr createObject(const std::string &code) const;
998
999
    PROJ_DLL common::UnitOfMeasureNNPtr
1000
    createUnitOfMeasure(const std::string &code) const;
1001
1002
    PROJ_DLL metadata::ExtentNNPtr createExtent(const std::string &code) const;
1003
1004
    PROJ_DLL datum::PrimeMeridianNNPtr
1005
    createPrimeMeridian(const std::string &code) const;
1006
1007
    PROJ_DLL std::string identifyBodyFromSemiMajorAxis(double a,
1008
                                                       double tolerance) const;
1009
1010
    PROJ_DLL datum::EllipsoidNNPtr
1011
    createEllipsoid(const std::string &code) const;
1012
1013
    PROJ_DLL datum::DatumNNPtr createDatum(const std::string &code) const;
1014
1015
    PROJ_DLL datum::DatumEnsembleNNPtr
1016
    createDatumEnsemble(const std::string &code,
1017
                        const std::string &type = std::string()) const;
1018
1019
    PROJ_DLL datum::GeodeticReferenceFrameNNPtr
1020
    createGeodeticDatum(const std::string &code) const;
1021
1022
    PROJ_DLL datum::VerticalReferenceFrameNNPtr
1023
    createVerticalDatum(const std::string &code) const;
1024
1025
    PROJ_DLL cs::CoordinateSystemNNPtr
1026
    createCoordinateSystem(const std::string &code) const;
1027
1028
    PROJ_DLL crs::GeodeticCRSNNPtr
1029
    createGeodeticCRS(const std::string &code) const;
1030
1031
    PROJ_DLL crs::GeographicCRSNNPtr
1032
    createGeographicCRS(const std::string &code) const;
1033
1034
    PROJ_DLL crs::VerticalCRSNNPtr
1035
    createVerticalCRS(const std::string &code) const;
1036
1037
    PROJ_DLL operation::ConversionNNPtr
1038
    createConversion(const std::string &code) const;
1039
1040
    PROJ_DLL crs::ProjectedCRSNNPtr
1041
    createProjectedCRS(const std::string &code) const;
1042
1043
    PROJ_DLL crs::CompoundCRSNNPtr
1044
    createCompoundCRS(const std::string &code) const;
1045
1046
    PROJ_DLL crs::CRSNNPtr
1047
    createCoordinateReferenceSystem(const std::string &code) const;
1048
1049
    PROJ_DLL coordinates::CoordinateMetadataNNPtr
1050
    createCoordinateMetadata(const std::string &code) const;
1051
1052
    PROJ_DLL operation::CoordinateOperationNNPtr
1053
    createCoordinateOperation(const std::string &code,
1054
                              bool usePROJAlternativeGridNames) const;
1055
1056
    PROJ_DLL std::vector<operation::CoordinateOperationNNPtr>
1057
    createFromCoordinateReferenceSystemCodes(
1058
        const std::string &sourceCRSCode,
1059
        const std::string &targetCRSCode) const;
1060
1061
    PROJ_DLL std::list<std::string>
1062
    getGeoidModels(const std::string &code) const;
1063
1064
    PROJ_DLL const std::string &getAuthority() PROJ_PURE_DECL;
1065
1066
    /** Object type. */
1067
    enum class ObjectType {
1068
        /** Object of type datum::PrimeMeridian */
1069
        PRIME_MERIDIAN,
1070
        /** Object of type datum::Ellipsoid */
1071
        ELLIPSOID,
1072
        /** Object of type datum::Datum (and derived classes) */
1073
        DATUM,
1074
        /** Object of type datum::GeodeticReferenceFrame (and derived
1075
           classes) */
1076
        GEODETIC_REFERENCE_FRAME,
1077
        /** Object of type datum::VerticalReferenceFrame (and derived
1078
           classes) */
1079
        VERTICAL_REFERENCE_FRAME,
1080
        /** Object of type crs::CRS (and derived classes) */
1081
        CRS,
1082
        /** Object of type crs::GeodeticCRS (and derived classes) */
1083
        GEODETIC_CRS,
1084
        /** GEODETIC_CRS of type geocentric */
1085
        GEOCENTRIC_CRS,
1086
        /** Object of type crs::GeographicCRS (and derived classes) */
1087
        GEOGRAPHIC_CRS,
1088
        /** GEOGRAPHIC_CRS of type Geographic 2D */
1089
        GEOGRAPHIC_2D_CRS,
1090
        /** GEOGRAPHIC_CRS of type Geographic 3D */
1091
        GEOGRAPHIC_3D_CRS,
1092
        /** Object of type crs::ProjectedCRS (and derived classes) */
1093
        PROJECTED_CRS,
1094
        /** Object of type crs::VerticalCRS (and derived classes) */
1095
        VERTICAL_CRS,
1096
        /** Object of type crs::CompoundCRS (and derived classes) */
1097
        COMPOUND_CRS,
1098
        /** Object of type operation::CoordinateOperation (and derived
1099
           classes) */
1100
        COORDINATE_OPERATION,
1101
        /** Object of type operation::Conversion (and derived classes) */
1102
        CONVERSION,
1103
        /** Object of type operation::Transformation (and derived classes)
1104
         */
1105
        TRANSFORMATION,
1106
        /** Object of type operation::ConcatenatedOperation (and derived
1107
           classes) */
1108
        CONCATENATED_OPERATION,
1109
        /** Object of type datum::DynamicGeodeticReferenceFrame */
1110
        DYNAMIC_GEODETIC_REFERENCE_FRAME,
1111
        /** Object of type datum::DynamicVerticalReferenceFrame */
1112
        DYNAMIC_VERTICAL_REFERENCE_FRAME,
1113
        /** Object of type datum::DatumEnsemble */
1114
        DATUM_ENSEMBLE,
1115
    };
1116
1117
    PROJ_DLL std::set<std::string>
1118
    getAuthorityCodes(const ObjectType &type,
1119
                      bool allowDeprecated = true) const;
1120
1121
    PROJ_DLL std::string getDescriptionText(const std::string &code) const;
1122
1123
    // non-standard
1124
1125
    /** CRS information */
1126
    struct CRSInfo {
1127
        /** Authority name */
1128
        std::string authName;
1129
        /** Code */
1130
        std::string code;
1131
        /** Name */
1132
        std::string name;
1133
        /** Type */
1134
        ObjectType type;
1135
        /** Whether the object is deprecated */
1136
        bool deprecated;
1137
        /** Whereas the west_lon_degree, south_lat_degree, east_lon_degree and
1138
         * north_lat_degree fields are valid. */
1139
        bool bbox_valid;
1140
        /** Western-most longitude of the area of use, in degrees. */
1141
        double west_lon_degree;
1142
        /** Southern-most latitude of the area of use, in degrees. */
1143
        double south_lat_degree;
1144
        /** Eastern-most longitude of the area of use, in degrees. */
1145
        double east_lon_degree;
1146
        /** Northern-most latitude of the area of use, in degrees. */
1147
        double north_lat_degree;
1148
        /** Name of the area of use. */
1149
        std::string areaName;
1150
        /** Name of the projection method for a projected CRS. Might be empty
1151
         * even for projected CRS in some cases. */
1152
        std::string projectionMethodName;
1153
        /** Name of the celestial body of the CRS (e.g. "Earth") */
1154
        std::string celestialBodyName;
1155
1156
        //! @cond Doxygen_Suppress
1157
        CRSInfo();
1158
        //! @endcond
1159
    };
1160
1161
    PROJ_DLL std::list<CRSInfo> getCRSInfoList() const;
1162
1163
    /** Unit information */
1164
    struct UnitInfo {
1165
        /** Authority name */
1166
        std::string authName;
1167
        /** Code */
1168
        std::string code;
1169
        /** Name */
1170
        std::string name;
1171
        /** Category: one of "linear", "linear_per_time", "angular",
1172
         * "angular_per_time", "scale", "scale_per_time" or "time" */
1173
        std::string category;
1174
        /** Conversion factor to the SI unit.
1175
         * It might be 0 in some cases to indicate no known conversion factor.
1176
         */
1177
        double convFactor;
1178
        /** PROJ short name (may be empty) */
1179
        std::string projShortName;
1180
        /** Whether the object is deprecated */
1181
        bool deprecated;
1182
1183
        //! @cond Doxygen_Suppress
1184
        UnitInfo();
1185
        //! @endcond
1186
    };
1187
1188
    PROJ_DLL std::list<UnitInfo> getUnitList() const;
1189
1190
    /** Celestial Body information */
1191
    struct CelestialBodyInfo {
1192
        /** Authority name */
1193
        std::string authName;
1194
        /** Name */
1195
        std::string name;
1196
        //! @cond Doxygen_Suppress
1197
        CelestialBodyInfo();
1198
        //! @endcond
1199
    };
1200
1201
    PROJ_DLL std::list<CelestialBodyInfo> getCelestialBodyList() const;
1202
1203
    PROJ_DLL static AuthorityFactoryNNPtr
1204
    create(const DatabaseContextNNPtr &context,
1205
           const std::string &authorityName);
1206
1207
    PROJ_DLL const DatabaseContextNNPtr &databaseContext() const;
1208
1209
    PROJ_DLL std::vector<operation::CoordinateOperationNNPtr>
1210
    createFromCoordinateReferenceSystemCodes(
1211
        const std::string &sourceCRSAuthName, const std::string &sourceCRSCode,
1212
        const std::string &targetCRSAuthName, const std::string &targetCRSCode,
1213
        bool usePROJAlternativeGridNames, bool discardIfMissingGrid,
1214
        bool considerKnownGridsAsAvailable, bool discardSuperseded,
1215
        bool tryReverseOrder = false,
1216
        bool reportOnlyIntersectingTransformations = false,
1217
        const metadata::ExtentPtr &intersectingExtent1 = nullptr,
1218
        const metadata::ExtentPtr &intersectingExtent2 = nullptr) const;
1219
1220
    PROJ_DLL std::vector<operation::CoordinateOperationNNPtr>
1221
    createFromCRSCodesWithIntermediates(
1222
        const std::string &sourceCRSAuthName, const std::string &sourceCRSCode,
1223
        const std::string &targetCRSAuthName, const std::string &targetCRSCode,
1224
        bool usePROJAlternativeGridNames, bool discardIfMissingGrid,
1225
        bool considerKnownGridsAsAvailable, bool discardSuperseded,
1226
        const std::vector<std::pair<std::string, std::string>>
1227
            &intermediateCRSAuthCodes,
1228
        ObjectType allowedIntermediateObjectType = ObjectType::CRS,
1229
        const std::vector<std::string> &allowedAuthorities =
1230
            std::vector<std::string>(),
1231
        const metadata::ExtentPtr &intersectingExtent1 = nullptr,
1232
        const metadata::ExtentPtr &intersectingExtent2 = nullptr) const;
1233
1234
    PROJ_DLL std::string getOfficialNameFromAlias(
1235
        const std::string &aliasedName, const std::string &tableName,
1236
        const std::string &source, bool tryEquivalentNameSpelling,
1237
        std::string &outTableName, std::string &outAuthName,
1238
        std::string &outCode) const;
1239
1240
    PROJ_DLL std::list<common::IdentifiedObjectNNPtr>
1241
    createObjectsFromName(const std::string &name,
1242
                          const std::vector<ObjectType> &allowedObjectTypes =
1243
                              std::vector<ObjectType>(),
1244
                          bool approximateMatch = true,
1245
                          size_t limitResultCount = 0) const;
1246
1247
    PROJ_DLL std::list<std::pair<std::string, std::string>>
1248
    listAreaOfUseFromName(const std::string &name, bool approximateMatch) const;
1249
1250
    PROJ_PRIVATE :
1251
        //! @cond Doxygen_Suppress
1252
1253
        PROJ_INTERNAL std::list<datum::EllipsoidNNPtr>
1254
        createEllipsoidFromExisting(
1255
            const datum::EllipsoidNNPtr &ellipsoid) const;
1256
1257
    PROJ_INTERNAL std::list<crs::GeodeticCRSNNPtr>
1258
    createGeodeticCRSFromDatum(const std::string &datum_auth_name,
1259
                               const std::string &datum_code,
1260
                               const std::string &geodetic_crs_type) const;
1261
1262
    PROJ_INTERNAL std::list<crs::GeodeticCRSNNPtr>
1263
    createGeodeticCRSFromDatum(const datum::GeodeticReferenceFrameNNPtr &datum,
1264
                               const std::string &preferredAuthName,
1265
                               const std::string &geodetic_crs_type) const;
1266
1267
    PROJ_INTERNAL std::list<crs::VerticalCRSNNPtr>
1268
    createVerticalCRSFromDatum(const std::string &datum_auth_name,
1269
                               const std::string &datum_code) const;
1270
1271
    PROJ_INTERNAL std::list<crs::GeodeticCRSNNPtr>
1272
    createGeodeticCRSFromEllipsoid(const std::string &ellipsoid_auth_name,
1273
                                   const std::string &ellipsoid_code,
1274
                                   const std::string &geodetic_crs_type) const;
1275
1276
    PROJ_INTERNAL std::list<crs::ProjectedCRSNNPtr>
1277
    createProjectedCRSFromExisting(const crs::ProjectedCRSNNPtr &crs) const;
1278
1279
    PROJ_INTERNAL std::list<crs::CompoundCRSNNPtr>
1280
    createCompoundCRSFromExisting(const crs::CompoundCRSNNPtr &crs) const;
1281
1282
    PROJ_INTERNAL crs::CRSNNPtr
1283
    createCoordinateReferenceSystem(const std::string &code,
1284
                                    bool allowCompound) const;
1285
1286
    PROJ_INTERNAL std::vector<operation::CoordinateOperationNNPtr>
1287
    getTransformationsForGeoid(const std::string &geoidName,
1288
                               bool usePROJAlternativeGridNames) const;
1289
1290
    PROJ_INTERNAL std::vector<operation::CoordinateOperationNNPtr>
1291
    createBetweenGeodeticCRSWithDatumBasedIntermediates(
1292
        const crs::CRSNNPtr &sourceCRS, const std::string &sourceCRSAuthName,
1293
        const std::string &sourceCRSCode, const crs::CRSNNPtr &targetCRS,
1294
        const std::string &targetCRSAuthName, const std::string &targetCRSCode,
1295
        bool usePROJAlternativeGridNames, bool discardIfMissingGrid,
1296
        bool considerKnownGridsAsAvailable, bool discardSuperseded,
1297
        const std::vector<std::string> &allowedAuthorities,
1298
        const metadata::ExtentPtr &intersectingExtent1,
1299
        const metadata::ExtentPtr &intersectingExtent2) const;
1300
1301
    typedef std::pair<common::IdentifiedObjectNNPtr, std::string>
1302
        PairObjectName;
1303
    PROJ_INTERNAL std::list<PairObjectName>
1304
    createObjectsFromNameEx(const std::string &name,
1305
                            const std::vector<ObjectType> &allowedObjectTypes =
1306
                                std::vector<ObjectType>(),
1307
                            bool approximateMatch = true,
1308
                            size_t limitResultCount = 0) const;
1309
1310
    PROJ_FOR_TEST std::vector<operation::PointMotionOperationNNPtr>
1311
    getPointMotionOperationsFor(const crs::GeodeticCRSNNPtr &crs,
1312
                                bool usePROJAlternativeGridNames) const;
1313
1314
    //! @endcond
1315
1316
  protected:
1317
    PROJ_INTERNAL AuthorityFactory(const DatabaseContextNNPtr &context,
1318
                                   const std::string &authorityName);
1319
1320
    PROJ_INTERNAL crs::GeodeticCRSNNPtr
1321
    createGeodeticCRS(const std::string &code, bool geographicOnly) const;
1322
1323
    PROJ_INTERNAL operation::CoordinateOperationNNPtr
1324
    createCoordinateOperation(const std::string &code, bool allowConcatenated,
1325
                              bool usePROJAlternativeGridNames,
1326
                              const std::string &type) const;
1327
1328
    INLINED_MAKE_SHARED
1329
1330
  private:
1331
    PROJ_OPAQUE_PRIVATE_DATA
1332
1333
    PROJ_INTERNAL void
1334
    createGeodeticDatumOrEnsemble(const std::string &code,
1335
                                  datum::GeodeticReferenceFramePtr &outDatum,
1336
                                  datum::DatumEnsemblePtr &outDatumEnsemble,
1337
                                  bool turnEnsembleAsDatum) const;
1338
1339
    PROJ_INTERNAL void
1340
    createVerticalDatumOrEnsemble(const std::string &code,
1341
                                  datum::VerticalReferenceFramePtr &outDatum,
1342
                                  datum::DatumEnsemblePtr &outDatumEnsemble,
1343
                                  bool turnEnsembleAsDatum) const;
1344
};
1345
1346
// ---------------------------------------------------------------------------
1347
1348
/** \brief Exception thrown when a factory can't create an instance of the
1349
 * requested object.
1350
 */
1351
class PROJ_GCC_DLL FactoryException : public util::Exception {
1352
  public:
1353
    //! @cond Doxygen_Suppress
1354
    PROJ_DLL explicit FactoryException(const char *message);
1355
    PROJ_DLL explicit FactoryException(const std::string &message);
1356
    PROJ_DLL
1357
    FactoryException(const FactoryException &other);
1358
    PROJ_DLL ~FactoryException() override;
1359
    //! @endcond
1360
};
1361
1362
// ---------------------------------------------------------------------------
1363
1364
/** \brief Exception thrown when an authority factory can't find the requested
1365
 * authority code.
1366
 */
1367
class PROJ_GCC_DLL NoSuchAuthorityCodeException : public FactoryException {
1368
  public:
1369
    //! @cond Doxygen_Suppress
1370
    PROJ_DLL explicit NoSuchAuthorityCodeException(const std::string &message,
1371
                                                   const std::string &authority,
1372
                                                   const std::string &code);
1373
    PROJ_DLL
1374
    NoSuchAuthorityCodeException(const NoSuchAuthorityCodeException &other);
1375
    PROJ_DLL ~NoSuchAuthorityCodeException() override;
1376
    //! @endcond
1377
1378
    PROJ_DLL const std::string &getAuthority() const;
1379
    PROJ_DLL const std::string &getAuthorityCode() const;
1380
1381
  private:
1382
    PROJ_OPAQUE_PRIVATE_DATA
1383
};
1384
1385
} // namespace io
1386
1387
NS_PROJ_END
1388
1389
#endif // IO_HH_INCLUDED