GDAL
ogr_spatialref.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_spatialref.h 39776 2017-08-08 14:51:37Z 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 
43 /************************************************************************/
44 /* OGR_SRSNode */
45 /************************************************************************/
46 
60 class CPL_DLL OGR_SRSNode
61 {
62  char *pszValue;
63 
64  OGR_SRSNode **papoChildNodes;
65  OGR_SRSNode *poParent;
66 
67  int nChildren;
68 
69  int NeedsQuoting() const;
70  OGRErr importFromWkt( char **, int nRecLevel, int* pnNodes );
71 
72  public:
73  explicit OGR_SRSNode(const char * = NULL);
74  ~OGR_SRSNode();
75 
79  int IsLeafNode() const { return nChildren == 0; }
80 
81  int GetChildCount() const { return nChildren; }
82  OGR_SRSNode *GetChild( int );
83  const OGR_SRSNode *GetChild( int ) const;
84 
85  OGR_SRSNode *GetNode( const char * );
86  const OGR_SRSNode *GetNode( const char * ) const;
87 
88  void InsertChild( OGR_SRSNode *, int );
89  void AddChild( OGR_SRSNode * );
90  int FindChild( const char * ) const;
91  void DestroyChild( int );
92  void ClearChildren();
93  void StripNodes( const char * );
94 
95  const char *GetValue() const { return pszValue; }
96  void SetValue( const char * );
97 
98  void MakeValueSafe();
99  OGRErr FixupOrdering();
100 
101  OGR_SRSNode *Clone() const;
102 
103  OGRErr importFromWkt( char ** );
104  OGRErr exportToWkt( char ** ) const;
105  OGRErr exportToPrettyWkt( char **, int = 1) const;
106 
107  OGRErr applyRemapper( const char *pszNode,
108  char **papszSrcValues,
109  char **papszDstValues,
110  int nStepSize = 1,
111  int bChildOfHit = FALSE );
112 };
113 
114 /************************************************************************/
115 /* OGRSpatialReference */
116 /************************************************************************/
117 
132 class CPL_DLL OGRSpatialReference
133 {
134  double dfFromGreenwich;
135  double dfToMeter;
136  double dfToDegrees;
137 
138  OGR_SRSNode *poRoot;
139 
140  int nRefCount;
141  int bNormInfoSet;
142 
143  static OGRErr Validate(OGR_SRSNode *poRoot);
144  static OGRErr ValidateAuthority(OGR_SRSNode *poRoot);
145  static OGRErr ValidateAxis(OGR_SRSNode *poRoot);
146  static OGRErr ValidateUnit(OGR_SRSNode *poRoot);
147  static OGRErr ValidateVertDatum(OGR_SRSNode *poRoot);
148  static OGRErr ValidateProjection( OGR_SRSNode* poRoot );
149  static int IsAliasFor( const char *, const char * );
150  void GetNormInfo() const;
151 
152  OGRErr importFromURNPart(const char* pszAuthority,
153  const char* pszCode,
154  const char* pszURN);
155  public:
157  explicit OGRSpatialReference(const char * = NULL);
158 
159  virtual ~OGRSpatialReference();
160 
161  static void DestroySpatialReference(OGRSpatialReference* poSRS);
162 
163  OGRSpatialReference &operator=(const OGRSpatialReference&);
164 
165  int Reference();
166  int Dereference();
167  int GetReferenceCount() const { return nRefCount; }
168  void Release();
169 
170  OGRSpatialReference *Clone() const;
171  OGRSpatialReference *CloneGeogCS() const;
172 
173  void dumpReadable();
174  OGRErr exportToWkt( char ** ) const;
175  OGRErr exportToPrettyWkt( char **, int = FALSE) const;
176  OGRErr exportToProj4( char ** ) const;
177  OGRErr exportToPCI( char **, char **, double ** ) const;
178  OGRErr exportToUSGS( long *, long *, double **, long * ) const;
179  OGRErr exportToXML( char **, const char * = NULL ) const;
180  OGRErr exportToPanorama( long *, long *, long *, long *,
181  double * ) const;
182  OGRErr exportToERM( char *pszProj, char *pszDatum, char *pszUnits );
183  OGRErr exportToMICoordSys( char ** ) const;
184 
185  OGRErr importFromWkt( char ** );
186  OGRErr importFromProj4( const char * );
187  OGRErr importFromEPSG( int );
188  OGRErr importFromEPSGA( int );
189  OGRErr importFromESRI( char ** );
190  OGRErr importFromPCI( const char *, const char * = NULL,
191  double * = NULL );
192 
193 #define USGS_ANGLE_DECIMALDEGREES 0
194 #define USGS_ANGLE_PACKEDDMS TRUE
195 #define USGS_ANGLE_RADIANS 2
196  OGRErr importFromUSGS( long iProjSys, long iZone,
197  double *padfPrjParams, long iDatum,
198  int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS );
199  OGRErr importFromPanorama( long, long, long, double* );
200  OGRErr importFromOzi( const char * const* papszLines );
201  OGRErr importFromWMSAUTO( const char *pszAutoDef );
202  OGRErr importFromXML( const char * );
203  OGRErr importFromDict( const char *pszDict, const char *pszCode );
204  OGRErr importFromURN( const char * );
205  OGRErr importFromCRSURL( const char * );
206  OGRErr importFromERM( const char *pszProj, const char *pszDatum,
207  const char *pszUnits );
208  OGRErr importFromUrl( const char * );
209  OGRErr importFromMICoordSys( const char * );
210 
211  OGRErr morphToESRI();
212  OGRErr morphFromESRI();
213 
214  OGRErr Validate();
215  OGRErr StripCTParms( OGR_SRSNode * = NULL );
216  OGRErr StripVertical();
217  OGRErr FixupOrdering();
218  OGRErr Fixup();
219 
220  int EPSGTreatsAsLatLong();
221  int EPSGTreatsAsNorthingEasting();
222  const char *GetAxis( const char *pszTargetKey, int iAxis,
223  OGRAxisOrientation *peOrientation ) const;
224  OGRErr SetAxes( const char *pszTargetKey,
225  const char *pszXAxisName,
226  OGRAxisOrientation eXAxisOrientation,
227  const char *pszYAxisName,
228  OGRAxisOrientation eYAxisOrientation );
229 
230  // Machinery for accessing parse nodes
231 
233  OGR_SRSNode *GetRoot() { return poRoot; }
235  const OGR_SRSNode *GetRoot() const { return poRoot; }
236  void SetRoot( OGR_SRSNode * );
237 
238  OGR_SRSNode *GetAttrNode(const char *);
239  const OGR_SRSNode *GetAttrNode(const char *) const;
240  const char *GetAttrValue(const char *, int = 0) const;
241 
242  OGRErr SetNode( const char *, const char * );
243  OGRErr SetNode( const char *, double );
244 
245  OGRErr SetLinearUnitsAndUpdateParameters( const char *pszName,
246  double dfInMeters );
247  OGRErr SetLinearUnits( const char *pszName, double dfInMeters );
248  OGRErr SetTargetLinearUnits( const char *pszTargetKey,
249  const char *pszName, double dfInMeters );
250  double GetLinearUnits( char ** = NULL ) const;
251  double GetTargetLinearUnits( const char *pszTargetKey,
252  char ** ppszRetName = NULL ) const;
253 
254  OGRErr SetAngularUnits( const char *pszName, double dfInRadians );
255  double GetAngularUnits( char ** = NULL ) const;
256 
257  double GetPrimeMeridian( char ** = NULL ) const;
258 
259  int IsGeographic() const;
260  int IsProjected() const;
261  int IsGeocentric() const;
262  int IsLocal() const;
263  int IsVertical() const;
264  int IsCompound() const;
265  int IsSameGeogCS( const OGRSpatialReference * ) const;
266  int IsSameVertCS( const OGRSpatialReference * ) const;
267  int IsSame( const OGRSpatialReference * ) const;
268 
269  void Clear();
270  OGRErr SetLocalCS( const char * );
271  OGRErr SetProjCS( const char * );
272  OGRErr SetProjection( const char * );
273  OGRErr SetGeocCS( const char * pszGeocName );
274  OGRErr SetGeogCS( const char * pszGeogName,
275  const char * pszDatumName,
276  const char * pszEllipsoidName,
277  double dfSemiMajor, double dfInvFlattening,
278  const char * pszPMName = NULL,
279  double dfPMOffset = 0.0,
280  const char * pszUnits = NULL,
281  double dfConvertToRadians = 0.0 );
282  OGRErr SetWellKnownGeogCS( const char * );
283  OGRErr CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
284  OGRErr SetVertCS( const char *pszVertCSName,
285  const char *pszVertDatumName,
286  int nVertDatumClass = 2005 );
287  OGRErr SetCompoundCS( const char *pszName,
288  const OGRSpatialReference *poHorizSRS,
289  const OGRSpatialReference *poVertSRS );
290 
291  OGRErr SetFromUserInput( const char * );
292 
293  OGRErr SetTOWGS84( double, double, double,
294  double = 0.0, double = 0.0, double = 0.0,
295  double = 0.0 );
296  OGRErr GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
297 
298  double GetSemiMajor( OGRErr * = NULL ) const;
299  double GetSemiMinor( OGRErr * = NULL ) const;
300  double GetInvFlattening( OGRErr * = NULL ) const;
301 
302  OGRErr SetAuthority( const char * pszTargetKey,
303  const char * pszAuthority,
304  int nCode );
305 
306  OGRErr AutoIdentifyEPSG();
307  int GetEPSGGeogCS();
308 
309  const char *GetAuthorityCode( const char * pszTargetKey ) const;
310  const char *GetAuthorityName( const char * pszTargetKey ) const;
311 
312  const char *GetExtension( const char *pszTargetKey,
313  const char *pszName,
314  const char *pszDefault = NULL ) const;
315  OGRErr SetExtension( const char *pszTargetKey,
316  const char *pszName,
317  const char *pszValue );
318 
319  int FindProjParm( const char *pszParameter,
320  const OGR_SRSNode *poPROJCS=NULL ) const;
321  OGRErr SetProjParm( const char *, double );
322  double GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
323 
324  OGRErr SetNormProjParm( const char *, double );
325  double GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
326 
327  static int IsAngularParameter( const char * );
328  static int IsLongitudeParameter( const char * );
329  static int IsLinearParameter( const char * );
330 
332  OGRErr SetACEA( double dfStdP1, double dfStdP2,
333  double dfCenterLat, double dfCenterLong,
334  double dfFalseEasting, double dfFalseNorthing );
335 
337  OGRErr SetAE( double dfCenterLat, double dfCenterLong,
338  double dfFalseEasting, double dfFalseNorthing );
339 
341  OGRErr SetBonne( double dfStdP1, double dfCentralMeridian,
342  double dfFalseEasting, double dfFalseNorthing );
343 
345  OGRErr SetCEA( double dfStdP1, double dfCentralMeridian,
346  double dfFalseEasting, double dfFalseNorthing );
347 
349  OGRErr SetCS( double dfCenterLat, double dfCenterLong,
350  double dfFalseEasting, double dfFalseNorthing );
351 
353  OGRErr SetEC( double dfStdP1, double dfStdP2,
354  double dfCenterLat, double dfCenterLong,
355  double dfFalseEasting, double dfFalseNorthing );
356 
358  OGRErr SetEckert( int nVariation, double dfCentralMeridian,
359  double dfFalseEasting, double dfFalseNorthing );
360 
362  OGRErr SetEckertIV( double dfCentralMeridian,
363  double dfFalseEasting, double dfFalseNorthing );
364 
366  OGRErr SetEckertVI( double dfCentralMeridian,
367  double dfFalseEasting, double dfFalseNorthing );
368 
370  OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
371  double dfFalseEasting, double dfFalseNorthing );
373  OGRErr SetEquirectangular2( double dfCenterLat, double dfCenterLong,
374  double dfPseudoStdParallel1,
375  double dfFalseEasting, double dfFalseNorthing );
376 
378  OGRErr SetGEOS( double dfCentralMeridian, double dfSatelliteHeight,
379  double dfFalseEasting, double dfFalseNorthing );
380 
382  OGRErr SetGH( double dfCentralMeridian,
383  double dfFalseEasting, double dfFalseNorthing );
384 
386  OGRErr SetIGH();
387 
389  OGRErr SetGS( double dfCentralMeridian,
390  double dfFalseEasting, double dfFalseNorthing );
391 
393  OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
394  double dfScale,
395  double dfFalseEasting, double dfFalseNorthing );
396 
398  OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
399  double dfFalseEasting, double dfFalseNorthing );
400 
402  OGRErr SetHOM( double dfCenterLat, double dfCenterLong,
403  double dfAzimuth, double dfRectToSkew,
404  double dfScale,
405  double dfFalseEasting, double dfFalseNorthing );
406 
408  OGRErr SetHOM2PNO( double dfCenterLat,
409  double dfLat1, double dfLong1,
410  double dfLat2, double dfLong2,
411  double dfScale,
412  double dfFalseEasting, double dfFalseNorthing );
413 
414 #ifdef undef
415 
416  OGRErr SetOM( double dfCenterLat, double dfCenterLong,
417  double dfAzimuth, double dfRectToSkew,
418  double dfScale,
419  double dfFalseEasting, double dfFalseNorthing );
420 #endif
421 
423  OGRErr SetHOMAC( double dfCenterLat, double dfCenterLong,
424  double dfAzimuth, double dfRectToSkew,
425  double dfScale,
426  double dfFalseEasting, double dfFalseNorthing );
427 
429  OGRErr SetIWMPolyconic( double dfLat1, double dfLat2,
430  double dfCenterLong,
431  double dfFalseEasting,
432  double dfFalseNorthing );
433 
435  OGRErr SetKrovak( double dfCenterLat, double dfCenterLong,
436  double dfAzimuth, double dfPseudoStdParallelLat,
437  double dfScale,
438  double dfFalseEasting, double dfFalseNorthing );
439 
441  OGRErr SetLAEA( double dfCenterLat, double dfCenterLong,
442  double dfFalseEasting, double dfFalseNorthing );
443 
445  OGRErr SetLCC( double dfStdP1, double dfStdP2,
446  double dfCenterLat, double dfCenterLong,
447  double dfFalseEasting, double dfFalseNorthing );
448 
450  OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong,
451  double dfScale,
452  double dfFalseEasting, double dfFalseNorthing );
453 
455  OGRErr SetLCCB( double dfStdP1, double dfStdP2,
456  double dfCenterLat, double dfCenterLong,
457  double dfFalseEasting, double dfFalseNorthing );
458 
460  OGRErr SetMC( double dfCenterLat, double dfCenterLong,
461  double dfFalseEasting, double dfFalseNorthing );
462 
464  OGRErr SetMercator( double dfCenterLat, double dfCenterLong,
465  double dfScale,
466  double dfFalseEasting, double dfFalseNorthing );
467 
469  OGRErr SetMercator2SP( double dfStdP1,
470  double dfCenterLat, double dfCenterLong,
471  double dfFalseEasting, double dfFalseNorthing );
472 
474  OGRErr SetMollweide( double dfCentralMeridian,
475  double dfFalseEasting, double dfFalseNorthing );
476 
478  OGRErr SetNZMG( double dfCenterLat, double dfCenterLong,
479  double dfFalseEasting, double dfFalseNorthing );
480 
482  OGRErr SetOS( double dfOriginLat, double dfCMeridian,
483  double dfScale,
484  double dfFalseEasting,double dfFalseNorthing);
485 
487  OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong,
488  double dfFalseEasting,double dfFalseNorthing);
489 
491  OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong,
492  double dfFalseEasting, double dfFalseNorthing );
493 
495  OGRErr SetPS( double dfCenterLat, double dfCenterLong,
496  double dfScale,
497  double dfFalseEasting, double dfFalseNorthing);
498 
500  OGRErr SetRobinson( double dfCenterLong,
501  double dfFalseEasting, double dfFalseNorthing );
502 
504  OGRErr SetSinusoidal( double dfCenterLong,
505  double dfFalseEasting, double dfFalseNorthing );
506 
508  OGRErr SetStereographic( double dfCenterLat, double dfCenterLong,
509  double dfScale,
510  double dfFalseEasting,double dfFalseNorthing);
511 
513  OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
514  double dfFalseEasting, double dfFalseNorthing );
515 
517  OGRErr SetTM( double dfCenterLat, double dfCenterLong,
518  double dfScale,
519  double dfFalseEasting, double dfFalseNorthing );
520 
522  OGRErr SetTMVariant( const char *pszVariantName,
523  double dfCenterLat, double dfCenterLong,
524  double dfScale,
525  double dfFalseEasting, double dfFalseNorthing );
526 
528  OGRErr SetTMG( double dfCenterLat, double dfCenterLong,
529  double dfFalseEasting, double dfFalseNorthing );
530 
532  OGRErr SetTMSO( double dfCenterLat, double dfCenterLong,
533  double dfScale,
534  double dfFalseEasting, double dfFalseNorthing );
535 
537  OGRErr SetTPED( double dfLat1, double dfLong1,
538  double dfLat2, double dfLong2,
539  double dfFalseEasting, double dfFalseNorthing );
540 
542  OGRErr SetVDG( double dfCenterLong,
543  double dfFalseEasting, double dfFalseNorthing );
544 
546  OGRErr SetUTM( int nZone, int bNorth = TRUE );
547  int GetUTMZone( int *pbNorth = NULL ) const;
548 
550  OGRErr SetWagner( int nVariation, double dfCenterLat,
551  double dfFalseEasting, double dfFalseNorthing );
552 
554  OGRErr SetQSC(double dfCenterLat, double dfCenterLong);
555 
557  OGRErr SetSCH( double dfPegLat, double dfPegLong,
558  double dfPegHeading, double dfPegHgt);
560  OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE,
561  const char *pszOverrideUnitName = NULL,
562  double dfOverrideUnit = 0.0 );
563 
565  OGRErr ImportFromESRIStatePlaneWKT(
566  int nCode, const char* pszDatumName, const char* pszUnitsName,
567  int nPCSCode, const char* pszCSName = NULL );
568 
570  OGRErr ImportFromESRIWisconsinWKT(
571  const char* pszPrjName, double dfCentralMeridian, double dfLatOfOrigin,
572  const char* pszUnitsName, const char* pszCSName = NULL );
573 
574  static OGRSpatialReference* GetWGS84SRS();
575 };
576 
577 /************************************************************************/
578 /* OGRCoordinateTransformation */
579 /* */
580 /* This is really just used as a base class for a private */
581 /* implementation. */
582 /************************************************************************/
583 
594 {
595 public:
596  virtual ~OGRCoordinateTransformation() {}
597 
598  static void DestroyCT(OGRCoordinateTransformation* poCT);
599 
600  // From CT_CoordinateTransformation
601 
603  virtual OGRSpatialReference *GetSourceCS() = 0;
604 
606  virtual OGRSpatialReference *GetTargetCS() = 0;
607 
609  virtual bool GetEmitErrors() { return false; }
610 
612  virtual void SetEmitErrors(bool /*bEmitErrors*/) {}
613 
614  // From CT_MathTransform
615 
631  virtual int Transform( int nCount,
632  double *x, double *y, double *z = NULL ) = 0;
633 
649  virtual int TransformEx( int nCount,
650  double *x, double *y, double *z = NULL,
651  int *pabSuccess = NULL ) = 0;
652 };
653 
656  OGRSpatialReference *poTarget );
657 
658 #endif /* ndef OGR_SPATIALREF_H_INCLUDED */
virtual void SetEmitErrors(bool)
Set if the transformer must emit CPLError.
Definition: ogr_spatialref.h:612
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:60
int IsLeafNode() const
Return whether this is a leaf node.
Definition: ogr_spatialref.h:79
const char * GetValue() const
Fetch value string for this node.
Definition: ogr_spatialref.h:95
#define USGS_ANGLE_PACKEDDMS
Angle is in packed degree minute second.
Definition: ogr_spatialref.h:194
OGR_SRSNode * GetRoot()
Return root node.
Definition: ogr_spatialref.h:233
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:609
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:132
int GetReferenceCount() const
Fetch current reference count.
Definition: ogr_spatialref.h:167
Interface for transforming between coordinate systems.
Definition: ogr_spatialref.h:593
const OGR_SRSNode * GetRoot() const
Return root node.
Definition: ogr_spatialref.h:235
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:81

Generated for GDAL by doxygen 1.8.8.