00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _OGR_SPATIALREF_H_INCLUDED
00032 #define _OGR_SPATIALREF_H_INCLUDED
00033
00034 #include "ogr_srs_api.h"
00035
00042
00043
00044
00045
00059 class CPL_DLL OGR_SRSNode
00060 {
00061 char *pszValue;
00062
00063 OGR_SRSNode **papoChildNodes;
00064 OGR_SRSNode *poParent;
00065
00066 int nChildren;
00067
00068 int NeedsQuoting() const;
00069
00070 public:
00071 OGR_SRSNode(const char * = NULL);
00072 ~OGR_SRSNode();
00073
00074 int IsLeafNode() const { return nChildren == 0; }
00075
00076 int GetChildCount() const { return nChildren; }
00077 OGR_SRSNode *GetChild( int );
00078 const OGR_SRSNode *GetChild( int ) const;
00079
00080 OGR_SRSNode *GetNode( const char * );
00081 const OGR_SRSNode *GetNode( const char * ) const;
00082
00083 void InsertChild( OGR_SRSNode *, int );
00084 void AddChild( OGR_SRSNode * );
00085 int FindChild( const char * ) const;
00086 void DestroyChild( int );
00087 void ClearChildren();
00088 void StripNodes( const char * );
00089
00090 const char *GetValue() const { return pszValue; }
00091 void SetValue( const char * );
00092
00093 void MakeValueSafe();
00094 OGRErr FixupOrdering();
00095
00096 OGR_SRSNode *Clone() const;
00097
00098 OGRErr importFromWkt( char ** );
00099 OGRErr exportToWkt( char ** ) const;
00100 OGRErr exportToPrettyWkt( char **, int = 1) const;
00101
00102 OGRErr applyRemapper( const char *pszNode,
00103 char **papszSrcValues,
00104 char **papszDstValues,
00105 int nStepSize = 1,
00106 int bChildOfHit = FALSE );
00107 };
00108
00109
00110
00111
00112
00127 class CPL_DLL OGRSpatialReference
00128 {
00129 double dfFromGreenwich;
00130 double dfToMeter;
00131 double dfToDegrees;
00132
00133 OGR_SRSNode *poRoot;
00134
00135 int nRefCount;
00136 int bNormInfoSet;
00137
00138 static OGRErr Validate(OGR_SRSNode *poRoot);
00139 static OGRErr ValidateAuthority(OGR_SRSNode *poRoot);
00140 static OGRErr ValidateAxis(OGR_SRSNode *poRoot);
00141 static OGRErr ValidateUnit(OGR_SRSNode *poRoot);
00142 static OGRErr ValidateVertDatum(OGR_SRSNode *poRoot);
00143 static OGRErr ValidateProjection( OGR_SRSNode* poRoot );
00144 static int IsAliasFor( const char *, const char * );
00145 void GetNormInfo() const;
00146
00147 OGRErr importFromURNPart(const char* pszAuthority,
00148 const char* pszCode,
00149 const char* pszURN);
00150 public:
00151 OGRSpatialReference(const OGRSpatialReference&);
00152 OGRSpatialReference(const char * = NULL);
00153
00154 virtual ~OGRSpatialReference();
00155
00156 static void DestroySpatialReference(OGRSpatialReference* poSRS);
00157
00158 OGRSpatialReference &operator=(const OGRSpatialReference&);
00159
00160 int Reference();
00161 int Dereference();
00162 int GetReferenceCount() const { return nRefCount; }
00163 void Release();
00164
00165 OGRSpatialReference *Clone() const;
00166 OGRSpatialReference *CloneGeogCS() const;
00167
00168 void dumpReadable();
00169 OGRErr exportToWkt( char ** ) const;
00170 OGRErr exportToPrettyWkt( char **, int = FALSE) const;
00171 OGRErr exportToProj4( char ** ) const;
00172 OGRErr exportToPCI( char **, char **, double ** ) const;
00173 OGRErr exportToUSGS( long *, long *, double **, long * ) const;
00174 OGRErr exportToXML( char **, const char * = NULL ) const;
00175 OGRErr exportToPanorama( long *, long *, long *, long *,
00176 double * ) const;
00177 OGRErr exportToERM( char *pszProj, char *pszDatum, char *pszUnits );
00178 OGRErr exportToMICoordSys( char ** ) const;
00179
00180 OGRErr importFromWkt( char ** );
00181 OGRErr importFromProj4( const char * );
00182 OGRErr importFromEPSG( int );
00183 OGRErr importFromEPSGA( int );
00184 OGRErr importFromESRI( char ** );
00185 OGRErr importFromPCI( const char *, const char * = NULL,
00186 double * = NULL );
00187 #define USGS_ANGLE_DECIMALDEGREES 0
00188 #define USGS_ANGLE_PACKEDDMS TRUE
00189 #define USGS_ANGLE_RADIANS 2
00190 OGRErr importFromUSGS( long iProjSys, long iZone,
00191 double *padfPrjParams, long iDatum,
00192 int nUSGSAngleFormat = USGS_ANGLE_PACKEDDMS );
00193 OGRErr importFromPanorama( long, long, long, double* );
00194 OGRErr importFromOzi( const char *, const char *, const char * );
00195 OGRErr importFromOzi( const char * const* papszLines );
00196 OGRErr importFromWMSAUTO( const char *pszAutoDef );
00197 OGRErr importFromXML( const char * );
00198 OGRErr importFromDict( const char *pszDict, const char *pszCode );
00199 OGRErr importFromURN( const char * );
00200 OGRErr importFromCRSURL( const char * );
00201 OGRErr importFromERM( const char *pszProj, const char *pszDatum,
00202 const char *pszUnits );
00203 OGRErr importFromUrl( const char * );
00204 OGRErr importFromMICoordSys( const char * );
00205
00206 OGRErr morphToESRI();
00207 OGRErr morphFromESRI();
00208
00209 OGRErr Validate();
00210 OGRErr StripCTParms( OGR_SRSNode * = NULL );
00211 OGRErr StripVertical();
00212 OGRErr FixupOrdering();
00213 OGRErr Fixup();
00214
00215 int EPSGTreatsAsLatLong();
00216 int EPSGTreatsAsNorthingEasting();
00217 const char *GetAxis( const char *pszTargetKey, int iAxis,
00218 OGRAxisOrientation *peOrientation ) const;
00219 OGRErr SetAxes( const char *pszTargetKey,
00220 const char *pszXAxisName,
00221 OGRAxisOrientation eXAxisOrientation,
00222 const char *pszYAxisName,
00223 OGRAxisOrientation eYAxisOrientation );
00224
00225
00226 OGR_SRSNode *GetRoot() { return poRoot; }
00227 const OGR_SRSNode *GetRoot() const { return poRoot; }
00228 void SetRoot( OGR_SRSNode * );
00229
00230 OGR_SRSNode *GetAttrNode(const char *);
00231 const OGR_SRSNode *GetAttrNode(const char *) const;
00232 const char *GetAttrValue(const char *, int = 0) const;
00233
00234 OGRErr SetNode( const char *, const char * );
00235 OGRErr SetNode( const char *, double );
00236
00237 OGRErr SetLinearUnitsAndUpdateParameters( const char *pszName,
00238 double dfInMeters );
00239 OGRErr SetLinearUnits( const char *pszName, double dfInMeters );
00240 OGRErr SetTargetLinearUnits( const char *pszTargetKey,
00241 const char *pszName, double dfInMeters );
00242 double GetLinearUnits( char ** = NULL ) const;
00243 double GetTargetLinearUnits( const char *pszTargetKey,
00244 char ** ppszRetName = NULL ) const;
00245
00246 OGRErr SetAngularUnits( const char *pszName, double dfInRadians );
00247 double GetAngularUnits( char ** = NULL ) const;
00248
00249 double GetPrimeMeridian( char ** = NULL ) const;
00250
00251 int IsGeographic() const;
00252 int IsProjected() const;
00253 int IsGeocentric() const;
00254 int IsLocal() const;
00255 int IsVertical() const;
00256 int IsCompound() const;
00257 int IsSameGeogCS( const OGRSpatialReference * ) const;
00258 int IsSameVertCS( const OGRSpatialReference * ) const;
00259 int IsSame( const OGRSpatialReference * ) const;
00260
00261 void Clear();
00262 OGRErr SetLocalCS( const char * );
00263 OGRErr SetProjCS( const char * );
00264 OGRErr SetProjection( const char * );
00265 OGRErr SetGeocCS( const char * pszGeocName );
00266 OGRErr SetGeogCS( const char * pszGeogName,
00267 const char * pszDatumName,
00268 const char * pszEllipsoidName,
00269 double dfSemiMajor, double dfInvFlattening,
00270 const char * pszPMName = NULL,
00271 double dfPMOffset = 0.0,
00272 const char * pszUnits = NULL,
00273 double dfConvertToRadians = 0.0 );
00274 OGRErr SetWellKnownGeogCS( const char * );
00275 OGRErr CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
00276 OGRErr SetVertCS( const char *pszVertCSName,
00277 const char *pszVertDatumName,
00278 int nVertDatumClass = 2005 );
00279 OGRErr SetCompoundCS( const char *pszName,
00280 const OGRSpatialReference *poHorizSRS,
00281 const OGRSpatialReference *poVertSRS );
00282
00283 OGRErr SetFromUserInput( const char * );
00284
00285 OGRErr SetTOWGS84( double, double, double,
00286 double = 0.0, double = 0.0, double = 0.0,
00287 double = 0.0 );
00288 OGRErr GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
00289
00290 double GetSemiMajor( OGRErr * = NULL ) const;
00291 double GetSemiMinor( OGRErr * = NULL ) const;
00292 double GetInvFlattening( OGRErr * = NULL ) const;
00293
00294 OGRErr SetAuthority( const char * pszTargetKey,
00295 const char * pszAuthority,
00296 int nCode );
00297
00298 OGRErr AutoIdentifyEPSG();
00299 int GetEPSGGeogCS();
00300
00301 const char *GetAuthorityCode( const char * pszTargetKey ) const;
00302 const char *GetAuthorityName( const char * pszTargetKey ) const;
00303
00304 const char *GetExtension( const char *pszTargetKey,
00305 const char *pszName,
00306 const char *pszDefault = NULL ) const;
00307 OGRErr SetExtension( const char *pszTargetKey,
00308 const char *pszName,
00309 const char *pszValue );
00310
00311 int FindProjParm( const char *pszParameter,
00312 const OGR_SRSNode *poPROJCS=NULL ) const;
00313 OGRErr SetProjParm( const char *, double );
00314 double GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
00315
00316 OGRErr SetNormProjParm( const char *, double );
00317 double GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
00318
00319 static int IsAngularParameter( const char * );
00320 static int IsLongitudeParameter( const char * );
00321 static int IsLinearParameter( const char * );
00322
00324 OGRErr SetACEA( double dfStdP1, double dfStdP2,
00325 double dfCenterLat, double dfCenterLong,
00326 double dfFalseEasting, double dfFalseNorthing );
00327
00329 OGRErr SetAE( double dfCenterLat, double dfCenterLong,
00330 double dfFalseEasting, double dfFalseNorthing );
00331
00333 OGRErr SetBonne( double dfStdP1, double dfCentralMeridian,
00334 double dfFalseEasting, double dfFalseNorthing );
00335
00337 OGRErr SetCEA( double dfStdP1, double dfCentralMeridian,
00338 double dfFalseEasting, double dfFalseNorthing );
00339
00341 OGRErr SetCS( double dfCenterLat, double dfCenterLong,
00342 double dfFalseEasting, double dfFalseNorthing );
00343
00345 OGRErr SetEC( double dfStdP1, double dfStdP2,
00346 double dfCenterLat, double dfCenterLong,
00347 double dfFalseEasting, double dfFalseNorthing );
00348
00350 OGRErr SetEckert( int nVariation, double dfCentralMeridian,
00351 double dfFalseEasting, double dfFalseNorthing );
00352
00353 OGRErr SetEckertIV( double dfCentralMeridian,
00354 double dfFalseEasting, double dfFalseNorthing );
00355
00356 OGRErr SetEckertVI( double dfCentralMeridian,
00357 double dfFalseEasting, double dfFalseNorthing );
00358
00360 OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong,
00361 double dfFalseEasting, double dfFalseNorthing );
00363 OGRErr SetEquirectangular2( double dfCenterLat, double dfCenterLong,
00364 double dfPseudoStdParallel1,
00365 double dfFalseEasting, double dfFalseNorthing );
00366
00368 OGRErr SetGEOS( double dfCentralMeridian, double dfSatelliteHeight,
00369 double dfFalseEasting, double dfFalseNorthing );
00370
00372 OGRErr SetGH( double dfCentralMeridian,
00373 double dfFalseEasting, double dfFalseNorthing );
00374
00376 OGRErr SetIGH();
00377
00379 OGRErr SetGS( double dfCentralMeridian,
00380 double dfFalseEasting, double dfFalseNorthing );
00381
00383 OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
00384 double dfScale,
00385 double dfFalseEasting, double dfFalseNorthing );
00386
00388 OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong,
00389 double dfFalseEasting, double dfFalseNorthing );
00390
00392 OGRErr SetHOM( double dfCenterLat, double dfCenterLong,
00393 double dfAzimuth, double dfRectToSkew,
00394 double dfScale,
00395 double dfFalseEasting, double dfFalseNorthing );
00396
00397 OGRErr SetHOM2PNO( double dfCenterLat,
00398 double dfLat1, double dfLong1,
00399 double dfLat2, double dfLong2,
00400 double dfScale,
00401 double dfFalseEasting, double dfFalseNorthing );
00402
00403 OGRErr SetOM( double dfCenterLat, double dfCenterLong,
00404 double dfAzimuth, double dfRectToSkew,
00405 double dfScale,
00406 double dfFalseEasting, double dfFalseNorthing );
00407
00409 OGRErr SetHOMAC( double dfCenterLat, double dfCenterLong,
00410 double dfAzimuth, double dfRectToSkew,
00411 double dfScale,
00412 double dfFalseEasting, double dfFalseNorthing );
00413
00415 OGRErr SetIWMPolyconic( double dfLat1, double dfLat2,
00416 double dfCenterLong,
00417 double dfFalseEasting,
00418 double dfFalseNorthing );
00419
00421 OGRErr SetKrovak( double dfCenterLat, double dfCenterLong,
00422 double dfAzimuth, double dfPseudoStdParallelLat,
00423 double dfScale,
00424 double dfFalseEasting, double dfFalseNorthing );
00425
00427 OGRErr SetLAEA( double dfCenterLat, double dfCenterLong,
00428 double dfFalseEasting, double dfFalseNorthing );
00429
00431 OGRErr SetLCC( double dfStdP1, double dfStdP2,
00432 double dfCenterLat, double dfCenterLong,
00433 double dfFalseEasting, double dfFalseNorthing );
00434
00436 OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong,
00437 double dfScale,
00438 double dfFalseEasting, double dfFalseNorthing );
00439
00441 OGRErr SetLCCB( double dfStdP1, double dfStdP2,
00442 double dfCenterLat, double dfCenterLong,
00443 double dfFalseEasting, double dfFalseNorthing );
00444
00446 OGRErr SetMC( double dfCenterLat, double dfCenterLong,
00447 double dfFalseEasting, double dfFalseNorthing );
00448
00450 OGRErr SetMercator( double dfCenterLat, double dfCenterLong,
00451 double dfScale,
00452 double dfFalseEasting, double dfFalseNorthing );
00453
00454 OGRErr SetMercator2SP( double dfStdP1,
00455 double dfCenterLat, double dfCenterLong,
00456 double dfFalseEasting, double dfFalseNorthing );
00457
00459 OGRErr SetMollweide( double dfCentralMeridian,
00460 double dfFalseEasting, double dfFalseNorthing );
00461
00463 OGRErr SetNZMG( double dfCenterLat, double dfCenterLong,
00464 double dfFalseEasting, double dfFalseNorthing );
00465
00467 OGRErr SetOS( double dfOriginLat, double dfCMeridian,
00468 double dfScale,
00469 double dfFalseEasting,double dfFalseNorthing);
00470
00472 OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong,
00473 double dfFalseEasting,double dfFalseNorthing);
00474
00476 OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong,
00477 double dfFalseEasting, double dfFalseNorthing );
00478
00480 OGRErr SetPS( double dfCenterLat, double dfCenterLong,
00481 double dfScale,
00482 double dfFalseEasting, double dfFalseNorthing);
00483
00485 OGRErr SetRobinson( double dfCenterLong,
00486 double dfFalseEasting, double dfFalseNorthing );
00487
00489 OGRErr SetSinusoidal( double dfCenterLong,
00490 double dfFalseEasting, double dfFalseNorthing );
00491
00493 OGRErr SetStereographic( double dfCenterLat, double dfCenterLong,
00494 double dfScale,
00495 double dfFalseEasting,double dfFalseNorthing);
00496
00498 OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
00499 double dfFalseEasting, double dfFalseNorthing );
00500
00502 OGRErr SetTM( double dfCenterLat, double dfCenterLong,
00503 double dfScale,
00504 double dfFalseEasting, double dfFalseNorthing );
00505
00507 OGRErr SetTMVariant( const char *pszVariantName,
00508 double dfCenterLat, double dfCenterLong,
00509 double dfScale,
00510 double dfFalseEasting, double dfFalseNorthing );
00511
00513 OGRErr SetTMG( double dfCenterLat, double dfCenterLong,
00514 double dfFalseEasting, double dfFalseNorthing );
00515
00517 OGRErr SetTMSO( double dfCenterLat, double dfCenterLong,
00518 double dfScale,
00519 double dfFalseEasting, double dfFalseNorthing );
00520
00522 OGRErr SetTPED( double dfLat1, double dfLong1,
00523 double dfLat2, double dfLong2,
00524 double dfFalseEasting, double dfFalseNorthing );
00525
00527 OGRErr SetVDG( double dfCenterLong,
00528 double dfFalseEasting, double dfFalseNorthing );
00529
00531 OGRErr SetUTM( int nZone, int bNorth = TRUE );
00532 int GetUTMZone( int *pbNorth = NULL ) const;
00533
00535 OGRErr SetWagner( int nVariation, double dfCenterLat,
00536 double dfFalseEasting, double dfFalseNorthing );
00537
00539 OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE,
00540 const char *pszOverrideUnitName = NULL,
00541 double dfOverrideUnit = 0.0 );
00542
00543 OGRErr ImportFromESRIStatePlaneWKT(
00544 int nCode, const char* pszDatumName, const char* pszUnitsName,
00545 int nPCSCode, const char* pszCSName = 0 );
00546 OGRErr ImportFromESRIWisconsinWKT(
00547 const char* pszPrjName, double dfCentralMeridian, double dfLatOfOrigin,
00548 const char* pszUnitsName, const char* pszCSName = 0 );
00549 };
00550
00551
00552
00553
00554
00555
00556
00557
00567 class CPL_DLL OGRCoordinateTransformation
00568 {
00569 public:
00570 virtual ~OGRCoordinateTransformation() {}
00571
00572 static void DestroyCT(OGRCoordinateTransformation* poCT);
00573
00574
00575
00577 virtual OGRSpatialReference *GetSourceCS() = 0;
00578
00580 virtual OGRSpatialReference *GetTargetCS() = 0;
00581
00582
00583
00599 virtual int Transform( int nCount,
00600 double *x, double *y, double *z = NULL ) = 0;
00601
00617 virtual int TransformEx( int nCount,
00618 double *x, double *y, double *z = NULL,
00619 int *pabSuccess = NULL ) = 0;
00620
00621 };
00622
00623 OGRCoordinateTransformation CPL_DLL *
00624 OGRCreateCoordinateTransformation( OGRSpatialReference *poSource,
00625 OGRSpatialReference *poTarget );
00626
00627 #endif