GDAL

- Main Page
- Related Pages
- Classes
- Files
- Download
- Issue Tracker

- File List
- File Members

ogr_spatialref.h
Go to the documentation of this file.
1 /******************************************************************************
2 * $Id: ogr_spatialref.h 36411 2016-11-21 22:03:48Z 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:
156 OGRSpatialReference(const OGRSpatialReference&);
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
415 OGRErr SetOM( double dfCenterLat, double dfCenterLong,
416 double dfAzimuth, double dfRectToSkew,
417 double dfScale,
418 double dfFalseEasting, double dfFalseNorthing );
419
421 OGRErr SetHOMAC( double dfCenterLat, double dfCenterLong,
422 double dfAzimuth, double dfRectToSkew,
423 double dfScale,
424 double dfFalseEasting, double dfFalseNorthing );
425
427 OGRErr SetIWMPolyconic( double dfLat1, double dfLat2,
428 double dfCenterLong,
429 double dfFalseEasting,
430 double dfFalseNorthing );
431
433 OGRErr SetKrovak( double dfCenterLat, double dfCenterLong,
434 double dfAzimuth, double dfPseudoStdParallelLat,
435 double dfScale,
436 double dfFalseEasting, double dfFalseNorthing );
437
439 OGRErr SetLAEA( double dfCenterLat, double dfCenterLong,
440 double dfFalseEasting, double dfFalseNorthing );
441
443 OGRErr SetLCC( double dfStdP1, double dfStdP2,
444 double dfCenterLat, double dfCenterLong,
445 double dfFalseEasting, double dfFalseNorthing );
446
448 OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong,
449 double dfScale,
450 double dfFalseEasting, double dfFalseNorthing );
451
453 OGRErr SetLCCB( double dfStdP1, double dfStdP2,
454 double dfCenterLat, double dfCenterLong,
455 double dfFalseEasting, double dfFalseNorthing );
456
458 OGRErr SetMC( double dfCenterLat, double dfCenterLong,
459 double dfFalseEasting, double dfFalseNorthing );
460
462 OGRErr SetMercator( double dfCenterLat, double dfCenterLong,
463 double dfScale,
464 double dfFalseEasting, double dfFalseNorthing );
465
467 OGRErr SetMercator2SP( double dfStdP1,
468 double dfCenterLat, double dfCenterLong,
469 double dfFalseEasting, double dfFalseNorthing );
470
472 OGRErr SetMollweide( double dfCentralMeridian,
473 double dfFalseEasting, double dfFalseNorthing );
474
476 OGRErr SetNZMG( double dfCenterLat, double dfCenterLong,
477 double dfFalseEasting, double dfFalseNorthing );
478
480 OGRErr SetOS( double dfOriginLat, double dfCMeridian,
481 double dfScale,
482 double dfFalseEasting,double dfFalseNorthing);
483
485 OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong,
486 double dfFalseEasting,double dfFalseNorthing);
487
489 OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong,
490 double dfFalseEasting, double dfFalseNorthing );
491
493 OGRErr SetPS( double dfCenterLat, double dfCenterLong,
494 double dfScale,
495 double dfFalseEasting, double dfFalseNorthing);
496
498 OGRErr SetRobinson( double dfCenterLong,
499 double dfFalseEasting, double dfFalseNorthing );
500
502 OGRErr SetSinusoidal( double dfCenterLong,
503 double dfFalseEasting, double dfFalseNorthing );
504
506 OGRErr SetStereographic( double dfCenterLat, double dfCenterLong,
507 double dfScale,
508 double dfFalseEasting,double dfFalseNorthing);
509
511 OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
512 double dfFalseEasting, double dfFalseNorthing );
513
515 OGRErr SetTM( double dfCenterLat, double dfCenterLong,
516 double dfScale,
517 double dfFalseEasting, double dfFalseNorthing );
518
520 OGRErr SetTMVariant( const char *pszVariantName,
521 double dfCenterLat, double dfCenterLong,
522 double dfScale,
523 double dfFalseEasting, double dfFalseNorthing );
524
526 OGRErr SetTMG( double dfCenterLat, double dfCenterLong,
527 double dfFalseEasting, double dfFalseNorthing );
528
530 OGRErr SetTMSO( double dfCenterLat, double dfCenterLong,
531 double dfScale,
532 double dfFalseEasting, double dfFalseNorthing );
533
535 OGRErr SetTPED( double dfLat1, double dfLong1,
536 double dfLat2, double dfLong2,
537 double dfFalseEasting, double dfFalseNorthing );
538
540 OGRErr SetVDG( double dfCenterLong,
541 double dfFalseEasting, double dfFalseNorthing );
542
544 OGRErr SetUTM( int nZone, int bNorth = TRUE );
545 int GetUTMZone( int *pbNorth = NULL ) const;
546
548 OGRErr SetWagner( int nVariation, double dfCenterLat,
549 double dfFalseEasting, double dfFalseNorthing );
550
552 OGRErr SetQSC(double dfCenterLat, double dfCenterLong);
553
555 OGRErr SetSCH( double dfPegLat, double dfPegLong,
556 double dfPegHeading, double dfPegHgt);
558 OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE,
559 const char *pszOverrideUnitName = NULL,
560 double dfOverrideUnit = 0.0 );
561
563 OGRErr ImportFromESRIStatePlaneWKT(
564 int nCode, const char* pszDatumName, const char* pszUnitsName,
565 int nPCSCode, const char* pszCSName = NULL );
566
568 OGRErr ImportFromESRIWisconsinWKT(
569 const char* pszPrjName, double dfCentralMeridian, double dfLatOfOrigin,
570 const char* pszUnitsName, const char* pszCSName = NULL );
571
572 static OGRSpatialReference* GetWGS84SRS();
573 };
574
575 /************************************************************************/
576 /* OGRCoordinateTransformation */
577 /* */
578 /* This is really just used as a base class for a private */
579 /* implementation. */
580 /************************************************************************/
581
591 class CPL_DLL OGRCoordinateTransformation
592 {
593 public:
594 virtual ~OGRCoordinateTransformation() {}
595
596 static void DestroyCT(OGRCoordinateTransformation* poCT);
597
598 // From CT_CoordinateTransformation
599
601 virtual OGRSpatialReference *GetSourceCS() = 0;
602
604 virtual OGRSpatialReference *GetTargetCS() = 0;
605
607 virtual bool GetEmitErrors() { return false; }
608
610 virtual void SetEmitErrors(bool /*bEmitErrors*/) {}
611
612 // From CT_MathTransform
613
629 virtual int Transform( int nCount,
630 double *x, double *y, double *z = NULL ) = 0;
631
647 virtual int TransformEx( int nCount,
648 double *x, double *y, double *z = NULL,
649 int *pabSuccess = NULL ) = 0;
650 };
651
652 OGRCoordinateTransformation CPL_DLL *
653 OGRCreateCoordinateTransformation( OGRSpatialReference *poSource,
654 OGRSpatialReference *poTarget );
655
656 #endif /* ndef OGR_SPATIALREF_H_INCLUDED */
OGRCoordinateTransformation::SetEmitErrors
virtual void SetEmitErrors(bool)
Set if the transformer must emit CPLError.
Definition: ogr_spatialref.h:610
OGRCreateCoordinateTransformation
OGRCoordinateTransformation * OGRCreateCoordinateTransformation(OGRSpatialReference *poSource, OGRSpatialReference *poTarget)
Create transformation object.
Definition: ogrct.cpp:433
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:60
OGR_SRSNode::IsLeafNode
int IsLeafNode() const
Return whether this is a leaf node.
Definition: ogr_spatialref.h:79
OGR_SRSNode::GetValue
const char * GetValue() const
Fetch value string for this node.
Definition: ogr_spatialref.h:95
USGS_ANGLE_PACKEDDMS
#define USGS_ANGLE_PACKEDDMS
Angle is in packed degree minute second.
Definition: ogr_spatialref.h:194
OGRSpatialReference::GetRoot
OGR_SRSNode * GetRoot()
Return root node.
Definition: ogr_spatialref.h:233
ogr_srs_api.h
C spatial reference system services and defines.
OGRAxisOrientation
OGRAxisOrientation
Axis orientations (corresponds to CS_AxisOrientationEnum).
Definition: ogr_srs_api.h:48
OGRCoordinateTransformation::GetEmitErrors
virtual bool GetEmitErrors()
Whether the transformer will emit CPLError.
Definition: ogr_spatialref.h:607
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:132
OGRSpatialReference::GetReferenceCount
int GetReferenceCount() const
Fetch current reference count.
Definition: ogr_spatialref.h:167
OGRCoordinateTransformation
Interface for transforming between coordinate systems.
Definition: ogr_spatialref.h:591
OGRSpatialReference::GetRoot
const OGR_SRSNode * GetRoot() const
Return root node.
Definition: ogr_spatialref.h:235
OGRErr
int OGRErr
Simple container for a bounding region.
Definition: ogr_core.h:285
OGR_SRSNode::GetChildCount
int GetChildCount() const
Get number of children nodes.
Definition: ogr_spatialref.h:81

Generated for GDAL by 1.8.9.1.