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 CopyGeogCSFrom(const OGRSpatialReference *poSrcSRS,
419 bool bInnerMostGeogCRS);
420 OGRErr SetVertCS(const char *pszVertCSName, const char *pszVertDatumName,
421 int nVertDatumClass = 2005);
422 OGRErr SetCompoundCS(const char *pszName,
423 const OGRSpatialReference *poHorizSRS,
424 const OGRSpatialReference *poVertSRS);
425
426 void SetCoordinateEpoch(double dfCoordinateEpoch);
427 double GetCoordinateEpoch() const;
428
429 // cppcheck-suppress functionStatic
430 OGRErr PromoteTo3D(const char *pszName);
431 // cppcheck-suppress functionStatic
432 OGRErr DemoteTo2D(const char *pszName);
433
434 OGRErr SetFromUserInput(const char *);
435
436 static const char *const SET_FROM_USER_INPUT_LIMITATIONS[];
437 static CSLConstList SET_FROM_USER_INPUT_LIMITATIONS_get();
438
439 OGRErr SetFromUserInput(const char *, CSLConstList papszOptions);
440
441 OGRErr SetTOWGS84(double, double, double, double = 0.0, double = 0.0,
442 double = 0.0, double = 0.0);
443 OGRErr GetTOWGS84(double *padfCoef, int nCoeff = 7) const;
444 OGRErr AddGuessedTOWGS84();
445
446 double GetSemiMajor(OGRErr * = nullptr) const;
447 double GetSemiMinor(OGRErr * = nullptr) const;
448 double GetInvFlattening(OGRErr * = nullptr) const;
449 double GetEccentricity() const;
450 double GetSquaredEccentricity() const;
451
452 OGRErr SetAuthority(const char *pszTargetKey, const char *pszAuthority,
453 int nCode);
454
455 OGRErr AutoIdentifyEPSG();
456 OGRSpatialReferenceH *FindMatches(CSLConstList papszOptions, int *pnEntries,
457 int **ppanMatchConfidence) const;
459 FindBestMatch(int nMinimumMatchConfidence = 90,
460 const char *pszPreferredAuthority = "EPSG",
461 CSLConstList papszOptions = nullptr) const;
462
463 int GetEPSGGeogCS() const;
464
465 const char *GetAuthorityCode(const char *pszTargetKey = nullptr) const;
466 const char *GetAuthorityName(const char *pszTargetKey = nullptr) const;
467 char *GetOGCURN() const;
468
469 bool GetAreaOfUse(double *pdfWestLongitudeDeg, double *pdfSouthLatitudeDeg,
470 double *pdfEastLongitudeDeg, double *pdfNorthLatitudeDeg,
471 const char **ppszAreaName) const;
472
473 const char *GetExtension(const char *pszTargetKey, const char *pszName,
474 const char *pszDefault = nullptr) const;
475 OGRErr SetExtension(const char *pszTargetKey, const char *pszName,
476 const char *pszValue);
477
478 int FindProjParm(const char *pszParameter,
479 const OGR_SRSNode *poPROJCS = nullptr) const;
480 OGRErr SetProjParm(const char *, double);
481 double GetProjParm(const char *, double = 0.0, OGRErr * = nullptr) const;
482
483 OGRErr SetNormProjParm(const char *, double);
484 double GetNormProjParm(const char *, double = 0.0,
485 OGRErr * = nullptr) const;
486
487 static int IsAngularParameter(const char *);
488 static int IsLongitudeParameter(const char *);
489 static int IsLinearParameter(const char *);
490
492 OGRErr SetACEA(double dfStdP1, double dfStdP2, double dfCenterLat,
493 double dfCenterLong, double dfFalseEasting,
494 double dfFalseNorthing);
495
497 OGRErr SetAE(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
498 double dfFalseNorthing);
499
501 OGRErr SetBonne(double dfStdP1, double dfCentralMeridian,
502 double dfFalseEasting, double dfFalseNorthing);
503
505 OGRErr SetCEA(double dfStdP1, double dfCentralMeridian,
506 double dfFalseEasting, double dfFalseNorthing);
507
509 OGRErr SetCS(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
510 double dfFalseNorthing);
511
513 OGRErr SetEC(double dfStdP1, double dfStdP2, double dfCenterLat,
514 double dfCenterLong, double dfFalseEasting,
515 double dfFalseNorthing);
516
518 OGRErr SetEckert(int nVariation, double dfCentralMeridian,
519 double dfFalseEasting, double dfFalseNorthing);
520
522 OGRErr SetEckertIV(double dfCentralMeridian, double dfFalseEasting,
523 double dfFalseNorthing);
524
526 OGRErr SetEckertVI(double dfCentralMeridian, double dfFalseEasting,
527 double dfFalseNorthing);
528
530 OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
531 double dfFalseEasting, double dfFalseNorthing);
533 OGRErr SetEquirectangular2(double dfCenterLat, double dfCenterLong,
534 double dfPseudoStdParallel1,
535 double dfFalseEasting, double dfFalseNorthing);
536
538 OGRErr SetGEOS(double dfCentralMeridian, double dfSatelliteHeight,
539 double dfFalseEasting, double dfFalseNorthing);
540
542 OGRErr SetGH(double dfCentralMeridian, double dfFalseEasting,
543 double dfFalseNorthing);
544
546 OGRErr SetIGH();
547
549 OGRErr SetGS(double dfCentralMeridian, double dfFalseEasting,
550 double dfFalseNorthing);
551
553 OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
554 double dfScale, double dfFalseEasting,
555 double dfFalseNorthing);
556
558 OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
559 double dfFalseEasting, double dfFalseNorthing);
560
562 OGRErr SetHOM(double dfCenterLat, double dfCenterLong, double dfAzimuth,
563 double dfRectToSkew, double dfScale, double dfFalseEasting,
564 double dfFalseNorthing);
565
567 OGRErr SetHOM2PNO(double dfCenterLat, double dfLat1, double dfLong1,
568 double dfLat2, double dfLong2, double dfScale,
569 double dfFalseEasting, double dfFalseNorthing);
570
572 OGRErr SetHOMAC(double dfCenterLat, double dfCenterLong, double dfAzimuth,
573 double dfRectToSkew, double dfScale, double dfFalseEasting,
574 double dfFalseNorthing);
575
577 OGRErr SetLOM(double dfCenterLat, double dfCenterLong, double dfAzimuth,
578 double dfScale, double dfFalseEasting,
579 double dfFalseNorthing);
580
582 OGRErr SetIWMPolyconic(double dfLat1, double dfLat2, double dfCenterLong,
583 double dfFalseEasting, double dfFalseNorthing);
584
586 OGRErr SetKrovak(double dfCenterLat, double dfCenterLong, double dfAzimuth,
587 double dfPseudoStdParallelLat, double dfScale,
588 double dfFalseEasting, double dfFalseNorthing);
589
591 OGRErr SetLAEA(double dfCenterLat, double dfCenterLong,
592 double dfFalseEasting, double dfFalseNorthing);
593
595 OGRErr SetLCC(double dfStdP1, double dfStdP2, double dfCenterLat,
596 double dfCenterLong, double dfFalseEasting,
597 double dfFalseNorthing);
598
600 OGRErr SetLCC1SP(double dfCenterLat, double dfCenterLong, double dfScale,
601 double dfFalseEasting, double dfFalseNorthing);
602
604 OGRErr SetLCCB(double dfStdP1, double dfStdP2, double dfCenterLat,
605 double dfCenterLong, double dfFalseEasting,
606 double dfFalseNorthing);
607
609 OGRErr SetMC(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
610 double dfFalseNorthing);
611
613 OGRErr SetMercator(double dfCenterLat, double dfCenterLong, double dfScale,
614 double dfFalseEasting, double dfFalseNorthing);
615
617 OGRErr SetMercator2SP(double dfStdP1, double dfCenterLat,
618 double dfCenterLong, double dfFalseEasting,
619 double dfFalseNorthing);
620
622 OGRErr SetMollweide(double dfCentralMeridian, double dfFalseEasting,
623 double dfFalseNorthing);
624
626 OGRErr SetNZMG(double dfCenterLat, double dfCenterLong,
627 double dfFalseEasting, double dfFalseNorthing);
628
630 OGRErr SetOS(double dfOriginLat, double dfCMeridian, double dfScale,
631 double dfFalseEasting, double dfFalseNorthing);
632
634 OGRErr SetOrthographic(double dfCenterLat, double dfCenterLong,
635 double dfFalseEasting, double dfFalseNorthing);
636
638 OGRErr SetPolyconic(double dfCenterLat, double dfCenterLong,
639 double dfFalseEasting, double dfFalseNorthing);
640
642 OGRErr SetPS(double dfCenterLat, double dfCenterLong, double dfScale,
643 double dfFalseEasting, double dfFalseNorthing);
644
646 OGRErr SetRobinson(double dfCenterLong, double dfFalseEasting,
647 double dfFalseNorthing);
648
650 OGRErr SetSinusoidal(double dfCenterLong, double dfFalseEasting,
651 double dfFalseNorthing);
652
654 OGRErr SetStereographic(double dfCenterLat, double dfCenterLong,
655 double dfScale, double dfFalseEasting,
656 double dfFalseNorthing);
657
659 OGRErr SetSOC(double dfLatitudeOfOrigin, double dfCentralMeridian,
660 double dfFalseEasting, double dfFalseNorthing);
661
663 OGRErr SetTM(double dfCenterLat, double dfCenterLong, double dfScale,
664 double dfFalseEasting, double dfFalseNorthing);
665
667 OGRErr SetTMVariant(const char *pszVariantName, double dfCenterLat,
668 double dfCenterLong, double dfScale,
669 double dfFalseEasting, double dfFalseNorthing);
670
672 OGRErr SetTMG(double dfCenterLat, double dfCenterLong,
673 double dfFalseEasting, double dfFalseNorthing);
674
676 OGRErr SetTMSO(double dfCenterLat, double dfCenterLong, double dfScale,
677 double dfFalseEasting, double dfFalseNorthing);
678
680 OGRErr SetTPED(double dfLat1, double dfLong1, double dfLat2, double dfLong2,
681 double dfFalseEasting, double dfFalseNorthing);
682
684 OGRErr SetVDG(double dfCenterLong, double dfFalseEasting,
685 double dfFalseNorthing);
686
688 OGRErr SetUTM(int nZone, int bNorth = TRUE);
689 int GetUTMZone(int *pbNorth = nullptr) const;
690
692 OGRErr SetWagner(int nVariation, double dfCenterLat, double dfFalseEasting,
693 double dfFalseNorthing);
694
696 OGRErr SetQSC(double dfCenterLat, double dfCenterLong);
697
699 OGRErr SetSCH(double dfPegLat, double dfPegLong, double dfPegHeading,
700 double dfPegHgt);
701
703 OGRErr
704 SetVerticalPerspective(double dfTopoOriginLat, double dfTopoOriginLon,
705 double dfTopoOriginHeight, double dfViewPointHeight,
706 double dfFalseEasting, double dfFalseNorthing);
707
709 OGRErr SetDerivedGeogCRSWithPoleRotationGRIBConvention(
710 const char *pszCRSName, double dfSouthPoleLat, double dfSouthPoleLon,
711 double dfAxisRotation);
712
714 OGRErr SetDerivedGeogCRSWithPoleRotationNetCDFCFConvention(
715 const char *pszCRSName, double dfGridNorthPoleLat,
716 double dfGridNorthPoleLon, double dfNorthPoleGridLon);
717
719 OGRErr SetStatePlane(int nZone, int bNAD83 = TRUE,
720 const char *pszOverrideUnitName = nullptr,
721 double dfOverrideUnit = 0.0);
722
724 OGRErr ImportFromESRIStatePlaneWKT(int nCode, const char *pszDatumName,
725 const char *pszUnitsName, int nPCSCode,
726 const char *pszCRSName = nullptr);
727
729 OGRErr ImportFromESRIWisconsinWKT(const char *pszPrjName,
730 double dfCentralMeridian,
731 double dfLatOfOrigin,
732 const char *pszUnitsName,
733 const char *pszCRSName = nullptr);
734
736 void UpdateCoordinateSystemFromGeogCRS();
739 static OGRSpatialReference *GetWGS84SRS();
740
744 {
745 return reinterpret_cast<OGRSpatialReferenceH>(poSRS);
746 }
747
751 {
752 return reinterpret_cast<OGRSpatialReference *>(hSRS);
753 }
754};
755
758#include "ogr_refcountedptr.h"
759
760template <>
761struct OGRRefCountedPtr<OGRSpatialReference>
762 : public OGRRefCountedPtrBase<OGRSpatialReference>
763{
771 inline explicit OGRRefCountedPtr(OGRSpatialReference *poSRS, bool add_ref)
772 : OGRRefCountedPtrBase<OGRSpatialReference>(poSRS, add_ref)
773 {
774 }
775
778 inline OGRRefCountedPtr()
779 {
780 }
781
784 // cppcheck-suppress noExplicitConstructor
785 inline /* implicit */ OGRRefCountedPtr(std::nullptr_t)
786 {
787 }
788
792 inline static OGRRefCountedPtr makeInstance(const char *pszWKT = nullptr)
793 {
794 // Initial ref_count of OGRSpatialReference is 1, so don't add a ref
795 return OGRRefCountedPtr(new OGRSpatialReference(pszWKT),
796 /* add_ref = */ false);
797 }
798
801 inline static OGRRefCountedPtr makeClone(const OGRSpatialReference *poSRS)
802 {
803 return OGRRefCountedPtr(poSRS ? poSRS->Clone() : nullptr,
804 /* add_ref = */ false);
805 }
806
809 inline static OGRRefCountedPtr makeClone(const OGRSpatialReference &oSRS)
810 {
811 return OGRRefCountedPtr(oSRS.Clone(),
812 /* add_ref = */ false);
813 }
814
819 inline void reset()
820 {
821 OGRRefCountedPtrBase<OGRSpatialReference>::reset(nullptr, false);
822 }
823
830 inline void reset(OGRSpatialReference *poRawPtr, bool add_ref)
831 {
832 OGRRefCountedPtrBase<OGRSpatialReference>::reset(poRawPtr, add_ref);
833 }
834
838 inline void reset(OGRSpatialReference *poRawPtr) = delete;
839};
840
848using OGRSpatialReferenceRefCountedPtr = OGRRefCountedPtr<OGRSpatialReference>;
849
852/************************************************************************/
853/* OGRCoordinateTransformation */
854/* */
855/* This is really just used as a base class for a private */
856/* implementation. */
857/************************************************************************/
858
869{
870 public:
872
873 static void DestroyCT(OGRCoordinateTransformation *poCT);
874
875 // From CT_CoordinateTransformation
876
878 virtual const OGRSpatialReference *GetSourceCS() const = 0;
879
881 virtual const OGRSpatialReference *GetTargetCS() const = 0;
882
884 virtual bool GetEmitErrors() const
885 {
886 return false;
887 }
888
890 virtual void SetEmitErrors(bool /*bEmitErrors*/)
891 {
892 }
893
894 // From CT_MathTransform
895
916 int Transform(size_t nCount, double *x, double *y, double *z = nullptr,
917 int *pabSuccess = nullptr);
918
943 virtual int Transform(size_t nCount, double *x, double *y, double *z,
944 double *t, int *pabSuccess) = 0;
945
971 virtual int TransformWithErrorCodes(size_t nCount, double *x, double *y,
972 double *z, double *t,
973 int *panErrorCodes);
974
1011 virtual int TransformBounds(const double xmin, const double ymin,
1012 const double xmax, const double ymax,
1013 double *out_xmin, double *out_ymin,
1014 double *out_xmax, double *out_ymax,
1015 const int densify_pts)
1016 {
1017 (void)xmin;
1018 (void)xmax;
1019 (void)ymin;
1020 (void)ymax;
1021 (void)densify_pts;
1022 *out_xmin = HUGE_VAL;
1023 *out_ymin = HUGE_VAL;
1024 *out_xmax = HUGE_VAL;
1025 *out_ymax = HUGE_VAL;
1026 CPLError(CE_Failure, CPLE_AppDefined,
1027 "TransformBounds not implemented.");
1028 return false;
1029 }
1030
1034 static inline OGRCoordinateTransformationH
1036 {
1037 return reinterpret_cast<OGRCoordinateTransformationH>(poCT);
1038 }
1039
1043 static inline OGRCoordinateTransformation *
1045 {
1046 return reinterpret_cast<OGRCoordinateTransformation *>(hCT);
1047 }
1048
1053
1064
1065 protected:
1067 OGRCoordinateTransformation() = default;
1070 operator=(const OGRCoordinateTransformation &) = default;
1073 operator=(OGRCoordinateTransformation &&) = default;
1075};
1076
1079 const OGRSpatialReference *poTarget);
1080
1088{
1090 private:
1091 friend class OGRProjCT;
1092 struct Private;
1093 std::unique_ptr<Private> d;
1096 public:
1101 operator=(const OGRCoordinateTransformationOptions &);
1103
1104 bool SetAreaOfInterest(double dfWestLongitudeDeg, double dfSouthLatitudeDeg,
1105 double dfEastLongitudeDeg,
1106 double dfNorthLatitudeDeg);
1107 bool SetDesiredAccuracy(double dfAccuracy);
1108 bool SetBallparkAllowed(bool bAllowBallpark);
1109 bool SetOnlyBest(bool bOnlyBest);
1110
1111 bool SetCoordinateOperation(const char *pszCT, bool bReverseCT);
1113 void SetSourceCenterLong(double dfCenterLong);
1114 void SetTargetCenterLong(double dfCenterLong);
1116};
1117
1119 const OGRSpatialReference *poSource, const OGRSpatialReference *poTarget,
1120 const OGRCoordinateTransformationOptions &options);
1121
1122#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:869
virtual void SetEmitErrors(bool)
Set if the transformer must emit CPLError.
Definition ogr_spatialref.h:890
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:1011
virtual bool GetEmitErrors() const
Whether the transformer will emit CPLError.
Definition ogr_spatialref.h:884
static OGRCoordinateTransformation * FromHandle(OGRCoordinateTransformationH hCT)
Convert a OGRCoordinateTransformationH to a OGRCoordinateTransformation*.
Definition ogr_spatialref.h:1044
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:1035
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:743
static OGRSpatialReference * FromHandle(OGRSpatialReferenceH hSRS)
Convert a OGRSpatialReferenceH to a OGRSpatialReference*.
Definition ogr_spatialref.h:750
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:1088
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.