GDAL
ogr_spatialref.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_spatialref.h 40207 2017-09-25 14:56:24Z rouault $
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 mines-paris dot org>
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef OGR_SPATIALREF_H_INCLUDED
33 #define OGR_SPATIALREF_H_INCLUDED
34 
35 #include "ogr_srs_api.h"
36 
37 #include <vector>
38 
45 /************************************************************************/
46 /* OGR_SRSNode */
47 /************************************************************************/
48 
62 class CPL_DLL OGR_SRSNode
63 {
64  char *pszValue;
65 
66  OGR_SRSNode **papoChildNodes;
67  OGR_SRSNode *poParent;
68 
69  int nChildren;
70 
71  int NeedsQuoting() const;
72  OGRErr importFromWkt( char **, int nRecLevel, int* pnNodes );
73 
74  public:
75  explicit OGR_SRSNode(const char * = NULL);
76  ~OGR_SRSNode();
77 
81  int IsLeafNode() const { return nChildren == 0; }
82 
83  int GetChildCount() const { return nChildren; }
84  OGR_SRSNode *GetChild( int );
85  const OGR_SRSNode *GetChild( int ) const;
86 
87  OGR_SRSNode *GetNode( const char * );
88  const OGR_SRSNode *GetNode( const char * ) const;
89 
90  void InsertChild( OGR_SRSNode *, int );
91  void AddChild( OGR_SRSNode * );
92  int FindChild( const char * ) const;
93  void DestroyChild( int );
94  void ClearChildren();
95  void StripNodes( const char * );
96 
97  const char *GetValue() const { return pszValue; }
98  void SetValue( const char * );
99 
100  void MakeValueSafe();
101  OGRErr FixupOrdering();
102 
103  OGR_SRSNode *Clone() const;
104 
105  OGRErr importFromWkt( char ** );
106  OGRErr exportToWkt( char ** ) const;
107  OGRErr exportToPrettyWkt( char **, int = 1) const;
108 
109  OGRErr applyRemapper( const char *pszNode,
110  char **papszSrcValues,
111  char **papszDstValues,
112  int nStepSize = 1,
113  int bChildOfHit = FALSE );
114 };
115 
116 /************************************************************************/
117 /* OGRSpatialReference */
118 /************************************************************************/
119 
134 class CPL_DLL OGRSpatialReference
135 {
136  double dfFromGreenwich;
137  double dfToMeter;
138  double dfToDegrees;
139 
140  OGR_SRSNode *poRoot;
141 
142  int nRefCount;
143  int bNormInfoSet;
144 
145  static OGRErr Validate(OGR_SRSNode *poRoot);
146  static OGRErr ValidateAuthority(OGR_SRSNode *poRoot);
147  static OGRErr ValidateAxis(OGR_SRSNode *poRoot);
148  static OGRErr ValidateUnit(OGR_SRSNode *poRoot);
149  static OGRErr ValidateVertDatum(OGR_SRSNode *poRoot);
150  static OGRErr ValidateProjection( OGR_SRSNode* poRoot );
151  static int IsAliasFor( const char *, const char * );
152  void GetNormInfo() const;
153 
154  OGRErr importFromURNPart(const char* pszAuthority,
155  const char* pszCode,
156  const char* pszURN);
157 
158  OGRErr importFromEPSGAInternal(int nCode,
159  const char* pszSRSType);
160 
161  static const std::vector<OGRSpatialReference*>* GetSRSCache(
162  const char* pszSRSType);
163 
164  public:
166  explicit OGRSpatialReference(const char * = NULL);
167 
168  virtual ~OGRSpatialReference();
169 
170  static void DestroySpatialReference(OGRSpatialReference* poSRS);
171 
172  OGRSpatialReference &operator=(const OGRSpatialReference&);
173 
174  int Reference();
175  int Dereference();
176  int GetReferenceCount() const { return nRefCount; }
177  void Release();
178 
179  OGRSpatialReference *Clone() const;
180  OGRSpatialReference *CloneGeogCS() const;
181 
182  void dumpReadable();
183  OGRErr exportToWkt( char ** ) const;
184  OGRErr exportToPrettyWkt( char **, int = FALSE) const;
185  OGRErr exportToProj4( char ** ) const;
186  OGRErr exportToPCI( char **, char **, double ** ) const;
187  OGRErr exportToUSGS( long *, long *, double **, long * ) const;
188  OGRErr exportToXML( char **, const char * = NULL ) const;
189  OGRErr exportToPanorama( long *, long *, long *, long *,
190  double * ) const;
191  OGRErr exportToERM( char *pszProj, char *pszDatum, char *pszUnits );
192  OGRErr exportToMICoordSys( char ** ) const;
193 
194  OGRErr importFromWkt( char ** );
195  OGRErr importFromProj4( const char * );
196  OGRErr importFromEPSG( int );
197  OGRErr importFromEPSGA( int );
198  OGRErr importFromESRI( char ** );
199  OGRErr importFromPCI( const char *, const char * = NULL,
200  double * = NULL );
201 
202 #define USGS_ANGLE_DECIMALDEGREES 0
203 #define USGS_ANGLE_PACKEDDMS TRUE
204 #define USGS_ANGLE_RADIANS 2
205  OGRErr importFromUSGS( long iProjSys, long iZone,
206  double *padfPrjParams, long iDatum,
207  int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS );
208  OGRErr importFromPanorama( long, long, long, double* );
209  OGRErr importFromOzi( const char * const* papszLines );
210  OGRErr importFromWMSAUTO( const char *pszAutoDef );
211  OGRErr importFromXML( const char * );
212  OGRErr importFromDict( const char *pszDict, const char *pszCode );
213  OGRErr importFromURN( const char * );
214  OGRErr importFromCRSURL( const char * );
215  OGRErr importFromERM( const char *pszProj, const char *pszDatum,
216  const char *pszUnits );
217  OGRErr importFromUrl( const char * );
218  OGRErr importFromMICoordSys( const char * );
219 
220  OGRErr morphToESRI();
221  OGRErr morphFromESRI();
222 
223  OGRErr Validate();
224  OGRErr StripCTParms( OGR_SRSNode * = NULL );
225  OGRErr StripVertical();
226  OGRErr FixupOrdering();
227  OGRErr Fixup();
228 
229  int EPSGTreatsAsLatLong();
230  int EPSGTreatsAsNorthingEasting();
231  const char *GetAxis( const char *pszTargetKey, int iAxis,
232  OGRAxisOrientation *peOrientation ) const;
233  OGRErr SetAxes( const char *pszTargetKey,
234  const char *pszXAxisName,
235  OGRAxisOrientation eXAxisOrientation,
236  const char *pszYAxisName,
237  OGRAxisOrientation eYAxisOrientation );
238 
239  // Machinery for accessing parse nodes
240 
242  OGR_SRSNode *GetRoot() { return poRoot; }
244  const OGR_SRSNode *GetRoot() const { return poRoot; }
245  void SetRoot( OGR_SRSNode * );
246 
247  OGR_SRSNode *GetAttrNode(const char *);
248  const OGR_SRSNode *GetAttrNode(const char *) const;
249  const char *GetAttrValue(const char *, int = 0) const;
250 
251  OGRErr SetNode( const char *, const char * );
252  OGRErr SetNode( const char *, double );
253 
254  OGRErr SetLinearUnitsAndUpdateParameters( const char *pszName,
255  double dfInMeters );
256  OGRErr SetLinearUnits( const char *pszName, double dfInMeters );
257  OGRErr SetTargetLinearUnits( const char *pszTargetKey,
258  const char *pszName, double dfInMeters );
259  double GetLinearUnits( char ** = NULL ) const;
260  double GetTargetLinearUnits( const char *pszTargetKey,
261  char ** ppszRetName = NULL ) const;
262 
263  OGRErr SetAngularUnits( const char *pszName, double dfInRadians );
264  double GetAngularUnits( char ** = NULL ) const;
265 
266  double GetPrimeMeridian( char ** = NULL ) const;
267 
268  int IsGeographic() const;
269  int IsProjected() const;
270  int IsGeocentric() const;
271  int IsLocal() const;
272  int IsVertical() const;
273  int IsCompound() const;
274  int IsSameGeogCS( const OGRSpatialReference * ) const;
275  int IsSameGeogCS( const OGRSpatialReference *,
276  const char* const * papszOptions ) const;
277  int IsSameVertCS( const OGRSpatialReference * ) const;
278  int IsSame( const OGRSpatialReference * ) const;
279  int IsSame( const OGRSpatialReference *,
280  const char* const * papszOptions ) const;
281 
282  void Clear();
283  OGRErr SetLocalCS( const char * );
284  OGRErr SetProjCS( const char * );
285  OGRErr SetProjection( const char * );
286  OGRErr SetGeocCS( const char * pszGeocName );
287  OGRErr SetGeogCS( const char * pszGeogName,
288  const char * pszDatumName,
289  const char * pszEllipsoidName,
290  double dfSemiMajor, double dfInvFlattening,
291  const char * pszPMName = NULL,
292  double dfPMOffset = 0.0,
293  const char * pszUnits = NULL,
294  double dfConvertToRadians = 0.0 );
295  OGRErr SetWellKnownGeogCS( const char * );
296  OGRErr CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
297  OGRErr SetVertCS( const char *pszVertCSName,
298  const char *pszVertDatumName,
299  int nVertDatumClass = 2005 );
300  OGRErr SetCompoundCS( const char *pszName,
301  const OGRSpatialReference *poHorizSRS,
302  const OGRSpatialReference *poVertSRS );
303 
304  OGRErr SetFromUserInput( const char * );
305 
306  OGRErr SetTOWGS84( double, double, double,
307  double = 0.0, double = 0.0, double = 0.0,
308  double = 0.0 );
309  OGRErr GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
310 
311  double GetSemiMajor( OGRErr * = NULL ) const;
312  double GetSemiMinor( OGRErr * = NULL ) const;
313  double GetInvFlattening( OGRErr * = NULL ) const;
314 
315  OGRErr SetAuthority( const char * pszTargetKey,
316  const char * pszAuthority,
317  int nCode );
318 
319  OGRErr AutoIdentifyEPSG();
320  OGRSpatialReferenceH* FindMatches( char** papszOptions,
321  int* pnEntries,
322  int** ppanMatchConfidence ) const;
323 
324  int GetEPSGGeogCS();
325 
326  const char *GetAuthorityCode( const char * pszTargetKey ) const;
327  const char *GetAuthorityName( const char * pszTargetKey ) const;
328 
329  const char *GetExtension( const char *pszTargetKey,
330  const char *pszName,
331  const char *pszDefault = NULL ) const;
332  OGRErr SetExtension( const char *pszTargetKey,
333  const char *pszName,
334  const char *pszValue );
335 
336  int FindProjParm( const char *pszParameter,
337  const OGR_SRSNode *poPROJCS=NULL ) const;
338  OGRErr SetProjParm( const char *, double );
339  double GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
340 
341  OGRErr SetNormProjParm( const char *, double );
342  double GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
343 
344  static int IsAngularParameter( const char * );
345  static int IsLongitudeParameter( const char * );
346  static int IsLinearParameter( const char * );
347 
349  OGRErr SetACEA( double dfStdP1, double dfStdP2,
350  double dfCenterLat, double dfCenterLong,
351  double dfFalseEasting, double dfFalseNorthing );
352 
354  OGRErr SetAE( double dfCenterLat, double dfCenterLong,
355  double dfFalseEasting, double dfFalseNorthing );
356 
358  OGRErr SetBonne( double dfStdP1, double dfCentralMeridian,
359  double dfFalseEasting, double dfFalseNorthing );
360 
362  OGRErr SetCEA( double dfStdP1, double dfCentralMeridian,
363  double dfFalseEasting, double dfFalseNorthing );
364 
366  OGRErr SetCS( double dfCenterLat, double dfCenterLong,
367  double dfFalseEasting, double dfFalseNorthing );
368 
370  OGRErr SetEC( double dfStdP1, double dfStdP2,
371  double dfCenterLat, double dfCenterLong,
372  double dfFalseEasting, double dfFalseNorthing );
373 
375  OGRErr SetEckert( int nVariation, double dfCentralMeridian,
376  double dfFalseEasting, double dfFalseNorthing );
377 
379  OGRErr SetEckertIV( double dfCentralMeridian,
380  double dfFalseEasting, double dfFalseNorthing );
381 
383  OGRErr SetEckertVI( double dfCentralMeridian,
384  double dfFalseEasting, double dfFalseNorthing );
385 
387  OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
388  double dfFalseEasting, double dfFalseNorthing );
390  OGRErr SetEquirectangular2( double dfCenterLat, double dfCenterLong,
391  double dfPseudoStdParallel1,
392  double dfFalseEasting, double dfFalseNorthing );
393 
395  OGRErr SetGEOS( double dfCentralMeridian, double dfSatelliteHeight,
396  double dfFalseEasting, double dfFalseNorthing );
397 
399  OGRErr SetGH( double dfCentralMeridian,
400  double dfFalseEasting, double dfFalseNorthing );
401 
403  OGRErr SetIGH();
404 
406  OGRErr SetGS( double dfCentralMeridian,
407  double dfFalseEasting, double dfFalseNorthing );
408 
410  OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
411  double dfScale,
412  double dfFalseEasting, double dfFalseNorthing );
413 
415  OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
416  double dfFalseEasting, double dfFalseNorthing );
417 
419  OGRErr SetHOM( double dfCenterLat, double dfCenterLong,
420  double dfAzimuth, double dfRectToSkew,
421  double dfScale,
422  double dfFalseEasting, double dfFalseNorthing );
423 
425  OGRErr SetHOM2PNO( double dfCenterLat,
426  double dfLat1, double dfLong1,
427  double dfLat2, double dfLong2,
428  double dfScale,
429  double dfFalseEasting, double dfFalseNorthing );
430 
431 #ifdef undef
432 
433  OGRErr SetOM( double dfCenterLat, double dfCenterLong,
434  double dfAzimuth, double dfRectToSkew,
435  double dfScale,
436  double dfFalseEasting, double dfFalseNorthing );
437 #endif
438 
440  OGRErr SetHOMAC( double dfCenterLat, double dfCenterLong,
441  double dfAzimuth, double dfRectToSkew,
442  double dfScale,
443  double dfFalseEasting, double dfFalseNorthing );
444 
446  OGRErr SetIWMPolyconic( double dfLat1, double dfLat2,
447  double dfCenterLong,
448  double dfFalseEasting,
449  double dfFalseNorthing );
450 
452  OGRErr SetKrovak( double dfCenterLat, double dfCenterLong,
453  double dfAzimuth, double dfPseudoStdParallelLat,
454  double dfScale,
455  double dfFalseEasting, double dfFalseNorthing );
456 
458  OGRErr SetLAEA( double dfCenterLat, double dfCenterLong,
459  double dfFalseEasting, double dfFalseNorthing );
460 
462  OGRErr SetLCC( double dfStdP1, double dfStdP2,
463  double dfCenterLat, double dfCenterLong,
464  double dfFalseEasting, double dfFalseNorthing );
465 
467  OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong,
468  double dfScale,
469  double dfFalseEasting, double dfFalseNorthing );
470 
472  OGRErr SetLCCB( double dfStdP1, double dfStdP2,
473  double dfCenterLat, double dfCenterLong,
474  double dfFalseEasting, double dfFalseNorthing );
475 
477  OGRErr SetMC( double dfCenterLat, double dfCenterLong,
478  double dfFalseEasting, double dfFalseNorthing );
479 
481  OGRErr SetMercator( double dfCenterLat, double dfCenterLong,
482  double dfScale,
483  double dfFalseEasting, double dfFalseNorthing );
484 
486  OGRErr SetMercator2SP( double dfStdP1,
487  double dfCenterLat, double dfCenterLong,
488  double dfFalseEasting, double dfFalseNorthing );
489 
491  OGRErr SetMollweide( double dfCentralMeridian,
492  double dfFalseEasting, double dfFalseNorthing );
493 
495  OGRErr SetNZMG( double dfCenterLat, double dfCenterLong,
496  double dfFalseEasting, double dfFalseNorthing );
497 
499  OGRErr SetOS( double dfOriginLat, double dfCMeridian,
500  double dfScale,
501  double dfFalseEasting,double dfFalseNorthing);
502 
504  OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong,
505  double dfFalseEasting,double dfFalseNorthing);
506 
508  OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong,
509  double dfFalseEasting, double dfFalseNorthing );
510 
512  OGRErr SetPS( double dfCenterLat, double dfCenterLong,
513  double dfScale,
514  double dfFalseEasting, double dfFalseNorthing);
515 
517  OGRErr SetRobinson( double dfCenterLong,
518  double dfFalseEasting, double dfFalseNorthing );
519 
521  OGRErr SetSinusoidal( double dfCenterLong,
522  double dfFalseEasting, double dfFalseNorthing );
523 
525  OGRErr SetStereographic( double dfCenterLat, double dfCenterLong,
526  double dfScale,
527  double dfFalseEasting,double dfFalseNorthing);
528 
530  OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
531  double dfFalseEasting, double dfFalseNorthing );
532 
534  OGRErr SetTM( double dfCenterLat, double dfCenterLong,
535  double dfScale,
536  double dfFalseEasting, double dfFalseNorthing );
537 
539  OGRErr SetTMVariant( const char *pszVariantName,
540  double dfCenterLat, double dfCenterLong,
541  double dfScale,
542  double dfFalseEasting, double dfFalseNorthing );
543 
545  OGRErr SetTMG( double dfCenterLat, double dfCenterLong,
546  double dfFalseEasting, double dfFalseNorthing );
547 
549  OGRErr SetTMSO( double dfCenterLat, double dfCenterLong,
550  double dfScale,
551  double dfFalseEasting, double dfFalseNorthing );
552 
554  OGRErr SetTPED( double dfLat1, double dfLong1,
555  double dfLat2, double dfLong2,
556  double dfFalseEasting, double dfFalseNorthing );
557 
559  OGRErr SetVDG( double dfCenterLong,
560  double dfFalseEasting, double dfFalseNorthing );
561 
563  OGRErr SetUTM( int nZone, int bNorth = TRUE );
564  int GetUTMZone( int *pbNorth = NULL ) const;
565 
567  OGRErr SetWagner( int nVariation, double dfCenterLat,
568  double dfFalseEasting, double dfFalseNorthing );
569 
571  OGRErr SetQSC(double dfCenterLat, double dfCenterLong);
572 
574  OGRErr SetSCH( double dfPegLat, double dfPegLong,
575  double dfPegHeading, double dfPegHgt);
577  OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE,
578  const char *pszOverrideUnitName = NULL,
579  double dfOverrideUnit = 0.0 );
580 
582  OGRErr ImportFromESRIStatePlaneWKT(
583  int nCode, const char* pszDatumName, const char* pszUnitsName,
584  int nPCSCode, const char* pszCSName = NULL );
585 
587  OGRErr ImportFromESRIWisconsinWKT(
588  const char* pszPrjName, double dfCentralMeridian, double dfLatOfOrigin,
589  const char* pszUnitsName, const char* pszCSName = NULL );
590 
591  static OGRSpatialReference* GetWGS84SRS();
592 };
593 
594 /************************************************************************/
595 /* OGRCoordinateTransformation */
596 /* */
597 /* This is really just used as a base class for a private */
598 /* implementation. */
599 /************************************************************************/
600 
611 {
612 public:
613  virtual ~OGRCoordinateTransformation() {}
614 
615  static void DestroyCT(OGRCoordinateTransformation* poCT);
616 
617  // From CT_CoordinateTransformation
618 
620  virtual OGRSpatialReference *GetSourceCS() = 0;
621 
623  virtual OGRSpatialReference *GetTargetCS() = 0;
624 
626  virtual bool GetEmitErrors() { return false; }
627 
629  virtual void SetEmitErrors(bool /*bEmitErrors*/) {}
630 
631  // From CT_MathTransform
632 
648  virtual int Transform( int nCount,
649  double *x, double *y, double *z = NULL ) = 0;
650 
666  virtual int TransformEx( int nCount,
667  double *x, double *y, double *z = NULL,
668  int *pabSuccess = NULL ) = 0;
669 };
670 
673  OGRSpatialReference *poTarget );
674 
675 #endif /* ndef OGR_SPATIALREF_H_INCLUDED */
virtual void SetEmitErrors(bool)
Set if the transformer must emit CPLError.
Definition: ogr_spatialref.h:629
OGRCoordinateTransformation * OGRCreateCoordinateTransformation(OGRSpatialReference *poSource, OGRSpatialReference *poTarget)
Create transformation object.
Definition: ogrct.cpp:433
Objects of this class are used to represent value nodes in the parsed representation of the WKT SRS f...
Definition: ogr_spatialref.h:62
int IsLeafNode() const
Return whether this is a leaf node.
Definition: ogr_spatialref.h:81
const char * GetValue() const
Fetch value string for this node.
Definition: ogr_spatialref.h:97
#define USGS_ANGLE_PACKEDDMS
Angle is in packed degree minute second.
Definition: ogr_spatialref.h:203
OGR_SRSNode * GetRoot()
Return root node.
Definition: ogr_spatialref.h:242
void * OGRSpatialReferenceH
Opaque type for a spatial reference system.
Definition: ogr_api.h:69
C spatial reference system services and defines.
OGRAxisOrientation
Axis orientations (corresponds to CS_AxisOrientationEnum).
Definition: ogr_srs_api.h:48
virtual bool GetEmitErrors()
Whether the transformer will emit CPLError.
Definition: ogr_spatialref.h:626
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:134
int GetReferenceCount() const
Fetch current reference count.
Definition: ogr_spatialref.h:176
Interface for transforming between coordinate systems.
Definition: ogr_spatialref.h:610
const OGR_SRSNode * GetRoot() const
Return root node.
Definition: ogr_spatialref.h:244
int OGRErr
Simple container for a bounding region.
Definition: ogr_core.h:287
int GetChildCount() const
Get number of children nodes.
Definition: ogr_spatialref.h:83

Generated for GDAL by doxygen 1.8.8.