GDAL

ogr_spatialref.h
Go to the documentation of this file.
1/******************************************************************************
2 * $Id$
3 *
4 * Project: OpenGIS Simple Features Reference Implementation
5 * Purpose: Classes for manipulating spatial reference systems in a
6 * platform non-specific manner.
7 * Author: Frank Warmerdam, warmerdam@pobox.com
8 *
9 ******************************************************************************
10 * Copyright (c) 1999, Les Technologies SoftMap Inc.
11 * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
12 *
13 * SPDX-License-Identifier: MIT
14 ****************************************************************************/
15
16#ifndef OGR_SPATIALREF_H_INCLUDED
17#define OGR_SPATIALREF_H_INCLUDED
18
19#include "cpl_string.h"
20#include "ogr_srs_api.h"
21
22#include <cstddef>
23#include <map>
24#include <memory>
25#include <vector>
26
33/************************************************************************/
34/* OGR_SRSNode */
35/************************************************************************/
36
50 class CPL_DLL OGR_SRSNode
51{
52 public:
54 struct Listener
55 {
56 virtual ~Listener();
58 virtual void notifyChange(OGR_SRSNode *) = 0;
59 };
60
61 explicit OGR_SRSNode(const char * = nullptr);
62 ~OGR_SRSNode();
63
65 void RegisterListener(const std::shared_ptr<Listener> &listener);
66
70 int IsLeafNode() const
71 {
72 return nChildren == 0;
73 }
74
75 int GetChildCount() const
76 {
77 return nChildren;
78 }
79
80 OGR_SRSNode *GetChild(int);
81 const OGR_SRSNode *GetChild(int) const;
82
83 OGR_SRSNode *GetNode(const char *);
84 const OGR_SRSNode *GetNode(const char *) const;
85
86 void InsertChild(OGR_SRSNode *, int);
87 void AddChild(OGR_SRSNode *);
88 int FindChild(const char *) const;
89 void DestroyChild(int);
90 void ClearChildren();
91 void StripNodes(const char *);
92
93 const char *GetValue() const
94 {
95 return pszValue;
96 }
97
98 void SetValue(const char *);
99
100 void MakeValueSafe();
101
102 OGR_SRSNode *Clone() const;
103
104 OGRErr importFromWkt(char **)
106 CPL_WARN_DEPRECATED("Use importFromWkt(const char**)")
108 ;
109 OGRErr importFromWkt(const char **);
110 OGRErr exportToWkt(char **) const;
111 OGRErr exportToPrettyWkt(char **, int = 1) const;
112
113 private:
114 char *pszValue;
115
116 OGR_SRSNode **papoChildNodes;
117 OGR_SRSNode *poParent;
118
119 int nChildren;
120
121 int NeedsQuoting() const;
122 OGRErr importFromWkt(const char **, int nRecLevel, int *pnNodes);
123
124 std::weak_ptr<Listener> m_listener{};
125 void notifyChange();
126
127 CPL_DISALLOW_COPY_ASSIGN(OGR_SRSNode)
128};
129
130/************************************************************************/
131/* OGRSpatialReference */
132/************************************************************************/
133
152 class CPL_DLL OGRSpatialReference
153{
154 struct Private;
155 std::unique_ptr<Private> d;
156
157 void GetNormInfo() const;
158
159 // No longer used with PROJ >= 8.1.0
160 OGRErr importFromURNPart(const char *pszAuthority, const char *pszCode,
161 const char *pszURN);
162
163 static CPLString lookupInDict(const char *pszDictFile, const char *pszCode);
164
165 OGRErr GetWKT2ProjectionMethod(const char **ppszMethodName,
166 const char **ppszMethodAuthName = nullptr,
167 const char **ppszMethodCode = nullptr) const;
168
169 public:
170 explicit OGRSpatialReference(const char * = nullptr);
171 OGRSpatialReference(const OGRSpatialReference &);
172 OGRSpatialReference(OGRSpatialReference &&);
173
174 virtual ~OGRSpatialReference();
175
176 static void DestroySpatialReference(OGRSpatialReference *poSRS);
177
178 OGRSpatialReference &operator=(const OGRSpatialReference &);
179 OGRSpatialReference &operator=(OGRSpatialReference &&);
180
181 OGRSpatialReference &AssignAndSetThreadSafe(const OGRSpatialReference &);
182
183 int Reference();
184 int Dereference();
185 int GetReferenceCount() const;
186 void Release();
187
188 const char *GetName() const;
189
190 OGRSpatialReference *Clone() const;
191 OGRSpatialReference *CloneGeogCS() const;
192
193 void dumpReadable();
194 OGRErr exportToWkt(char **) const;
195 OGRErr exportToWkt(char **ppszWKT, const char *const *papszOptions) const;
196 std::string exportToWkt(const char *const *papszOptions = nullptr) const;
197 OGRErr exportToPrettyWkt(char **, int = FALSE) const;
198 // cppcheck-suppress functionStatic
199 OGRErr exportToPROJJSON(char **, const char *const *papszOptions) const;
200 OGRErr exportToProj4(char **) const;
201 OGRErr exportToPCI(char **, char **, double **) const;
202 OGRErr exportToUSGS(long *, long *, double **, long *) const;
203 OGRErr exportToXML(char **, const char * = nullptr) const;
204 OGRErr exportToPanorama(long *, long *, long *, long *, double *) const;
205 OGRErr exportVertCSToPanorama(int *) const;
206 OGRErr exportToERM(char *pszProj, char *pszDatum, char *pszUnits);
207 OGRErr exportToMICoordSys(char **) const;
208 OGRErr exportToCF1(char **ppszGridMappingName, char ***ppapszKeyValues,
209 char **ppszUnits, CSLConstList papszOptions) const;
210
211 OGRErr importFromWkt(char **)
213 CPL_WARN_DEPRECATED(
214 "Use importFromWkt(const char**) or importFromWkt(const char*)")
216 ;
217
218 OGRErr importFromWkt(const char **);
220 OGRErr importFromWkt(const char *pszInput, CSLConstList papszOptions);
221 OGRErr importFromWkt(const char **ppszInput, CSLConstList papszOptions);
223 OGRErr importFromWkt(const char *);
224 OGRErr importFromProj4(const char *);
225 OGRErr importFromEPSG(int);
226 OGRErr importFromEPSGA(int);
227 OGRErr importFromESRI(char **);
228 OGRErr importFromPCI(const char *, const char * = nullptr,
229 const double * = nullptr);
230
231#define USGS_ANGLE_DECIMALDEGREES 0
232#define USGS_ANGLE_PACKEDDMS \
233 TRUE
234#define USGS_ANGLE_RADIANS 2
235 OGRErr importFromUSGS(long iProjSys, long iZone, double *padfPrjParams,
236 long iDatum,
237 int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS);
238 OGRErr importFromPanorama(long, long, long, double *, bool bNorth = true);
239 OGRErr importVertCSFromPanorama(int);
240 OGRErr importFromOzi(const char *const *papszLines);
241 OGRErr importFromWMSAUTO(const char *pszAutoDef);
242 OGRErr importFromXML(const char *);
243 OGRErr importFromDict(const char *pszDict, const char *pszCode);
244 OGRErr importFromURN(const char *);
245 OGRErr importFromCRSURL(const char *);
246 OGRErr importFromERM(const char *pszProj, const char *pszDatum,
247 const char *pszUnits);
248 OGRErr importFromUrl(const char *);
249 OGRErr importFromMICoordSys(const char *);
250 OGRErr importFromCF1(CSLConstList papszKeyValues, const char *pszUnits);
251
252 OGRErr morphToESRI();
253 OGRErr morphFromESRI();
254
255 OGRSpatialReference *
256 convertToOtherProjection(const char *pszTargetProjection,
257 const char *const *papszOptions = nullptr) const;
258
259 OGRErr Validate() const;
260 OGRErr StripVertical();
261
262 bool StripTOWGS84IfKnownDatumAndAllowed();
263 bool StripTOWGS84IfKnownDatum();
264
265 int EPSGTreatsAsLatLong() const;
266 int EPSGTreatsAsNorthingEasting() const;
267 int GetAxesCount() const;
268 const char *GetAxis(const char *pszTargetKey, int iAxis,
269 OGRAxisOrientation *peOrientation,
270 double *pdfConvFactor = nullptr) const;
271 OGRErr SetAxes(const char *pszTargetKey, const char *pszXAxisName,
272 OGRAxisOrientation eXAxisOrientation,
273 const char *pszYAxisName,
274 OGRAxisOrientation eYAxisOrientation);
275
276 OSRAxisMappingStrategy GetAxisMappingStrategy() const;
277 void SetAxisMappingStrategy(OSRAxisMappingStrategy);
278 const std::vector<int> &GetDataAxisToSRSAxisMapping() const;
279 OGRErr SetDataAxisToSRSAxisMapping(const std::vector<int> &mapping);
280
281 // Machinery for accessing parse nodes
282
284 OGR_SRSNode *GetRoot();
286 const OGR_SRSNode *GetRoot() const;
287 void SetRoot(OGR_SRSNode *);
288
289 OGR_SRSNode *GetAttrNode(const char *);
290 const OGR_SRSNode *GetAttrNode(const char *) const;
291 const char *GetAttrValue(const char *, int = 0) const;
292
293 OGRErr SetNode(const char *, const char *);
294 // cppcheck-suppress functionStatic
295 OGRErr SetNode(const char *, double);
296
297 OGRErr
298 SetLinearUnitsAndUpdateParameters(const char *pszName, double dfInMeters,
299 const char *pszUnitAuthority = nullptr,
300 const char *pszUnitCode = nullptr);
301 OGRErr SetLinearUnits(const char *pszName, double dfInMeters);
302 OGRErr SetTargetLinearUnits(const char *pszTargetKey, const char *pszName,
303 double dfInMeters,
304 const char *pszUnitAuthority = nullptr,
305 const char *pszUnitCode = nullptr);
306
307 double GetLinearUnits(char **) const
309 CPL_WARN_DEPRECATED("Use GetLinearUnits(const char**) instead")
311 ;
312 double GetLinearUnits(const char ** = nullptr) const;
313
315 double GetLinearUnits(std::nullptr_t) const
316 {
317 return GetLinearUnits(static_cast<const char **>(nullptr));
318 }
319
322 double GetTargetLinearUnits(const char *pszTargetKey,
323 char **ppszRetName) const
325 CPL_WARN_DEPRECATED(
326 "Use GetTargetLinearUnits(const char*, const char**)")
328 ;
329 double GetTargetLinearUnits(const char *pszTargetKey,
330 const char **ppszRetName = nullptr) const;
331
333 double GetTargetLinearUnits(const char *pszTargetKey, std::nullptr_t) const
334 {
335 return GetTargetLinearUnits(pszTargetKey,
336 static_cast<const char **>(nullptr));
337 }
338
341 OGRErr SetAngularUnits(const char *pszName, double dfInRadians);
342 double GetAngularUnits(char **) const
344 CPL_WARN_DEPRECATED("Use GetAngularUnits(const char**) instead")
346 ;
347 double GetAngularUnits(const char ** = nullptr) const;
348
350 double GetAngularUnits(std::nullptr_t) const
351 {
352 return GetAngularUnits(static_cast<const char **>(nullptr));
353 }
354
357 double GetPrimeMeridian(char **) const
359 CPL_WARN_DEPRECATED("Use GetPrimeMeridian(const char**) instead")
361 ;
362 double GetPrimeMeridian(const char ** = nullptr) const;
363
365 double GetPrimeMeridian(std::nullptr_t) const
366 {
367 return GetPrimeMeridian(static_cast<const char **>(nullptr));
368 }
369
372 bool IsEmpty() const;
373 int IsGeographic() const;
374 int IsDerivedGeographic() const;
375 int IsProjected() const;
376 int IsDerivedProjected() const;
377 int IsGeocentric() const;
378 bool IsDynamic() const;
379
380 // cppcheck-suppress functionStatic
381 bool HasPointMotionOperation() const;
382
383 int IsLocal() const;
384 int IsVertical() const;
385 int IsCompound() const;
386 int IsSameGeogCS(const OGRSpatialReference *) const;
387 int IsSameGeogCS(const OGRSpatialReference *,
388 const char *const *papszOptions) const;
389 int IsSameVertCS(const OGRSpatialReference *) const;
390 int IsSame(const OGRSpatialReference *) const;
391 int IsSame(const OGRSpatialReference *,
392 const char *const *papszOptions) const;
393
394 void Clear();
395 OGRErr SetLocalCS(const char *);
396 OGRErr SetProjCS(const char *);
397 OGRErr SetProjection(const char *);
398 OGRErr SetGeocCS(const char *pszGeocName);
399 OGRErr SetGeogCS(const char *pszGeogName, const char *pszDatumName,
400 const char *pszEllipsoidName, double dfSemiMajor,
401 double dfInvFlattening, const char *pszPMName = nullptr,
402 double dfPMOffset = 0.0, const char *pszUnits = nullptr,
403 double dfConvertToRadians = 0.0);
404 OGRErr SetWellKnownGeogCS(const char *);
405 OGRErr CopyGeogCSFrom(const OGRSpatialReference *poSrcSRS);
406 OGRErr SetVertCS(const char *pszVertCSName, const char *pszVertDatumName,
407 int nVertDatumClass = 2005);
408 OGRErr SetCompoundCS(const char *pszName,
409 const OGRSpatialReference *poHorizSRS,
410 const OGRSpatialReference *poVertSRS);
411
412 void SetCoordinateEpoch(double dfCoordinateEpoch);
413 double GetCoordinateEpoch() const;
414
415 // cppcheck-suppress functionStatic
416 OGRErr PromoteTo3D(const char *pszName);
417 // cppcheck-suppress functionStatic
418 OGRErr DemoteTo2D(const char *pszName);
419
420 OGRErr SetFromUserInput(const char *);
421
422 static const char *const SET_FROM_USER_INPUT_LIMITATIONS[];
423 static CSLConstList SET_FROM_USER_INPUT_LIMITATIONS_get();
424
425 OGRErr SetFromUserInput(const char *, CSLConstList papszOptions);
426
427 OGRErr SetTOWGS84(double, double, double, double = 0.0, double = 0.0,
428 double = 0.0, double = 0.0);
429 OGRErr GetTOWGS84(double *padfCoef, int nCoeff = 7) const;
430 OGRErr AddGuessedTOWGS84();
431
432 double GetSemiMajor(OGRErr * = nullptr) const;
433 double GetSemiMinor(OGRErr * = nullptr) const;
434 double GetInvFlattening(OGRErr * = nullptr) const;
435 double GetEccentricity() const;
436 double GetSquaredEccentricity() const;
437
438 OGRErr SetAuthority(const char *pszTargetKey, const char *pszAuthority,
439 int nCode);
440
441 OGRErr AutoIdentifyEPSG();
442 OGRSpatialReferenceH *FindMatches(char **papszOptions, int *pnEntries,
443 int **ppanMatchConfidence) const;
444 OGRSpatialReference *
445 FindBestMatch(int nMinimumMatchConfidence = 90,
446 const char *pszPreferredAuthority = "EPSG",
447 CSLConstList papszOptions = nullptr) const;
448
449 int GetEPSGGeogCS() const;
450
451 const char *GetAuthorityCode(const char *pszTargetKey) const;
452 const char *GetAuthorityName(const char *pszTargetKey) const;
453 char *GetOGCURN() const;
454
455 bool GetAreaOfUse(double *pdfWestLongitudeDeg, double *pdfSouthLatitudeDeg,
456 double *pdfEastLongitudeDeg, double *pdfNorthLatitudeDeg,
457 const char **ppszAreaName) const;
458
459 const char *GetExtension(const char *pszTargetKey, const char *pszName,
460 const char *pszDefault = nullptr) const;
461 OGRErr SetExtension(const char *pszTargetKey, const char *pszName,
462 const char *pszValue);
463
464 int FindProjParm(const char *pszParameter,
465 const OGR_SRSNode *poPROJCS = nullptr) const;
466 OGRErr SetProjParm(const char *, double);
467 double GetProjParm(const char *, double = 0.0, OGRErr * = nullptr) const;
468
469 OGRErr SetNormProjParm(const char *, double);
470 double GetNormProjParm(const char *, double = 0.0,
471 OGRErr * = nullptr) const;
472
473 static int IsAngularParameter(const char *);
474 static int IsLongitudeParameter(const char *);
475 static int IsLinearParameter(const char *);
476
478 OGRErr SetACEA(double dfStdP1, double dfStdP2, double dfCenterLat,
479 double dfCenterLong, double dfFalseEasting,
480 double dfFalseNorthing);
481
483 OGRErr SetAE(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
484 double dfFalseNorthing);
485
487 OGRErr SetBonne(double dfStdP1, double dfCentralMeridian,
488 double dfFalseEasting, double dfFalseNorthing);
489
491 OGRErr SetCEA(double dfStdP1, double dfCentralMeridian,
492 double dfFalseEasting, double dfFalseNorthing);
493
495 OGRErr SetCS(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
496 double dfFalseNorthing);
497
499 OGRErr SetEC(double dfStdP1, double dfStdP2, double dfCenterLat,
500 double dfCenterLong, double dfFalseEasting,
501 double dfFalseNorthing);
502
504 OGRErr SetEckert(int nVariation, double dfCentralMeridian,
505 double dfFalseEasting, double dfFalseNorthing);
506
508 OGRErr SetEckertIV(double dfCentralMeridian, double dfFalseEasting,
509 double dfFalseNorthing);
510
512 OGRErr SetEckertVI(double dfCentralMeridian, double dfFalseEasting,
513 double dfFalseNorthing);
514
516 OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
517 double dfFalseEasting, double dfFalseNorthing);
519 OGRErr SetEquirectangular2(double dfCenterLat, double dfCenterLong,
520 double dfPseudoStdParallel1,
521 double dfFalseEasting, double dfFalseNorthing);
522
524 OGRErr SetGEOS(double dfCentralMeridian, double dfSatelliteHeight,
525 double dfFalseEasting, double dfFalseNorthing);
526
528 OGRErr SetGH(double dfCentralMeridian, double dfFalseEasting,
529 double dfFalseNorthing);
530
532 OGRErr SetIGH();
533
535 OGRErr SetGS(double dfCentralMeridian, double dfFalseEasting,
536 double dfFalseNorthing);
537
539 OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
540 double dfScale, double dfFalseEasting,
541 double dfFalseNorthing);
542
544 OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
545 double dfFalseEasting, double dfFalseNorthing);
546
548 OGRErr SetHOM(double dfCenterLat, double dfCenterLong, double dfAzimuth,
549 double dfRectToSkew, double dfScale, double dfFalseEasting,
550 double dfFalseNorthing);
551
553 OGRErr SetHOM2PNO(double dfCenterLat, double dfLat1, double dfLong1,
554 double dfLat2, double dfLong2, double dfScale,
555 double dfFalseEasting, double dfFalseNorthing);
556
558 OGRErr SetHOMAC(double dfCenterLat, double dfCenterLong, double dfAzimuth,
559 double dfRectToSkew, double dfScale, double dfFalseEasting,
560 double dfFalseNorthing);
561
563 OGRErr SetLOM(double dfCenterLat, double dfCenterLong, double dfAzimuth,
564 double dfScale, double dfFalseEasting,
565 double dfFalseNorthing);
566
568 OGRErr SetIWMPolyconic(double dfLat1, double dfLat2, double dfCenterLong,
569 double dfFalseEasting, double dfFalseNorthing);
570
572 OGRErr SetKrovak(double dfCenterLat, double dfCenterLong, double dfAzimuth,
573 double dfPseudoStdParallelLat, double dfScale,
574 double dfFalseEasting, double dfFalseNorthing);
575
577 OGRErr SetLAEA(double dfCenterLat, double dfCenterLong,
578 double dfFalseEasting, double dfFalseNorthing);
579
581 OGRErr SetLCC(double dfStdP1, double dfStdP2, double dfCenterLat,
582 double dfCenterLong, double dfFalseEasting,
583 double dfFalseNorthing);
584
586 OGRErr SetLCC1SP(double dfCenterLat, double dfCenterLong, double dfScale,
587 double dfFalseEasting, double dfFalseNorthing);
588
590 OGRErr SetLCCB(double dfStdP1, double dfStdP2, double dfCenterLat,
591 double dfCenterLong, double dfFalseEasting,
592 double dfFalseNorthing);
593
595 OGRErr SetMC(double dfCenterLat, double dfCenterLong, double dfFalseEasting,
596 double dfFalseNorthing);
597
599 OGRErr SetMercator(double dfCenterLat, double dfCenterLong, double dfScale,
600 double dfFalseEasting, double dfFalseNorthing);
601
603 OGRErr SetMercator2SP(double dfStdP1, double dfCenterLat,
604 double dfCenterLong, double dfFalseEasting,
605 double dfFalseNorthing);
606
608 OGRErr SetMollweide(double dfCentralMeridian, double dfFalseEasting,
609 double dfFalseNorthing);
610
612 OGRErr SetNZMG(double dfCenterLat, double dfCenterLong,
613 double dfFalseEasting, double dfFalseNorthing);
614
616 OGRErr SetOS(double dfOriginLat, double dfCMeridian, double dfScale,
617 double dfFalseEasting, double dfFalseNorthing);
618
620 OGRErr SetOrthographic(double dfCenterLat, double dfCenterLong,
621 double dfFalseEasting, double dfFalseNorthing);
622
624 OGRErr SetPolyconic(double dfCenterLat, double dfCenterLong,
625 double dfFalseEasting, double dfFalseNorthing);
626
628 OGRErr SetPS(double dfCenterLat, double dfCenterLong, double dfScale,
629 double dfFalseEasting, double dfFalseNorthing);
630
632 OGRErr SetRobinson(double dfCenterLong, double dfFalseEasting,
633 double dfFalseNorthing);
634
636 OGRErr SetSinusoidal(double dfCenterLong, double dfFalseEasting,
637 double dfFalseNorthing);
638
640 OGRErr SetStereographic(double dfCenterLat, double dfCenterLong,
641 double dfScale, double dfFalseEasting,
642 double dfFalseNorthing);
643
645 OGRErr SetSOC(double dfLatitudeOfOrigin, double dfCentralMeridian,
646 double dfFalseEasting, double dfFalseNorthing);
647
649 OGRErr SetTM(double dfCenterLat, double dfCenterLong, double dfScale,
650 double dfFalseEasting, double dfFalseNorthing);
651
653 OGRErr SetTMVariant(const char *pszVariantName, double dfCenterLat,
654 double dfCenterLong, double dfScale,
655 double dfFalseEasting, double dfFalseNorthing);
656
658 OGRErr SetTMG(double dfCenterLat, double dfCenterLong,
659 double dfFalseEasting, double dfFalseNorthing);
660
662 OGRErr SetTMSO(double dfCenterLat, double dfCenterLong, double dfScale,
663 double dfFalseEasting, double dfFalseNorthing);
664
666 OGRErr SetTPED(double dfLat1, double dfLong1, double dfLat2, double dfLong2,
667 double dfFalseEasting, double dfFalseNorthing);
668
670 OGRErr SetVDG(double dfCenterLong, double dfFalseEasting,
671 double dfFalseNorthing);
672
674 OGRErr SetUTM(int nZone, int bNorth = TRUE);
675 int GetUTMZone(int *pbNorth = nullptr) const;
676
678 OGRErr SetWagner(int nVariation, double dfCenterLat, double dfFalseEasting,
679 double dfFalseNorthing);
680
682 OGRErr SetQSC(double dfCenterLat, double dfCenterLong);
683
685 OGRErr SetSCH(double dfPegLat, double dfPegLong, double dfPegHeading,
686 double dfPegHgt);
687
689 OGRErr
690 SetVerticalPerspective(double dfTopoOriginLat, double dfTopoOriginLon,
691 double dfTopoOriginHeight, double dfViewPointHeight,
692 double dfFalseEasting, double dfFalseNorthing);
693
695 OGRErr SetDerivedGeogCRSWithPoleRotationGRIBConvention(
696 const char *pszCRSName, double dfSouthPoleLat, double dfSouthPoleLon,
697 double dfAxisRotation);
698
700 OGRErr SetDerivedGeogCRSWithPoleRotationNetCDFCFConvention(
701 const char *pszCRSName, double dfGridNorthPoleLat,
702 double dfGridNorthPoleLon, double dfNorthPoleGridLon);
703
705 OGRErr SetStatePlane(int nZone, int bNAD83 = TRUE,
706 const char *pszOverrideUnitName = nullptr,
707 double dfOverrideUnit = 0.0);
708
710 OGRErr ImportFromESRIStatePlaneWKT(int nCode, const char *pszDatumName,
711 const char *pszUnitsName, int nPCSCode,
712 const char *pszCRSName = nullptr);
713
715 OGRErr ImportFromESRIWisconsinWKT(const char *pszPrjName,
716 double dfCentralMeridian,
717 double dfLatOfOrigin,
718 const char *pszUnitsName,
719 const char *pszCRSName = nullptr);
720
722 void UpdateCoordinateSystemFromGeogCRS();
725 static OGRSpatialReference *GetWGS84SRS();
726
730 static inline OGRSpatialReferenceH ToHandle(OGRSpatialReference *poSRS)
731 {
732 return reinterpret_cast<OGRSpatialReferenceH>(poSRS);
733 }
734
738 static inline OGRSpatialReference *FromHandle(OGRSpatialReferenceH hSRS)
739 {
740 return reinterpret_cast<OGRSpatialReference *>(hSRS);
741 }
742};
743
745 struct CPL_DLL OGRSpatialReferenceReleaser
746{
747 void operator()(OGRSpatialReference *poSRS) const
748 {
749 if (poSRS)
750 poSRS->Release();
751 }
752};
753
756/************************************************************************/
757/* OGRCoordinateTransformation */
758/* */
759/* This is really just used as a base class for a private */
760/* implementation. */
761/************************************************************************/
762
772 class CPL_DLL OGRCoordinateTransformation
773{
774 public:
775 virtual ~OGRCoordinateTransformation()
776 {
777 }
778
779 static void DestroyCT(OGRCoordinateTransformation *poCT);
780
781 // From CT_CoordinateTransformation
782
784 virtual const OGRSpatialReference *GetSourceCS() const = 0;
785
787 virtual const OGRSpatialReference *GetTargetCS() const = 0;
788
790 virtual bool GetEmitErrors() const
791 {
792 return false;
793 }
794
796 virtual void SetEmitErrors(bool /*bEmitErrors*/)
797 {
798 }
799
800 // From CT_MathTransform
801
820 int Transform(size_t nCount, double *x, double *y, double *z = nullptr,
821 int *pabSuccess = nullptr);
822
842 virtual int Transform(size_t nCount, double *x, double *y, double *z,
843 double *t, int *pabSuccess) = 0;
844
865 virtual int TransformWithErrorCodes(size_t nCount, double *x, double *y,
866 double *z, double *t,
867 int *panErrorCodes);
868
905 virtual int TransformBounds(const double xmin, const double ymin,
906 const double xmax, const double ymax,
907 double *out_xmin, double *out_ymin,
908 double *out_xmax, double *out_ymax,
909 const int densify_pts)
910 {
911 (void)xmin;
912 (void)xmax;
913 (void)ymin;
914 (void)ymax;
915 (void)densify_pts;
916 *out_xmin = HUGE_VAL;
917 *out_ymin = HUGE_VAL;
918 *out_xmax = HUGE_VAL;
919 *out_ymax = HUGE_VAL;
920 CPLError(CE_Failure, CPLE_AppDefined,
921 "TransformBounds not implemented.");
922 return false;
923 }
924
929 static inline OGRCoordinateTransformationH
930 ToHandle(OGRCoordinateTransformation *poCT)
931 {
932 return reinterpret_cast<OGRCoordinateTransformationH>(poCT);
933 }
934
939 static inline OGRCoordinateTransformation *
940 FromHandle(OGRCoordinateTransformationH hCT)
941 {
942 return reinterpret_cast<OGRCoordinateTransformation *>(hCT);
943 }
944
948 virtual OGRCoordinateTransformation *Clone() const = 0;
949
959 virtual OGRCoordinateTransformation *GetInverse() const = 0;
960};
961
962 OGRCoordinateTransformation CPL_DLL *
963 OGRCreateCoordinateTransformation(const OGRSpatialReference *poSource,
964 const OGRSpatialReference *poTarget);
965
972 struct CPL_DLL OGRCoordinateTransformationOptions
973{
975 private:
976 friend class OGRProjCT;
977 struct Private;
978 std::unique_ptr<Private> d;
981 public:
982 OGRCoordinateTransformationOptions();
983 OGRCoordinateTransformationOptions(
984 const OGRCoordinateTransformationOptions &);
985 OGRCoordinateTransformationOptions &
986 operator=(const OGRCoordinateTransformationOptions &);
987 ~OGRCoordinateTransformationOptions();
988
989 bool SetAreaOfInterest(double dfWestLongitudeDeg, double dfSouthLatitudeDeg,
990 double dfEastLongitudeDeg,
991 double dfNorthLatitudeDeg);
992 bool SetDesiredAccuracy(double dfAccuracy);
993 bool SetBallparkAllowed(bool bAllowBallpark);
994 bool SetOnlyBest(bool bOnlyBest);
995
996 bool SetCoordinateOperation(const char *pszCT, bool bReverseCT);
998 void SetSourceCenterLong(double dfCenterLong);
999 void SetTargetCenterLong(double dfCenterLong);
1001};
1002
1003 OGRCoordinateTransformation CPL_DLL *OGRCreateCoordinateTransformation(
1004 const OGRSpatialReference *poSource, const OGRSpatialReference *poTarget,
1005 const OGRCoordinateTransformationOptions &options);
1006
1007#endif /* ndef OGR_SPATIALREF_H_INCLUDED */
CPLString
Convenient string class based on std::string.
Definition cpl_string.h:307
OGRCoordinateTransformation
Interface for transforming between coordinate systems.
Definition ogr_spatialref.h:773
OGRCoordinateTransformation::SetEmitErrors
virtual void SetEmitErrors(bool)
Set if the transformer must emit CPLError.
Definition ogr_spatialref.h:796
OGRCoordinateTransformation::TransformWithErrorCodes
virtual int TransformWithErrorCodes(size_t nCount, double *x, double *y, double *z, double *t, int *panErrorCodes)
Transform points from source to destination space.
OGRCoordinateTransformation::GetTargetCS
virtual const OGRSpatialReference * GetTargetCS() const =0
Fetch internal target coordinate system.
OGRCoordinateTransformation::Transform
int Transform(size_t nCount, double *x, double *y, double *z=nullptr, int *pabSuccess=nullptr)
Transform points from source to destination space.
OGRCoordinateTransformation::GetInverse
virtual OGRCoordinateTransformation * GetInverse() const =0
Return a coordinate transformation that performs the inverse transformation of the current one.
OGRCoordinateTransformation::TransformBounds
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:905
OGRCoordinateTransformation::GetEmitErrors
virtual bool GetEmitErrors() const
Whether the transformer will emit CPLError.
Definition ogr_spatialref.h:790
OGRCoordinateTransformation::FromHandle
static OGRCoordinateTransformation * FromHandle(OGRCoordinateTransformationH hCT)
Convert a OGRCoordinateTransformationH to a OGRCoordinateTransformation*.
Definition ogr_spatialref.h:940
OGRCoordinateTransformation::Transform
virtual int Transform(size_t nCount, double *x, double *y, double *z, double *t, int *pabSuccess)=0
Transform points from source to destination space.
OGRCoordinateTransformation::GetSourceCS
virtual const OGRSpatialReference * GetSourceCS() const =0
Fetch internal source coordinate system.
OGRCoordinateTransformation::ToHandle
static OGRCoordinateTransformationH ToHandle(OGRCoordinateTransformation *poCT)
Convert a OGRCoordinateTransformation* to a OGRCoordinateTransformationH.
Definition ogr_spatialref.h:930
OGRCoordinateTransformation::Clone
virtual OGRCoordinateTransformation * Clone() const =0
Clone.
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:153
OGRSpatialReference::ToHandle
static OGRSpatialReferenceH ToHandle(OGRSpatialReference *poSRS)
Convert a OGRSpatialReference* to a OGRSpatialReferenceH.
Definition ogr_spatialref.h:730
OGRSpatialReference::FromHandle
static OGRSpatialReference * FromHandle(OGRSpatialReferenceH hSRS)
Convert a OGRSpatialReferenceH to a OGRSpatialReference*.
Definition ogr_spatialref.h:738
OGRSpatialReference::Release
void Release()
Decrements the reference count by one, and destroy if zero.
Definition ogrspatialreference.cpp:1141
OGR_SRSNode
Objects of this class are used to represent value nodes in the parsed representation of the WKT SRS f...
Definition ogr_spatialref.h:51
OGR_SRSNode::GetChildCount
int GetChildCount() const
Get number of children nodes.
Definition ogr_spatialref.h:75
OGR_SRSNode::GetValue
const char * GetValue() const
Fetch value string for this node.
Definition ogr_spatialref.h:93
OGR_SRSNode::IsLeafNode
int IsLeafNode() const
Return whether this is a leaf node.
Definition ogr_spatialref.h:70
CPLE_AppDefined
#define CPLE_AppDefined
Application defined error.
Definition cpl_error.h:84
CPL_DISALLOW_COPY_ASSIGN
#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:1030
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1179
cpl_string.h
Various convenience functions for working with strings and string lists.
OGRCoordinateTransformationH
void * OGRCoordinateTransformationH
Opaque type for a coordinate transformation object.
Definition ogr_api.h:67
OGRSpatialReferenceH
void * OGRSpatialReferenceH
Opaque type for a spatial reference system.
Definition ogr_api.h:65
OGRErr
int OGRErr
Type for a OGR error.
Definition ogr_core.h:371
USGS_ANGLE_PACKEDDMS
#define USGS_ANGLE_PACKEDDMS
Angle is in packed degree minute second.
Definition ogr_spatialref.h:232
OGRCreateCoordinateTransformation
OGRCoordinateTransformation * OGRCreateCoordinateTransformation(const OGRSpatialReference *poSource, const OGRSpatialReference *poTarget)
Create transformation object.
Definition ogrct.cpp:940
ogr_srs_api.h
C spatial reference system services and defines.
OSRAxisMappingStrategy
OSRAxisMappingStrategy
Data axis to CRS axis mapping strategy.
Definition ogr_srs_api.h:652
OGRAxisOrientation
OGRAxisOrientation
Axis orientations (corresponds to CS_AxisOrientationEnum).
Definition ogr_srs_api.h:35
OGRCoordinateTransformationOptions
Context for coordinate transformation.
Definition ogr_spatialref.h:973
OGR_SRSNode::Listener
Listener that is notified of modification to nodes.
Definition ogr_spatialref.h:55
OGR_SRSNode::Listener::notifyChange
virtual void notifyChange(OGR_SRSNode *)=0
Method triggered when a node is modified.