Coverage Report

Created: 2025-07-11 06:33

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