OGR
ogr_spatialref.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_spatialref.h 26289 2013-08-10 18:05:31Z 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  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef _OGR_SPATIALREF_H_INCLUDED
32 #define _OGR_SPATIALREF_H_INCLUDED
33 
34 #include "ogr_srs_api.h"
35 
42 /************************************************************************/
43 /* OGR_SRSNode */
44 /************************************************************************/
45 
59 class CPL_DLL OGR_SRSNode
60 {
61  char *pszValue;
62 
63  OGR_SRSNode **papoChildNodes;
64  OGR_SRSNode *poParent;
65 
66  int nChildren;
67 
68  int NeedsQuoting() const;
69  OGRErr importFromWkt( char **, int nRecLevel, int* pnNodes );
70 
71  public:
72  OGR_SRSNode(const char * = NULL);
73  ~OGR_SRSNode();
74 
75  int IsLeafNode() const { return nChildren == 0; }
76 
77  int GetChildCount() const { return nChildren; }
78  OGR_SRSNode *GetChild( int );
79  const OGR_SRSNode *GetChild( int ) const;
80 
81  OGR_SRSNode *GetNode( const char * );
82  const OGR_SRSNode *GetNode( const char * ) const;
83 
84  void InsertChild( OGR_SRSNode *, int );
85  void AddChild( OGR_SRSNode * );
86  int FindChild( const char * ) const;
87  void DestroyChild( int );
88  void ClearChildren();
89  void StripNodes( const char * );
90 
91  const char *GetValue() const { return pszValue; }
92  void SetValue( const char * );
93 
94  void MakeValueSafe();
95  OGRErr FixupOrdering();
96 
97  OGR_SRSNode *Clone() const;
98 
99  OGRErr importFromWkt( char ** );
100  OGRErr exportToWkt( char ** ) const;
101  OGRErr exportToPrettyWkt( char **, int = 1) const;
102 
103  OGRErr applyRemapper( const char *pszNode,
104  char **papszSrcValues,
105  char **papszDstValues,
106  int nStepSize = 1,
107  int bChildOfHit = FALSE );
108 };
109 
110 /************************************************************************/
111 /* OGRSpatialReference */
112 /************************************************************************/
113 
128 class CPL_DLL OGRSpatialReference
129 {
130  double dfFromGreenwich;
131  double dfToMeter;
132  double dfToDegrees;
133 
134  OGR_SRSNode *poRoot;
135 
136  int nRefCount;
137  int bNormInfoSet;
138 
139  static OGRErr Validate(OGR_SRSNode *poRoot);
140  static OGRErr ValidateAuthority(OGR_SRSNode *poRoot);
141  static OGRErr ValidateAxis(OGR_SRSNode *poRoot);
142  static OGRErr ValidateUnit(OGR_SRSNode *poRoot);
143  static OGRErr ValidateVertDatum(OGR_SRSNode *poRoot);
144  static OGRErr ValidateProjection( OGR_SRSNode* poRoot );
145  static int IsAliasFor( const char *, const char * );
146  void GetNormInfo() const;
147 
148  OGRErr importFromURNPart(const char* pszAuthority,
149  const char* pszCode,
150  const char* pszURN);
151  public:
153  OGRSpatialReference(const char * = NULL);
154 
155  virtual ~OGRSpatialReference();
156 
157  static void DestroySpatialReference(OGRSpatialReference* poSRS);
158 
159  OGRSpatialReference &operator=(const OGRSpatialReference&);
160 
161  int Reference();
162  int Dereference();
163  int GetReferenceCount() const { return nRefCount; }
164  void Release();
165 
166  OGRSpatialReference *Clone() const;
167  OGRSpatialReference *CloneGeogCS() const;
168 
169  void dumpReadable();
170  OGRErr exportToWkt( char ** ) const;
171  OGRErr exportToPrettyWkt( char **, int = FALSE) const;
172  OGRErr exportToProj4( char ** ) const;
173  OGRErr exportToPCI( char **, char **, double ** ) const;
174  OGRErr exportToUSGS( long *, long *, double **, long * ) const;
175  OGRErr exportToXML( char **, const char * = NULL ) const;
176  OGRErr exportToPanorama( long *, long *, long *, long *,
177  double * ) const;
178  OGRErr exportToERM( char *pszProj, char *pszDatum, char *pszUnits );
179  OGRErr exportToMICoordSys( char ** ) const;
180 
181  OGRErr importFromWkt( char ** );
182  OGRErr importFromProj4( const char * );
183  OGRErr importFromEPSG( int );
184  OGRErr importFromEPSGA( int );
185  OGRErr importFromESRI( char ** );
186  OGRErr importFromPCI( const char *, const char * = NULL,
187  double * = NULL );
188 #define USGS_ANGLE_DECIMALDEGREES 0
189 #define USGS_ANGLE_PACKEDDMS TRUE /* 1 */
190 #define USGS_ANGLE_RADIANS 2
191  OGRErr importFromUSGS( long iProjSys, long iZone,
192  double *padfPrjParams, long iDatum,
193  int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS );
194  OGRErr importFromPanorama( long, long, long, double* );
195  OGRErr importFromOzi( const char *, const char *, const char * );
196  OGRErr importFromOzi( const char * const* papszLines );
197  OGRErr importFromWMSAUTO( const char *pszAutoDef );
198  OGRErr importFromXML( const char * );
199  OGRErr importFromDict( const char *pszDict, const char *pszCode );
200  OGRErr importFromURN( const char * );
201  OGRErr importFromCRSURL( const char * );
202  OGRErr importFromERM( const char *pszProj, const char *pszDatum,
203  const char *pszUnits );
204  OGRErr importFromUrl( const char * );
205  OGRErr importFromMICoordSys( const char * );
206 
207  OGRErr morphToESRI();
208  OGRErr morphFromESRI();
209 
210  OGRErr Validate();
211  OGRErr StripCTParms( OGR_SRSNode * = NULL );
212  OGRErr StripVertical();
213  OGRErr FixupOrdering();
214  OGRErr Fixup();
215 
216  int EPSGTreatsAsLatLong();
217  int EPSGTreatsAsNorthingEasting();
218  const char *GetAxis( const char *pszTargetKey, int iAxis,
219  OGRAxisOrientation *peOrientation ) const;
220  OGRErr SetAxes( const char *pszTargetKey,
221  const char *pszXAxisName,
222  OGRAxisOrientation eXAxisOrientation,
223  const char *pszYAxisName,
224  OGRAxisOrientation eYAxisOrientation );
225 
226  // Machinary for accessing parse nodes
227  OGR_SRSNode *GetRoot() { return poRoot; }
228  const OGR_SRSNode *GetRoot() const { return poRoot; }
229  void SetRoot( OGR_SRSNode * );
230 
231  OGR_SRSNode *GetAttrNode(const char *);
232  const OGR_SRSNode *GetAttrNode(const char *) const;
233  const char *GetAttrValue(const char *, int = 0) const;
234 
235  OGRErr SetNode( const char *, const char * );
236  OGRErr SetNode( const char *, double );
237 
238  OGRErr SetLinearUnitsAndUpdateParameters( const char *pszName,
239  double dfInMeters );
240  OGRErr SetLinearUnits( const char *pszName, double dfInMeters );
241  OGRErr SetTargetLinearUnits( const char *pszTargetKey,
242  const char *pszName, double dfInMeters );
243  double GetLinearUnits( char ** = NULL ) const;
244  double GetTargetLinearUnits( const char *pszTargetKey,
245  char ** ppszRetName = NULL ) const;
246 
247  OGRErr SetAngularUnits( const char *pszName, double dfInRadians );
248  double GetAngularUnits( char ** = NULL ) const;
249 
250  double GetPrimeMeridian( char ** = NULL ) const;
251 
252  int IsGeographic() const;
253  int IsProjected() const;
254  int IsGeocentric() const;
255  int IsLocal() const;
256  int IsVertical() const;
257  int IsCompound() const;
258  int IsSameGeogCS( const OGRSpatialReference * ) const;
259  int IsSameVertCS( const OGRSpatialReference * ) const;
260  int IsSame( const OGRSpatialReference * ) const;
261 
262  void Clear();
263  OGRErr SetLocalCS( const char * );
264  OGRErr SetProjCS( const char * );
265  OGRErr SetProjection( const char * );
266  OGRErr SetGeocCS( const char * pszGeocName );
267  OGRErr SetGeogCS( const char * pszGeogName,
268  const char * pszDatumName,
269  const char * pszEllipsoidName,
270  double dfSemiMajor, double dfInvFlattening,
271  const char * pszPMName = NULL,
272  double dfPMOffset = 0.0,
273  const char * pszUnits = NULL,
274  double dfConvertToRadians = 0.0 );
275  OGRErr SetWellKnownGeogCS( const char * );
276  OGRErr CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
277  OGRErr SetVertCS( const char *pszVertCSName,
278  const char *pszVertDatumName,
279  int nVertDatumClass = 2005 );
280  OGRErr SetCompoundCS( const char *pszName,
281  const OGRSpatialReference *poHorizSRS,
282  const OGRSpatialReference *poVertSRS );
283 
284  OGRErr SetFromUserInput( const char * );
285 
286  OGRErr SetTOWGS84( double, double, double,
287  double = 0.0, double = 0.0, double = 0.0,
288  double = 0.0 );
289  OGRErr GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
290 
291  double GetSemiMajor( OGRErr * = NULL ) const;
292  double GetSemiMinor( OGRErr * = NULL ) const;
293  double GetInvFlattening( OGRErr * = NULL ) const;
294 
295  OGRErr SetAuthority( const char * pszTargetKey,
296  const char * pszAuthority,
297  int nCode );
298 
299  OGRErr AutoIdentifyEPSG();
300  int GetEPSGGeogCS();
301 
302  const char *GetAuthorityCode( const char * pszTargetKey ) const;
303  const char *GetAuthorityName( const char * pszTargetKey ) const;
304 
305  const char *GetExtension( const char *pszTargetKey,
306  const char *pszName,
307  const char *pszDefault = NULL ) const;
308  OGRErr SetExtension( const char *pszTargetKey,
309  const char *pszName,
310  const char *pszValue );
311 
312  int FindProjParm( const char *pszParameter,
313  const OGR_SRSNode *poPROJCS=NULL ) const;
314  OGRErr SetProjParm( const char *, double );
315  double GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
316 
317  OGRErr SetNormProjParm( const char *, double );
318  double GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
319 
320  static int IsAngularParameter( const char * );
321  static int IsLongitudeParameter( const char * );
322  static int IsLinearParameter( const char * );
323 
325  OGRErr SetACEA( double dfStdP1, double dfStdP2,
326  double dfCenterLat, double dfCenterLong,
327  double dfFalseEasting, double dfFalseNorthing );
328 
330  OGRErr SetAE( double dfCenterLat, double dfCenterLong,
331  double dfFalseEasting, double dfFalseNorthing );
332 
334  OGRErr SetBonne( double dfStdP1, double dfCentralMeridian,
335  double dfFalseEasting, double dfFalseNorthing );
336 
338  OGRErr SetCEA( double dfStdP1, double dfCentralMeridian,
339  double dfFalseEasting, double dfFalseNorthing );
340 
342  OGRErr SetCS( double dfCenterLat, double dfCenterLong,
343  double dfFalseEasting, double dfFalseNorthing );
344 
346  OGRErr SetEC( double dfStdP1, double dfStdP2,
347  double dfCenterLat, double dfCenterLong,
348  double dfFalseEasting, double dfFalseNorthing );
349 
351  OGRErr SetEckert( int nVariation, double dfCentralMeridian,
352  double dfFalseEasting, double dfFalseNorthing );
353 
354  OGRErr SetEckertIV( double dfCentralMeridian,
355  double dfFalseEasting, double dfFalseNorthing );
356 
357  OGRErr SetEckertVI( double dfCentralMeridian,
358  double dfFalseEasting, double dfFalseNorthing );
359 
361  OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
362  double dfFalseEasting, double dfFalseNorthing );
364  OGRErr SetEquirectangular2( double dfCenterLat, double dfCenterLong,
365  double dfPseudoStdParallel1,
366  double dfFalseEasting, double dfFalseNorthing );
367 
369  OGRErr SetGEOS( double dfCentralMeridian, double dfSatelliteHeight,
370  double dfFalseEasting, double dfFalseNorthing );
371 
373  OGRErr SetGH( double dfCentralMeridian,
374  double dfFalseEasting, double dfFalseNorthing );
375 
377  OGRErr SetIGH();
378 
380  OGRErr SetGS( double dfCentralMeridian,
381  double dfFalseEasting, double dfFalseNorthing );
382 
384  OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
385  double dfScale,
386  double dfFalseEasting, double dfFalseNorthing );
387 
389  OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
390  double dfFalseEasting, double dfFalseNorthing );
391 
393  OGRErr SetHOM( double dfCenterLat, double dfCenterLong,
394  double dfAzimuth, double dfRectToSkew,
395  double dfScale,
396  double dfFalseEasting, double dfFalseNorthing );
397 
398  OGRErr SetHOM2PNO( double dfCenterLat,
399  double dfLat1, double dfLong1,
400  double dfLat2, double dfLong2,
401  double dfScale,
402  double dfFalseEasting, double dfFalseNorthing );
403 
404  OGRErr SetOM( double dfCenterLat, double dfCenterLong,
405  double dfAzimuth, double dfRectToSkew,
406  double dfScale,
407  double dfFalseEasting, double dfFalseNorthing );
408 
410  OGRErr SetHOMAC( double dfCenterLat, double dfCenterLong,
411  double dfAzimuth, double dfRectToSkew,
412  double dfScale,
413  double dfFalseEasting, double dfFalseNorthing );
414 
416  OGRErr SetIWMPolyconic( double dfLat1, double dfLat2,
417  double dfCenterLong,
418  double dfFalseEasting,
419  double dfFalseNorthing );
420 
422  OGRErr SetKrovak( double dfCenterLat, double dfCenterLong,
423  double dfAzimuth, double dfPseudoStdParallelLat,
424  double dfScale,
425  double dfFalseEasting, double dfFalseNorthing );
426 
428  OGRErr SetLAEA( double dfCenterLat, double dfCenterLong,
429  double dfFalseEasting, double dfFalseNorthing );
430 
432  OGRErr SetLCC( double dfStdP1, double dfStdP2,
433  double dfCenterLat, double dfCenterLong,
434  double dfFalseEasting, double dfFalseNorthing );
435 
437  OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong,
438  double dfScale,
439  double dfFalseEasting, double dfFalseNorthing );
440 
442  OGRErr SetLCCB( double dfStdP1, double dfStdP2,
443  double dfCenterLat, double dfCenterLong,
444  double dfFalseEasting, double dfFalseNorthing );
445 
447  OGRErr SetMC( double dfCenterLat, double dfCenterLong,
448  double dfFalseEasting, double dfFalseNorthing );
449 
451  OGRErr SetMercator( double dfCenterLat, double dfCenterLong,
452  double dfScale,
453  double dfFalseEasting, double dfFalseNorthing );
454 
455  OGRErr SetMercator2SP( double dfStdP1,
456  double dfCenterLat, double dfCenterLong,
457  double dfFalseEasting, double dfFalseNorthing );
458 
460  OGRErr SetMollweide( double dfCentralMeridian,
461  double dfFalseEasting, double dfFalseNorthing );
462 
464  OGRErr SetNZMG( double dfCenterLat, double dfCenterLong,
465  double dfFalseEasting, double dfFalseNorthing );
466 
468  OGRErr SetOS( double dfOriginLat, double dfCMeridian,
469  double dfScale,
470  double dfFalseEasting,double dfFalseNorthing);
471 
473  OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong,
474  double dfFalseEasting,double dfFalseNorthing);
475 
477  OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong,
478  double dfFalseEasting, double dfFalseNorthing );
479 
481  OGRErr SetPS( double dfCenterLat, double dfCenterLong,
482  double dfScale,
483  double dfFalseEasting, double dfFalseNorthing);
484 
486  OGRErr SetRobinson( double dfCenterLong,
487  double dfFalseEasting, double dfFalseNorthing );
488 
490  OGRErr SetSinusoidal( double dfCenterLong,
491  double dfFalseEasting, double dfFalseNorthing );
492 
494  OGRErr SetStereographic( double dfCenterLat, double dfCenterLong,
495  double dfScale,
496  double dfFalseEasting,double dfFalseNorthing);
497 
499  OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
500  double dfFalseEasting, double dfFalseNorthing );
501 
503  OGRErr SetTM( double dfCenterLat, double dfCenterLong,
504  double dfScale,
505  double dfFalseEasting, double dfFalseNorthing );
506 
508  OGRErr SetTMVariant( const char *pszVariantName,
509  double dfCenterLat, double dfCenterLong,
510  double dfScale,
511  double dfFalseEasting, double dfFalseNorthing );
512 
514  OGRErr SetTMG( double dfCenterLat, double dfCenterLong,
515  double dfFalseEasting, double dfFalseNorthing );
516 
518  OGRErr SetTMSO( double dfCenterLat, double dfCenterLong,
519  double dfScale,
520  double dfFalseEasting, double dfFalseNorthing );
521 
523  OGRErr SetTPED( double dfLat1, double dfLong1,
524  double dfLat2, double dfLong2,
525  double dfFalseEasting, double dfFalseNorthing );
526 
528  OGRErr SetVDG( double dfCenterLong,
529  double dfFalseEasting, double dfFalseNorthing );
530 
532  OGRErr SetUTM( int nZone, int bNorth = TRUE );
533  int GetUTMZone( int *pbNorth = NULL ) const;
534 
536  OGRErr SetWagner( int nVariation, double dfCenterLat,
537  double dfFalseEasting, double dfFalseNorthing );
538 
540  OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE,
541  const char *pszOverrideUnitName = NULL,
542  double dfOverrideUnit = 0.0 );
543 
544  OGRErr ImportFromESRIStatePlaneWKT(
545  int nCode, const char* pszDatumName, const char* pszUnitsName,
546  int nPCSCode, const char* pszCSName = 0 );
547  OGRErr ImportFromESRIWisconsinWKT(
548  const char* pszPrjName, double dfCentralMeridian, double dfLatOfOrigin,
549  const char* pszUnitsName, const char* pszCSName = 0 );
550 };
551 
552 /************************************************************************/
553 /* OGRCoordinateTransformation */
554 /* */
555 /* This is really just used as a base class for a private */
556 /* implementation. */
557 /************************************************************************/
558 
569 {
570 public:
571  virtual ~OGRCoordinateTransformation() {}
572 
573  static void DestroyCT(OGRCoordinateTransformation* poCT);
574 
575  // From CT_CoordinateTransformation
576 
578  virtual OGRSpatialReference *GetSourceCS() = 0;
579 
581  virtual OGRSpatialReference *GetTargetCS() = 0;
582 
583  // From CT_MathTransform
584 
600  virtual int Transform( int nCount,
601  double *x, double *y, double *z = NULL ) = 0;
602 
618  virtual int TransformEx( int nCount,
619  double *x, double *y, double *z = NULL,
620  int *pabSuccess = NULL ) = 0;
621 
622 };
623 
626  OGRSpatialReference *poTarget );
627 
628 #endif /* ndef _OGR_SPATIALREF_H_INCLUDED */

Generated for GDAL by doxygen 1.8.4.