GDAL
ogr_spatialref.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Classes for manipulating spatial reference systems in a
5 * platform non-specific manner.
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1999, Les Technologies SoftMap Inc.
10 * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef OGR_SPATIALREF_H_INCLUDED
16#define OGR_SPATIALREF_H_INCLUDED
17
18#include "cpl_string.h"
19#include "ogr_srs_api.h"
20
21#include <cstddef>
22#include <map>
23#include <memory>
24#include <vector>
25
32/************************************************************************/
33/* OGR_SRSNode */
34/************************************************************************/
35
49class CPL_DLL OGR_SRSNode
50{
51 public:
53 struct Listener
54 {
55 virtual ~Listener();
57 virtual void notifyChange(OGR_SRSNode *) = 0;
58 };
59
60 explicit OGR_SRSNode(const char * = nullptr);
62
64 void RegisterListener(const std::shared_ptr<Listener> &listener);
65
69 int IsLeafNode() const
70 {
71 return nChildren == 0;
72 }
73
74 int GetChildCount() const
75 {
76 return nChildren;
77 }
78
79 OGR_SRSNode *GetChild(int);
80 const OGR_SRSNode *GetChild(int) const;
81
82 OGR_SRSNode *GetNode(const char *);
83 const OGR_SRSNode *GetNode(const char *) const;
84
85 void InsertChild(OGR_SRSNode *, int);
86 void AddChild(OGR_SRSNode *);
87 int FindChild(const char *) const;
88 void DestroyChild(int);
89 void ClearChildren();
90 void StripNodes(const char *);
91
92 const char *GetValue() const
93 {
94 return pszValue;
95 }
96
97 void SetValue(const char *);
98
99 void MakeValueSafe();
100
101 OGR_SRSNode *Clone() const;
102
103 OGRErr importFromWkt(char **)
105 CPL_WARN_DEPRECATED("Use importFromWkt(const char**)")
107 ;
108 OGRErr importFromWkt(const char **);
109 OGRErr exportToWkt(char **) const;
110 OGRErr exportToPrettyWkt(char **, int = 1) const;
111
112 private:
113 char *pszValue;
114
115 OGR_SRSNode **papoChildNodes;
116 OGR_SRSNode *poParent;
117
118 int nChildren;
119
120 int NeedsQuoting() const;
121 OGRErr importFromWkt(const char **, int nRecLevel, int *pnNodes);
122
123 std::weak_ptr<Listener> m_listener{};
124 void notifyChange();
125
127};
128
129/************************************************************************/
130/* OGRSpatialReference */
131/************************************************************************/
132
152{
153 struct Private;
154 std::unique_ptr<Private> d;
155
156 void GetNormInfo() const;
157
158 // No longer used with PROJ >= 8.1.0
159 OGRErr importFromURNPart(const char *pszAuthority, const char *pszCode,
160 const char *pszURN);
161
162 static CPLString lookupInDict(const char *pszDictFile, const char *pszCode);
163
164 OGRErr GetWKT2ProjectionMethod(const char **ppszMethodName,
165 const char **ppszMethodAuthName = nullptr,
166 const char **ppszMethodCode = nullptr) const;
167
168 public:
169 explicit OGRSpatialReference(const char * = nullptr);
172
173 virtual ~OGRSpatialReference();
174
175 static void DestroySpatialReference(OGRSpatialReference *poSRS);
176
177 OGRSpatialReference &operator=(const OGRSpatialReference &);
179
180 OGRSpatialReference &AssignAndSetThreadSafe(const OGRSpatialReference &);
181
182#ifdef DEPRECATE_OGRSPATIALREFERENCE_REF_COUNTING
183 int Reference()
184 CPL_WARN_DEPRECATED("Use OGRSpatialReferenceRefCountedPtr instead");
185 int Dereference()
186 CPL_WARN_DEPRECATED("Use OGRSpatialReferenceRefCountedPtr instead");
187 int GetReferenceCount() const
188 CPL_WARN_DEPRECATED("Use OGRSpatialReferenceRefCountedPtr instead");
189 void Release()
190 CPL_WARN_DEPRECATED("Use OGRSpatialReferenceRefCountedPtr instead");
191#else
192 int Reference();
193 int Dereference();
194 int GetReferenceCount() const;
195 void Release();
196#endif
197
198 const char *GetName() const;
199
200 OGRSpatialReference *Clone() const;
201 OGRSpatialReference *CloneGeogCS() const;
202
203 void dumpReadable();
204 OGRErr exportToWkt(char **) const;
205 OGRErr exportToWkt(char **ppszWKT, const char *const *papszOptions) const;
206 std::string exportToWkt(const char *const *papszOptions = nullptr) const;
207 OGRErr exportToPrettyWkt(char **, int = FALSE) const;
208 // cppcheck-suppress functionStatic
209 OGRErr exportToPROJJSON(char **, const char *const *papszOptions) const;
210 OGRErr exportToProj4(char **) const;
211 OGRErr exportToPCI(char **, char **, double **) const;
212 OGRErr exportToUSGS(long *, long *, double **, long *) const;
213 OGRErr exportToXML(char **, const char * = nullptr) const;
214 OGRErr exportToPanorama(long *, long *, long *, long *, double *) const;
215 OGRErr exportVertCSToPanorama(int *) const;
216 OGRErr exportToERM(char *pszProj, char *pszDatum, char *pszUnits);
217 OGRErr exportToMICoordSys(char **) const;
218 OGRErr exportToCF1(char **ppszGridMappingName, char ***ppapszKeyValues,
219 char **ppszUnits, CSLConstList papszOptions) const;
220
221 OGRErr importFromWkt(char **)
223 CPL_WARN_DEPRECATED(
224 "Use importFromWkt(const char**) or importFromWkt(const char*)")
226 ;
227
228 OGRErr importFromWkt(const char **);
230 OGRErr importFromWkt(const char *pszInput, CSLConstList papszOptions);
231 OGRErr importFromWkt(const char **ppszInput, CSLConstList papszOptions);
233 OGRErr importFromWkt(const char *);
234 OGRErr importFromProj4(const char *);
235 OGRErr importFromEPSG(int);
236 OGRErr importFromEPSGA(int);
237 OGRErr importFromESRI(char **);
238 OGRErr importFromPCI(const char *, const char * = nullptr,
239 const double * = nullptr);
240
241#define USGS_ANGLE_DECIMALDEGREES 0
242#define USGS_ANGLE_PACKEDDMS \
243 TRUE
244#define USGS_ANGLE_RADIANS 2
245 OGRErr importFromUSGS(long iProjSys, long iZone, double *padfPrjParams,
246 long iDatum,
247 int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS);
248 OGRErr importFromPanorama(long, long, long, double *, bool bNorth = true);
249 OGRErr importVertCSFromPanorama(int);
250 OGRErr importFromOzi(const char *const *papszLines);
251 OGRErr importFromWMSAUTO(const char *pszAutoDef);
252 OGRErr importFromXML(const char *);
253 OGRErr importFromDict(const char *pszDict, const char *pszCode);
254 OGRErr importFromURN(const char *);
255 OGRErr importFromCRSURL(const char *);
256 OGRErr importFromERM(const char *pszProj, const char *pszDatum,
257 const char *pszUnits);
258 OGRErr importFromUrl(const char *);
259 OGRErr importFromMICoordSys(const char *);
260 OGRErr importFromCF1(CSLConstList papszKeyValues, const char *pszUnits);
261
262 OGRErr morphToESRI();
263 OGRErr morphFromESRI();
264
266 convertToOtherProjection(const char *pszTargetProjection,
267 const char *const *papszOptions = nullptr) const;
268
269 OGRErr Validate() const;
270 OGRErr StripVertical();
271
272 bool StripTOWGS84IfKnownDatumAndAllowed();
273 bool StripTOWGS84IfKnownDatum();
274
275 int EPSGTreatsAsLatLong() const;
276 int EPSGTreatsAsNorthingEasting() const;
277 int GetAxesCount() const;
278 const char *GetAxis(const char *pszTargetKey, int iAxis,
279 OGRAxisOrientation *peOrientation,
280 double *pdfConvFactor = nullptr) const;
281 OGRErr SetAxes(const char *pszTargetKey, const char *pszXAxisName,
282 OGRAxisOrientation eXAxisOrientation,
283 const char *pszYAxisName,
284 OGRAxisOrientation eYAxisOrientation);
285
286 OSRAxisMappingStrategy GetAxisMappingStrategy() const;
287 void SetAxisMappingStrategy(OSRAxisMappingStrategy);
288 const std::vector<int> &GetDataAxisToSRSAxisMapping() const;
289 OGRErr SetDataAxisToSRSAxisMapping(const std::vector<int> &mapping);
290
291 // Machinery for accessing parse nodes
292
294 OGR_SRSNode *GetRoot();
296 const OGR_SRSNode *GetRoot() const;
297 void SetRoot(OGR_SRSNode *);
298
299 OGR_SRSNode *GetAttrNode(const char *);
300 const OGR_SRSNode *GetAttrNode(const char *) const;
301 const char *GetAttrValue(const char *, int = 0) const;
302
303 OGRErr SetNode(const char *, const char *);
304 // cppcheck-suppress functionStatic
305 OGRErr SetNode(const char *, double);
306
307 OGRErr
308 SetLinearUnitsAndUpdateParameters(const char *pszName, double dfInMeters,
309 const char *pszUnitAuthority = nullptr,
310 const char *pszUnitCode = nullptr);
311 OGRErr SetLinearUnits(const char *pszName, double dfInMeters);
312 OGRErr SetTargetLinearUnits(const char *pszTargetKey, const char *pszName,
313 double dfInMeters,
314 const char *pszUnitAuthority = nullptr,
315 const char *pszUnitCode = nullptr);
316
317 double GetLinearUnits(char **) const
319 CPL_WARN_DEPRECATED("Use GetLinearUnits(const char**) instead")
321 ;
322 double GetLinearUnits(const char ** = nullptr) const;
323
325 double GetLinearUnits(std::nullptr_t) const
326 {
327 return GetLinearUnits(static_cast<const char **>(nullptr));
328 }
329
332 double GetTargetLinearUnits(const char *pszTargetKey,
333 char **ppszRetName) const
335 CPL_WARN_DEPRECATED(
336 "Use GetTargetLinearUnits(const char*, const char**)")
338 ;
339 double GetTargetLinearUnits(const char *pszTargetKey,
340 const char **ppszRetName = nullptr) const;
341
343 double GetTargetLinearUnits(const char *pszTargetKey, std::nullptr_t) const
344 {
345 return GetTargetLinearUnits(pszTargetKey,
346 static_cast<const char **>(nullptr));
347 }
348
351 OGRErr SetAngularUnits(const char *pszName, double dfInRadians);
352 double GetAngularUnits(char **) const
354 CPL_WARN_DEPRECATED("Use GetAngularUnits(const char**) instead")
356 ;
357 double GetAngularUnits(const char ** = nullptr) const;
358
360 double GetAngularUnits(std::nullptr_t) const
361 {
362 return GetAngularUnits(static_cast<const char **>(nullptr));
363 }
364
367 double GetPrimeMeridian(char **) const
369 CPL_WARN_DEPRECATED("Use GetPrimeMeridian(const char**) instead")
371 ;
372 double GetPrimeMeridian(const char ** = nullptr) const;
373
375 double GetPrimeMeridian(std::nullptr_t) const
376 {
377 return GetPrimeMeridian(static_cast<const char **>(nullptr));
378 }
379
382 bool IsEmpty() const;
383 int IsGeographic() const;
384 int IsDerivedGeographic() const;
385 int IsProjected() const;
386 int IsDerivedProjected() const;
387 int IsGeocentric() const;
388 bool IsDynamic() const;
389
390 // cppcheck-suppress functionStatic
391 bool HasPointMotionOperation() const;
392
393 int IsLocal() const;
394 int IsVertical() const;
395 int IsCompound() const;
396 int IsSameGeogCS(const OGRSpatialReference *) const;
397 int IsSameGeogCS(const OGRSpatialReference *,
398 const char *const *papszOptions) const;
399 int IsSameVertCS(const OGRSpatialReference *) const;
400 int IsSame(const OGRSpatialReference *) const;
401 int IsSame(const OGRSpatialReference *,
402 const char *const *papszOptions) const;
403
404 const char *GetCelestialBodyName() const;
405
406 void Clear();
407 OGRErr SetLocalCS(const char *);
408 OGRErr SetProjCS(const char *);
409 OGRErr SetProjection(const char *);
410 OGRErr SetGeocCS(const char *pszGeocName);
411 OGRErr SetGeogCS(const char *pszGeogName, const char *pszDatumName,
412 const char *pszEllipsoidName, double dfSemiMajor,
413 double dfInvFlattening, const char *pszPMName = nullptr,
414 double dfPMOffset = 0.0, const char *pszUnits = nullptr,
415 double dfConvertToRadians = 0.0);
416 OGRErr SetWellKnownGeogCS(const char *);
417 OGRErr CopyGeogCSFrom(const OGRSpatialReference *poSrcSRS);
418 OGRErr SetVertCS(const char *pszVertCSName, const char *pszVertDatumName,
419 int nVertDatumClass = 2005);
420 OGRErr SetCompoundCS(const char *pszName,
421 const OGRSpatialReference *poHorizSRS,
422 const OGRSpatialReference *poVertSRS);
423
424 void SetCoordinateEpoch(double dfCoordinateEpoch);
425 double GetCoordinateEpoch() const;
426
427 // cppcheck-suppress functionStatic
428 OGRErr PromoteTo3D(const char *pszName);
429 // cppcheck-suppress functionStatic
430 OGRErr DemoteTo2D(const char *pszName);
431
432 OGRErr SetFromUserInput(const char *);
433
434 static const char *const SET_FROM_USER_INPUT_LIMITATIONS[];
435 static CSLConstList SET_FROM_USER_INPUT_LIMITATIONS_get();
436
437 OGRErr SetFromUserInput(const char *, CSLConstList papszOptions);
438
439 OGRErr SetTOWGS84(double, double, double, double = 0.0, double = 0.0,
440 double = 0.0, double = 0.0);
441 OGRErr GetTOWGS84(double *padfCoef, int nCoeff = 7) const;
442 OGRErr AddGuessedTOWGS84();
443
444 double GetSemiMajor(OGRErr * = nullptr) const;
445 double GetSemiMinor(OGRErr * = nullptr) const;
446 double GetInvFlattening(OGRErr * = nullptr) const;
447 double GetEccentricity() const;
448 double GetSquaredEccentricity() const;
449
450 OGRErr SetAuthority(const char *pszTargetKey, const char *pszAuthority,
451 int nCode);
452
453 OGRErr AutoIdentifyEPSG();
454 OGRSpatialReferenceH *FindMatches(CSLConstList papszOptions, int *pnEntries,
455 int **ppanMatchConfidence) const;
457 FindBestMatch(int nMinimumMatchConfidence = 90,
458 const char *pszPreferredAuthority = "EPSG",
459 CSLConstList papszOptions = nullptr) const;
460
461 int GetEPSGGeogCS() const;
462
463 const char *GetAuthorityCode(const char *pszTargetKey = nullptr) const;
464 const char *GetAuthorityName(const char *pszTargetKey = nullptr) const;
465 char *GetOGCURN() const;
466
467 bool GetAreaOfUse(double *pdfWestLongitudeDeg, double *pdfSouthLatitudeDeg,
468 double *pdfEastLongitudeDeg, double *pdfNorthLatitudeDeg,
469 const char **ppszAreaName) const;
470
471 const char *GetExtension(const char *pszTargetKey, const char *pszName,
472 const char *pszDefault = nullptr) const;
473 OGRErr SetExtension(const char *pszTargetKey, const char *pszName,
474 const char *pszValue);
475
476 int FindProjParm(const char *pszParameter,
477 const OGR_SRSNode *poPROJCS = nullptr) const;
478 OGRErr SetProjParm(const char *, double);
479 double GetProjParm(const char *, double = 0.0, OGRErr * = nullptr) const;
480
481 OGRErr SetNormProjParm(const char *, double);
482 double GetNormProjParm(const char *, double = 0.0,
483 OGRErr * = nullptr) const;
484
485 static int IsAngularParameter(const char *);
486 static int IsLongitudeParameter(const char *);
487 static int IsLinearParameter(const char *);
488
490 OGRErr SetACEA(double dfStdP1, double dfStdP2, double dfCenterLat,
491 double dfCenterLong, double dfFalseEasting,
492 double dfFalseNorthing);
493
495 OGRErr SetAE(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
496 double dfFalseNorthing);
497
499 OGRErr SetBonne(double dfStdP1, double dfCentralMeridian,
500 double dfFalseEasting, double dfFalseNorthing);
501
503 OGRErr SetCEA(double dfStdP1, double dfCentralMeridian,
504 double dfFalseEasting, double dfFalseNorthing);
505
507 OGRErr SetCS(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
508 double dfFalseNorthing);
509
511 OGRErr SetEC(double dfStdP1, double dfStdP2, double dfCenterLat,
512 double dfCenterLong, double dfFalseEasting,
513 double dfFalseNorthing);
514
516 OGRErr SetEckert(int nVariation, double dfCentralMeridian,
517 double dfFalseEasting, double dfFalseNorthing);
518
520 OGRErr SetEckertIV(double dfCentralMeridian, double dfFalseEasting,
521 double dfFalseNorthing);
522
524 OGRErr SetEckertVI(double dfCentralMeridian, double dfFalseEasting,
525 double dfFalseNorthing);
526
528 OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
529 double dfFalseEasting, double dfFalseNorthing);
531 OGRErr SetEquirectangular2(double dfCenterLat, double dfCenterLong,
532 double dfPseudoStdParallel1,
533 double dfFalseEasting, double dfFalseNorthing);
534
536 OGRErr SetGEOS(double dfCentralMeridian, double dfSatelliteHeight,
537 double dfFalseEasting, double dfFalseNorthing);
538
540 OGRErr SetGH(double dfCentralMeridian, double dfFalseEasting,
541 double dfFalseNorthing);
542
544 OGRErr SetIGH();
545
547 OGRErr SetGS(double dfCentralMeridian, double dfFalseEasting,
548 double dfFalseNorthing);
549
551 OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
552 double dfScale, double dfFalseEasting,
553 double dfFalseNorthing);
554
556 OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
557 double dfFalseEasting, double dfFalseNorthing);
558
560 OGRErr SetHOM(double dfCenterLat, double dfCenterLong, double dfAzimuth,
561 double dfRectToSkew, double dfScale, double dfFalseEasting,
562 double dfFalseNorthing);
563
565 OGRErr SetHOM2PNO(double dfCenterLat, double dfLat1, double dfLong1,
566 double dfLat2, double dfLong2, double dfScale,
567 double dfFalseEasting, double dfFalseNorthing);
568
570 OGRErr SetHOMAC(double dfCenterLat, double dfCenterLong, double dfAzimuth,
571 double dfRectToSkew, double dfScale, double dfFalseEasting,
572 double dfFalseNorthing);
573
575 OGRErr SetLOM(double dfCenterLat, double dfCenterLong, double dfAzimuth,
576 double dfScale, double dfFalseEasting,
577 double dfFalseNorthing);
578
580 OGRErr SetIWMPolyconic(double dfLat1, double dfLat2, double dfCenterLong,
581 double dfFalseEasting, double dfFalseNorthing);
582
584 OGRErr SetKrovak(double dfCenterLat, double dfCenterLong, double dfAzimuth,
585 double dfPseudoStdParallelLat, double dfScale,
586 double dfFalseEasting, double dfFalseNorthing);
587
589 OGRErr SetLAEA(double dfCenterLat, double dfCenterLong,
590 double dfFalseEasting, double dfFalseNorthing);
591
593 OGRErr SetLCC(double dfStdP1, double dfStdP2, double dfCenterLat,
594 double dfCenterLong, double dfFalseEasting,
595 double dfFalseNorthing);
596
598 OGRErr SetLCC1SP(double dfCenterLat, double dfCenterLong, double dfScale,
599 double dfFalseEasting, double dfFalseNorthing);
600
602 OGRErr SetLCCB(double dfStdP1, double dfStdP2, double dfCenterLat,
603 double dfCenterLong, double dfFalseEasting,
604 double dfFalseNorthing);
605
607 OGRErr SetMC(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
608 double dfFalseNorthing);
609
611 OGRErr SetMercator(double dfCenterLat, double dfCenterLong, double dfScale,
612 double dfFalseEasting, double dfFalseNorthing);
613
615 OGRErr SetMercator2SP(double dfStdP1, double dfCenterLat,
616 double dfCenterLong, double dfFalseEasting,
617 double dfFalseNorthing);
618
620 OGRErr SetMollweide(double dfCentralMeridian, double dfFalseEasting,
621 double dfFalseNorthing);
622
624 OGRErr SetNZMG(double dfCenterLat, double dfCenterLong,
625 double dfFalseEasting, double dfFalseNorthing);
626
628 OGRErr SetOS(double dfOriginLat, double dfCMeridian, double dfScale,
629 double dfFalseEasting, double dfFalseNorthing);
630
632 OGRErr SetOrthographic(double dfCenterLat, double dfCenterLong,
633 double dfFalseEasting, double dfFalseNorthing);
634
636 OGRErr SetPolyconic(double dfCenterLat, double dfCenterLong,
637 double dfFalseEasting, double dfFalseNorthing);
638
640 OGRErr SetPS(double dfCenterLat, double dfCenterLong, double dfScale,
641 double dfFalseEasting, double dfFalseNorthing);
642
644 OGRErr SetRobinson(double dfCenterLong, double dfFalseEasting,
645 double dfFalseNorthing);
646
648 OGRErr SetSinusoidal(double dfCenterLong, double dfFalseEasting,
649 double dfFalseNorthing);
650
652 OGRErr SetStereographic(double dfCenterLat, double dfCenterLong,
653 double dfScale, double dfFalseEasting,
654 double dfFalseNorthing);
655
657 OGRErr SetSOC(double dfLatitudeOfOrigin, double dfCentralMeridian,
658 double dfFalseEasting, double dfFalseNorthing);
659
661 OGRErr SetTM(double dfCenterLat, double dfCenterLong, double dfScale,
662 double dfFalseEasting, double dfFalseNorthing);
663
665 OGRErr SetTMVariant(const char *pszVariantName, double dfCenterLat,
666 double dfCenterLong, double dfScale,
667 double dfFalseEasting, double dfFalseNorthing);
668
670 OGRErr SetTMG(double dfCenterLat, double dfCenterLong,
671 double dfFalseEasting, double dfFalseNorthing);
672
674 OGRErr SetTMSO(double dfCenterLat, double dfCenterLong, double dfScale,
675 double dfFalseEasting, double dfFalseNorthing);
676
678 OGRErr SetTPED(double dfLat1, double dfLong1, double dfLat2, double dfLong2,
679 double dfFalseEasting, double dfFalseNorthing);
680
682 OGRErr SetVDG(double dfCenterLong, double dfFalseEasting,
683 double dfFalseNorthing);
684
686 OGRErr SetUTM(int nZone, int bNorth = TRUE);
687 int GetUTMZone(int *pbNorth = nullptr) const;
688
690 OGRErr SetWagner(int nVariation, double dfCenterLat, double dfFalseEasting,
691 double dfFalseNorthing);
692
694 OGRErr SetQSC(double dfCenterLat, double dfCenterLong);
695
697 OGRErr SetSCH(double dfPegLat, double dfPegLong, double dfPegHeading,
698 double dfPegHgt);
699
701 OGRErr
702 SetVerticalPerspective(double dfTopoOriginLat, double dfTopoOriginLon,
703 double dfTopoOriginHeight, double dfViewPointHeight,
704 double dfFalseEasting, double dfFalseNorthing);
705
707 OGRErr SetDerivedGeogCRSWithPoleRotationGRIBConvention(
708 const char *pszCRSName, double dfSouthPoleLat, double dfSouthPoleLon,
709 double dfAxisRotation);
710
712 OGRErr SetDerivedGeogCRSWithPoleRotationNetCDFCFConvention(
713 const char *pszCRSName, double dfGridNorthPoleLat,
714 double dfGridNorthPoleLon, double dfNorthPoleGridLon);
715
717 OGRErr SetStatePlane(int nZone, int bNAD83 = TRUE,
718 const char *pszOverrideUnitName = nullptr,
719 double dfOverrideUnit = 0.0);
720
722 OGRErr ImportFromESRIStatePlaneWKT(int nCode, const char *pszDatumName,
723 const char *pszUnitsName, int nPCSCode,
724 const char *pszCRSName = nullptr);
725
727 OGRErr ImportFromESRIWisconsinWKT(const char *pszPrjName,
728 double dfCentralMeridian,
729 double dfLatOfOrigin,
730 const char *pszUnitsName,
731 const char *pszCRSName = nullptr);
732
734 void UpdateCoordinateSystemFromGeogCRS();
737 static OGRSpatialReference *GetWGS84SRS();
738
742 {
743 return reinterpret_cast<OGRSpatialReferenceH>(poSRS);
744 }
745
749 {
750 return reinterpret_cast<OGRSpatialReference *>(hSRS);
751 }
752};
753
756#include "ogr_refcountedptr.h"
757
758template <>
759struct OGRRefCountedPtr<OGRSpatialReference>
760 : public OGRRefCountedPtrBase<OGRSpatialReference>
761{
769 inline explicit OGRRefCountedPtr(OGRSpatialReference *poSRS, bool add_ref)
770 : OGRRefCountedPtrBase<OGRSpatialReference>(poSRS, add_ref)
771 {
772 }
773
776 inline OGRRefCountedPtr()
777 {
778 }
779
782 // cppcheck-suppress noExplicitConstructor
783 inline /* implicit */ OGRRefCountedPtr(std::nullptr_t)
784 {
785 }
786
790 inline static OGRRefCountedPtr makeInstance(const char *pszWKT = nullptr)
791 {
792 // Initial ref_count of OGRSpatialReference is 1, so don't add a ref
793 return OGRRefCountedPtr(new OGRSpatialReference(pszWKT),
794 /* add_ref = */ false);
795 }
796
799 inline static OGRRefCountedPtr makeClone(const OGRSpatialReference *poSRS)
800 {
801 return OGRRefCountedPtr(poSRS ? poSRS->Clone() : nullptr,
802 /* add_ref = */ false);
803 }
804
807 inline static OGRRefCountedPtr makeClone(const OGRSpatialReference &oSRS)
808 {
809 return OGRRefCountedPtr(oSRS.Clone(),
810 /* add_ref = */ false);
811 }
812
817 inline void reset()
818 {
819 OGRRefCountedPtrBase<OGRSpatialReference>::reset(nullptr, false);
820 }
821
828 inline void reset(OGRSpatialReference *poRawPtr, bool add_ref)
829 {
830 OGRRefCountedPtrBase<OGRSpatialReference>::reset(poRawPtr, add_ref);
831 }
832
836 inline void reset(OGRSpatialReference *poRawPtr) = delete;
837};
838
846using OGRSpatialReferenceRefCountedPtr = OGRRefCountedPtr<OGRSpatialReference>;
847
850/************************************************************************/
851/* OGRCoordinateTransformation */
852/* */
853/* This is really just used as a base class for a private */
854/* implementation. */
855/************************************************************************/
856
867{
868 public:
870
871 static void DestroyCT(OGRCoordinateTransformation *poCT);
872
873 // From CT_CoordinateTransformation
874
876 virtual const OGRSpatialReference *GetSourceCS() const = 0;
877
879 virtual const OGRSpatialReference *GetTargetCS() const = 0;
880
882 virtual bool GetEmitErrors() const
883 {
884 return false;
885 }
886
888 virtual void SetEmitErrors(bool /*bEmitErrors*/)
889 {
890 }
891
892 // From CT_MathTransform
893
914 int Transform(size_t nCount, double *x, double *y, double *z = nullptr,
915 int *pabSuccess = nullptr);
916
941 virtual int Transform(size_t nCount, double *x, double *y, double *z,
942 double *t, int *pabSuccess) = 0;
943
969 virtual int TransformWithErrorCodes(size_t nCount, double *x, double *y,
970 double *z, double *t,
971 int *panErrorCodes);
972
1009 virtual int TransformBounds(const double xmin, const double ymin,
1010 const double xmax, const double ymax,
1011 double *out_xmin, double *out_ymin,
1012 double *out_xmax, double *out_ymax,
1013 const int densify_pts)
1014 {
1015 (void)xmin;
1016 (void)xmax;
1017 (void)ymin;
1018 (void)ymax;
1019 (void)densify_pts;
1020 *out_xmin = HUGE_VAL;
1021 *out_ymin = HUGE_VAL;
1022 *out_xmax = HUGE_VAL;
1023 *out_ymax = HUGE_VAL;
1024 CPLError(CE_Failure, CPLE_AppDefined,
1025 "TransformBounds not implemented.");
1026 return false;
1027 }
1028
1032 static inline OGRCoordinateTransformationH
1034 {
1035 return reinterpret_cast<OGRCoordinateTransformationH>(poCT);
1036 }
1037
1041 static inline OGRCoordinateTransformation *
1043 {
1044 return reinterpret_cast<OGRCoordinateTransformation *>(hCT);
1045 }
1046
1051
1062
1063 protected:
1065 OGRCoordinateTransformation() = default;
1068 operator=(const OGRCoordinateTransformation &) = default;
1071 operator=(OGRCoordinateTransformation &&) = default;
1073};
1074
1077 const OGRSpatialReference *poTarget);
1078
1086{
1088 private:
1089 friend class OGRProjCT;
1090 struct Private;
1091 std::unique_ptr<Private> d;
1094 public:
1099 operator=(const OGRCoordinateTransformationOptions &);
1101
1102 bool SetAreaOfInterest(double dfWestLongitudeDeg, double dfSouthLatitudeDeg,
1103 double dfEastLongitudeDeg,
1104 double dfNorthLatitudeDeg);
1105 bool SetDesiredAccuracy(double dfAccuracy);
1106 bool SetBallparkAllowed(bool bAllowBallpark);
1107 bool SetOnlyBest(bool bOnlyBest);
1108
1109 bool SetCoordinateOperation(const char *pszCT, bool bReverseCT);
1111 void SetSourceCenterLong(double dfCenterLong);
1112 void SetTargetCenterLong(double dfCenterLong);
1114};
1115
1117 const OGRSpatialReference *poSource, const OGRSpatialReference *poTarget,
1118 const OGRCoordinateTransformationOptions &options);
1119
1120#endif /* ndef OGR_SPATIALREF_H_INCLUDED */
Convenient string class based on std::string.
Definition cpl_string.h:338
Interface for transforming between coordinate systems.
Definition ogr_spatialref.h:867
virtual void SetEmitErrors(bool)
Set if the transformer must emit CPLError.
Definition ogr_spatialref.h:888
virtual int TransformWithErrorCodes(size_t nCount, double *x, double *y, double *z, double *t, int *panErrorCodes)
Transform points from source to destination space.
virtual const OGRSpatialReference * GetTargetCS() const =0
Fetch internal target coordinate system.
int Transform(size_t nCount, double *x, double *y, double *z=nullptr, int *pabSuccess=nullptr)
Transform points from source to destination space.
virtual OGRCoordinateTransformation * GetInverse() const =0
Return a coordinate transformation that performs the inverse transformation of the current one.
virtual int TransformBounds(const double xmin, const double ymin, const double xmax, const double ymax, double *out_xmin, double *out_ymin, double *out_xmax, double *out_ymax, const int densify_pts)
Transform boundary.
Definition ogr_spatialref.h:1009
virtual bool GetEmitErrors() const
Whether the transformer will emit CPLError.
Definition ogr_spatialref.h:882
static OGRCoordinateTransformation * FromHandle(OGRCoordinateTransformationH hCT)
Convert a OGRCoordinateTransformationH to a OGRCoordinateTransformation*.
Definition ogr_spatialref.h:1042
virtual int Transform(size_t nCount, double *x, double *y, double *z, double *t, int *pabSuccess)=0
Transform points from source to destination space.
virtual const OGRSpatialReference * GetSourceCS() const =0
Fetch internal source coordinate system.
static OGRCoordinateTransformationH ToHandle(OGRCoordinateTransformation *poCT)
Convert a OGRCoordinateTransformation* to a OGRCoordinateTransformationH.
Definition ogr_spatialref.h:1033
virtual OGRCoordinateTransformation * Clone() const =0
Clone.
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
static OGRSpatialReferenceH ToHandle(OGRSpatialReference *poSRS)
Convert a OGRSpatialReference* to a OGRSpatialReferenceH.
Definition ogr_spatialref.h:741
static OGRSpatialReference * FromHandle(OGRSpatialReferenceH hSRS)
Convert a OGRSpatialReferenceH to a OGRSpatialReference*.
Definition ogr_spatialref.h:748
OGRSpatialReference * Clone() const
Make a duplicate of this OGRSpatialReference.
Definition ogrspatialreference.cpp:1516
Objects of this class are used to represent value nodes in the parsed representation of the WKT SRS f...
Definition ogr_spatialref.h:50
int GetChildCount() const
Get number of children nodes.
Definition ogr_spatialref.h:74
const char * GetValue() const
Fetch value string for this node.
Definition ogr_spatialref.h:92
int IsLeafNode() const
Return whether this is a leaf node.
Definition ogr_spatialref.h:69
@ CE_Failure
Error that prevents the current operation to succeed.
Definition cpl_error.h:60
#define CPLE_AppDefined
Application defined error.
Definition cpl_error.h:108
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
Various convenience functions for working with strings and string lists.
void * OGRCoordinateTransformationH
Opaque type for a coordinate transformation object.
Definition gdal_fwd.h:197
void * OGRSpatialReferenceH
Opaque type for a spatial reference system.
Definition gdal_fwd.h:195
int OGRErr
Type for a OGR error.
Definition ogr_core.h:388
#define USGS_ANGLE_PACKEDDMS
Angle is in packed degree minute second.
Definition ogr_spatialref.h:242
OGRCoordinateTransformation * OGRCreateCoordinateTransformation(const OGRSpatialReference *poSource, const OGRSpatialReference *poTarget)
Create transformation object.
Definition ogrct.cpp:1027
C spatial reference system services and defines.
OSRAxisMappingStrategy
Data axis to CRS axis mapping strategy.
Definition ogr_srs_api.h:637
OGRAxisOrientation
Axis orientations (corresponds to CS_AxisOrientationEnum).
Definition ogr_srs_api.h:35
Context for coordinate transformation.
Definition ogr_spatialref.h:1086
Listener that is notified of modification to nodes.
Definition ogr_spatialref.h:54
virtual void notifyChange(OGR_SRSNode *)=0
Method triggered when a node is modified.