OGR
ogr_spatialref.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_spatialref.h 25727 2013-03-10 14:56:33Z 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 
70  public:
71  OGR_SRSNode(const char * = NULL);
72  ~OGR_SRSNode();
73 
74  int IsLeafNode() const { return nChildren == 0; }
75 
76  int GetChildCount() const { return nChildren; }
77  OGR_SRSNode *GetChild( int );
78  const OGR_SRSNode *GetChild( int ) const;
79 
80  OGR_SRSNode *GetNode( const char * );
81  const OGR_SRSNode *GetNode( const char * ) const;
82 
83  void InsertChild( OGR_SRSNode *, int );
84  void AddChild( OGR_SRSNode * );
85  int FindChild( const char * ) const;
86  void DestroyChild( int );
87  void ClearChildren();
88  void StripNodes( const char * );
89 
90  const char *GetValue() const { return pszValue; }
91  void SetValue( const char * );
92 
93  void MakeValueSafe();
94  OGRErr FixupOrdering();
95 
96  OGR_SRSNode *Clone() const;
97 
98  OGRErr importFromWkt( char ** );
99  OGRErr exportToWkt( char ** ) const;
100  OGRErr exportToPrettyWkt( char **, int = 1) const;
101 
102  OGRErr applyRemapper( const char *pszNode,
103  char **papszSrcValues,
104  char **papszDstValues,
105  int nStepSize = 1,
106  int bChildOfHit = FALSE );
107 };
108 
109 /************************************************************************/
110 /* OGRSpatialReference */
111 /************************************************************************/
112 
127 class CPL_DLL OGRSpatialReference
128 {
129  double dfFromGreenwich;
130  double dfToMeter;
131  double dfToDegrees;
132 
133  OGR_SRSNode *poRoot;
134 
135  int nRefCount;
136  int bNormInfoSet;
137 
138  static OGRErr Validate(OGR_SRSNode *poRoot);
139  static OGRErr ValidateAuthority(OGR_SRSNode *poRoot);
140  static OGRErr ValidateAxis(OGR_SRSNode *poRoot);
141  static OGRErr ValidateUnit(OGR_SRSNode *poRoot);
142  static OGRErr ValidateVertDatum(OGR_SRSNode *poRoot);
143  static OGRErr ValidateProjection( OGR_SRSNode* poRoot );
144  static int IsAliasFor( const char *, const char * );
145  void GetNormInfo() const;
146 
147  OGRErr importFromURNPart(const char* pszAuthority,
148  const char* pszCode,
149  const char* pszURN);
150  public:
152  OGRSpatialReference(const char * = NULL);
153 
154  virtual ~OGRSpatialReference();
155 
156  static void DestroySpatialReference(OGRSpatialReference* poSRS);
157 
158  OGRSpatialReference &operator=(const OGRSpatialReference&);
159 
160  int Reference();
161  int Dereference();
162  int GetReferenceCount() const { return nRefCount; }
163  void Release();
164 
165  OGRSpatialReference *Clone() const;
166  OGRSpatialReference *CloneGeogCS() const;
167 
168  void dumpReadable();
169  OGRErr exportToWkt( char ** ) const;
170  OGRErr exportToPrettyWkt( char **, int = FALSE) const;
171  OGRErr exportToProj4( char ** ) const;
172  OGRErr exportToPCI( char **, char **, double ** ) const;
173  OGRErr exportToUSGS( long *, long *, double **, long * ) const;
174  OGRErr exportToXML( char **, const char * = NULL ) const;
175  OGRErr exportToPanorama( long *, long *, long *, long *,
176  double * ) const;
177  OGRErr exportToERM( char *pszProj, char *pszDatum, char *pszUnits );
178  OGRErr exportToMICoordSys( char ** ) const;
179 
180  OGRErr importFromWkt( char ** );
181  OGRErr importFromProj4( const char * );
182  OGRErr importFromEPSG( int );
183  OGRErr importFromEPSGA( int );
184  OGRErr importFromESRI( char ** );
185  OGRErr importFromPCI( const char *, const char * = NULL,
186  double * = NULL );
187 #define USGS_ANGLE_DECIMALDEGREES 0
188 #define USGS_ANGLE_PACKEDDMS TRUE /* 1 */
189 #define USGS_ANGLE_RADIANS 2
190  OGRErr importFromUSGS( long iProjSys, long iZone,
191  double *padfPrjParams, long iDatum,
192  int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS );
193  OGRErr importFromPanorama( long, long, long, double* );
194  OGRErr importFromOzi( const char *, const char *, const char * );
195  OGRErr importFromOzi( const char * const* papszLines );
196  OGRErr importFromWMSAUTO( const char *pszAutoDef );
197  OGRErr importFromXML( const char * );
198  OGRErr importFromDict( const char *pszDict, const char *pszCode );
199  OGRErr importFromURN( const char * );
200  OGRErr importFromCRSURL( const char * );
201  OGRErr importFromERM( const char *pszProj, const char *pszDatum,
202  const char *pszUnits );
203  OGRErr importFromUrl( const char * );
204  OGRErr importFromMICoordSys( const char * );
205 
206  OGRErr morphToESRI();
207  OGRErr morphFromESRI();
208 
209  OGRErr Validate();
210  OGRErr StripCTParms( OGR_SRSNode * = NULL );
211  OGRErr StripVertical();
212  OGRErr FixupOrdering();
213  OGRErr Fixup();
214 
215  int EPSGTreatsAsLatLong();
216  int EPSGTreatsAsNorthingEasting();
217  const char *GetAxis( const char *pszTargetKey, int iAxis,
218  OGRAxisOrientation *peOrientation ) const;
219  OGRErr SetAxes( const char *pszTargetKey,
220  const char *pszXAxisName,
221  OGRAxisOrientation eXAxisOrientation,
222  const char *pszYAxisName,
223  OGRAxisOrientation eYAxisOrientation );
224 
225  // Machinary for accessing parse nodes
226  OGR_SRSNode *GetRoot() { return poRoot; }
227  const OGR_SRSNode *GetRoot() const { return poRoot; }
228  void SetRoot( OGR_SRSNode * );
229 
230  OGR_SRSNode *GetAttrNode(const char *);
231  const OGR_SRSNode *GetAttrNode(const char *) const;
232  const char *GetAttrValue(const char *, int = 0) const;
233 
234  OGRErr SetNode( const char *, const char * );
235  OGRErr SetNode( const char *, double );
236 
237  OGRErr SetLinearUnitsAndUpdateParameters( const char *pszName,
238  double dfInMeters );
239  OGRErr SetLinearUnits( const char *pszName, double dfInMeters );
240  OGRErr SetTargetLinearUnits( const char *pszTargetKey,
241  const char *pszName, double dfInMeters );
242  double GetLinearUnits( char ** = NULL ) const;
243  double GetTargetLinearUnits( const char *pszTargetKey,
244  char ** ppszRetName = NULL ) const;
245 
246  OGRErr SetAngularUnits( const char *pszName, double dfInRadians );
247  double GetAngularUnits( char ** = NULL ) const;
248 
249  double GetPrimeMeridian( char ** = NULL ) const;
250 
251  int IsGeographic() const;
252  int IsProjected() const;
253  int IsGeocentric() const;
254  int IsLocal() const;
255  int IsVertical() const;
256  int IsCompound() const;
257  int IsSameGeogCS( const OGRSpatialReference * ) const;
258  int IsSameVertCS( const OGRSpatialReference * ) const;
259  int IsSame( const OGRSpatialReference * ) const;
260 
261  void Clear();
262  OGRErr SetLocalCS( const char * );
263  OGRErr SetProjCS( const char * );
264  OGRErr SetProjection( const char * );
265  OGRErr SetGeocCS( const char * pszGeocName );
266  OGRErr SetGeogCS( const char * pszGeogName,
267  const char * pszDatumName,
268  const char * pszEllipsoidName,
269  double dfSemiMajor, double dfInvFlattening,
270  const char * pszPMName = NULL,
271  double dfPMOffset = 0.0,
272  const char * pszUnits = NULL,
273  double dfConvertToRadians = 0.0 );
274  OGRErr SetWellKnownGeogCS( const char * );
275  OGRErr CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
276  OGRErr SetVertCS( const char *pszVertCSName,
277  const char *pszVertDatumName,
278  int nVertDatumClass = 2005 );
279  OGRErr SetCompoundCS( const char *pszName,
280  const OGRSpatialReference *poHorizSRS,
281  const OGRSpatialReference *poVertSRS );
282 
283  OGRErr SetFromUserInput( const char * );
284 
285  OGRErr SetTOWGS84( double, double, double,
286  double = 0.0, double = 0.0, double = 0.0,
287  double = 0.0 );
288  OGRErr GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
289 
290  double GetSemiMajor( OGRErr * = NULL ) const;
291  double GetSemiMinor( OGRErr * = NULL ) const;
292  double GetInvFlattening( OGRErr * = NULL ) const;
293 
294  OGRErr SetAuthority( const char * pszTargetKey,
295  const char * pszAuthority,
296  int nCode );
297 
298  OGRErr AutoIdentifyEPSG();
299  int GetEPSGGeogCS();
300 
301  const char *GetAuthorityCode( const char * pszTargetKey ) const;
302  const char *GetAuthorityName( const char * pszTargetKey ) const;
303 
304  const char *GetExtension( const char *pszTargetKey,
305  const char *pszName,
306  const char *pszDefault = NULL ) const;
307  OGRErr SetExtension( const char *pszTargetKey,
308  const char *pszName,
309  const char *pszValue );
310 
311  int FindProjParm( const char *pszParameter,
312  const OGR_SRSNode *poPROJCS=NULL ) const;
313  OGRErr SetProjParm( const char *, double );
314  double GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
315 
316  OGRErr SetNormProjParm( const char *, double );
317  double GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
318 
319  static int IsAngularParameter( const char * );
320  static int IsLongitudeParameter( const char * );
321  static int IsLinearParameter( const char * );
322 
324  OGRErr SetACEA( double dfStdP1, double dfStdP2,
325  double dfCenterLat, double dfCenterLong,
326  double dfFalseEasting, double dfFalseNorthing );
327 
329  OGRErr SetAE( double dfCenterLat, double dfCenterLong,
330  double dfFalseEasting, double dfFalseNorthing );
331 
333  OGRErr SetBonne( double dfStdP1, double dfCentralMeridian,
334  double dfFalseEasting, double dfFalseNorthing );
335 
337  OGRErr SetCEA( double dfStdP1, double dfCentralMeridian,
338  double dfFalseEasting, double dfFalseNorthing );
339 
341  OGRErr SetCS( double dfCenterLat, double dfCenterLong,
342  double dfFalseEasting, double dfFalseNorthing );
343 
345  OGRErr SetEC( double dfStdP1, double dfStdP2,
346  double dfCenterLat, double dfCenterLong,
347  double dfFalseEasting, double dfFalseNorthing );
348 
350  OGRErr SetEckert( int nVariation, double dfCentralMeridian,
351  double dfFalseEasting, double dfFalseNorthing );
352 
353  OGRErr SetEckertIV( double dfCentralMeridian,
354  double dfFalseEasting, double dfFalseNorthing );
355 
356  OGRErr SetEckertVI( double dfCentralMeridian,
357  double dfFalseEasting, double dfFalseNorthing );
358 
360  OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
361  double dfFalseEasting, double dfFalseNorthing );
363  OGRErr SetEquirectangular2( double dfCenterLat, double dfCenterLong,
364  double dfPseudoStdParallel1,
365  double dfFalseEasting, double dfFalseNorthing );
366 
368  OGRErr SetGEOS( double dfCentralMeridian, double dfSatelliteHeight,
369  double dfFalseEasting, double dfFalseNorthing );
370 
372  OGRErr SetGH( double dfCentralMeridian,
373  double dfFalseEasting, double dfFalseNorthing );
374 
376  OGRErr SetIGH();
377 
379  OGRErr SetGS( double dfCentralMeridian,
380  double dfFalseEasting, double dfFalseNorthing );
381 
383  OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
384  double dfScale,
385  double dfFalseEasting, double dfFalseNorthing );
386 
388  OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
389  double dfFalseEasting, double dfFalseNorthing );
390 
392  OGRErr SetHOM( double dfCenterLat, double dfCenterLong,
393  double dfAzimuth, double dfRectToSkew,
394  double dfScale,
395  double dfFalseEasting, double dfFalseNorthing );
396 
397  OGRErr SetHOM2PNO( double dfCenterLat,
398  double dfLat1, double dfLong1,
399  double dfLat2, double dfLong2,
400  double dfScale,
401  double dfFalseEasting, double dfFalseNorthing );
402 
403  OGRErr SetOM( double dfCenterLat, double dfCenterLong,
404  double dfAzimuth, double dfRectToSkew,
405  double dfScale,
406  double dfFalseEasting, double dfFalseNorthing );
407 
409  OGRErr SetHOMAC( double dfCenterLat, double dfCenterLong,
410  double dfAzimuth, double dfRectToSkew,
411  double dfScale,
412  double dfFalseEasting, double dfFalseNorthing );
413 
415  OGRErr SetIWMPolyconic( double dfLat1, double dfLat2,
416  double dfCenterLong,
417  double dfFalseEasting,
418  double dfFalseNorthing );
419 
421  OGRErr SetKrovak( double dfCenterLat, double dfCenterLong,
422  double dfAzimuth, double dfPseudoStdParallelLat,
423  double dfScale,
424  double dfFalseEasting, double dfFalseNorthing );
425 
427  OGRErr SetLAEA( double dfCenterLat, double dfCenterLong,
428  double dfFalseEasting, double dfFalseNorthing );
429 
431  OGRErr SetLCC( double dfStdP1, double dfStdP2,
432  double dfCenterLat, double dfCenterLong,
433  double dfFalseEasting, double dfFalseNorthing );
434 
436  OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong,
437  double dfScale,
438  double dfFalseEasting, double dfFalseNorthing );
439 
441  OGRErr SetLCCB( double dfStdP1, double dfStdP2,
442  double dfCenterLat, double dfCenterLong,
443  double dfFalseEasting, double dfFalseNorthing );
444 
446  OGRErr SetMC( double dfCenterLat, double dfCenterLong,
447  double dfFalseEasting, double dfFalseNorthing );
448 
450  OGRErr SetMercator( double dfCenterLat, double dfCenterLong,
451  double dfScale,
452  double dfFalseEasting, double dfFalseNorthing );
453 
454  OGRErr SetMercator2SP( double dfStdP1,
455  double dfCenterLat, double dfCenterLong,
456  double dfFalseEasting, double dfFalseNorthing );
457 
459  OGRErr SetMollweide( double dfCentralMeridian,
460  double dfFalseEasting, double dfFalseNorthing );
461 
463  OGRErr SetNZMG( double dfCenterLat, double dfCenterLong,
464  double dfFalseEasting, double dfFalseNorthing );
465 
467  OGRErr SetOS( double dfOriginLat, double dfCMeridian,
468  double dfScale,
469  double dfFalseEasting,double dfFalseNorthing);
470 
472  OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong,
473  double dfFalseEasting,double dfFalseNorthing);
474 
476  OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong,
477  double dfFalseEasting, double dfFalseNorthing );
478 
480  OGRErr SetPS( double dfCenterLat, double dfCenterLong,
481  double dfScale,
482  double dfFalseEasting, double dfFalseNorthing);
483 
485  OGRErr SetRobinson( double dfCenterLong,
486  double dfFalseEasting, double dfFalseNorthing );
487 
489  OGRErr SetSinusoidal( double dfCenterLong,
490  double dfFalseEasting, double dfFalseNorthing );
491 
493  OGRErr SetStereographic( double dfCenterLat, double dfCenterLong,
494  double dfScale,
495  double dfFalseEasting,double dfFalseNorthing);
496 
498  OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
499  double dfFalseEasting, double dfFalseNorthing );
500 
502  OGRErr SetTM( double dfCenterLat, double dfCenterLong,
503  double dfScale,
504  double dfFalseEasting, double dfFalseNorthing );
505 
507  OGRErr SetTMVariant( const char *pszVariantName,
508  double dfCenterLat, double dfCenterLong,
509  double dfScale,
510  double dfFalseEasting, double dfFalseNorthing );
511 
513  OGRErr SetTMG( double dfCenterLat, double dfCenterLong,
514  double dfFalseEasting, double dfFalseNorthing );
515 
517  OGRErr SetTMSO( double dfCenterLat, double dfCenterLong,
518  double dfScale,
519  double dfFalseEasting, double dfFalseNorthing );
520 
522  OGRErr SetTPED( double dfLat1, double dfLong1,
523  double dfLat2, double dfLong2,
524  double dfFalseEasting, double dfFalseNorthing );
525 
527  OGRErr SetVDG( double dfCenterLong,
528  double dfFalseEasting, double dfFalseNorthing );
529 
531  OGRErr SetUTM( int nZone, int bNorth = TRUE );
532  int GetUTMZone( int *pbNorth = NULL ) const;
533 
535  OGRErr SetWagner( int nVariation, double dfCenterLat,
536  double dfFalseEasting, double dfFalseNorthing );
537 
539  OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE,
540  const char *pszOverrideUnitName = NULL,
541  double dfOverrideUnit = 0.0 );
542 
543  OGRErr ImportFromESRIStatePlaneWKT(
544  int nCode, const char* pszDatumName, const char* pszUnitsName,
545  int nPCSCode, const char* pszCSName = 0 );
546  OGRErr ImportFromESRIWisconsinWKT(
547  const char* pszPrjName, double dfCentralMeridian, double dfLatOfOrigin,
548  const char* pszUnitsName, const char* pszCSName = 0 );
549 };
550 
551 /************************************************************************/
552 /* OGRCoordinateTransformation */
553 /* */
554 /* This is really just used as a base class for a private */
555 /* implementation. */
556 /************************************************************************/
557 
568 {
569 public:
570  virtual ~OGRCoordinateTransformation() {}
571 
572  static void DestroyCT(OGRCoordinateTransformation* poCT);
573 
574  // From CT_CoordinateTransformation
575 
577  virtual OGRSpatialReference *GetSourceCS() = 0;
578 
580  virtual OGRSpatialReference *GetTargetCS() = 0;
581 
582  // From CT_MathTransform
583 
599  virtual int Transform( int nCount,
600  double *x, double *y, double *z = NULL ) = 0;
601 
617  virtual int TransformEx( int nCount,
618  double *x, double *y, double *z = NULL,
619  int *pabSuccess = NULL ) = 0;
620 
621 };
622 
625  OGRSpatialReference *poTarget );
626 
627 #endif /* ndef _OGR_SPATIALREF_H_INCLUDED */

Generated for GDAL by doxygen 1.8.3.1.