OGR
|
00001 /****************************************************************************** 00002 * $Id: ogr_spatialref.h 18490 2010-01-09 05:44:49Z warmerdam $ 00003 * 00004 * Project: OpenGIS Simple Features Reference Implementation 00005 * Purpose: Classes for manipulating spatial reference systems in a 00006 * platform non-specific manner. 00007 * Author: Frank Warmerdam, warmerdam@pobox.com 00008 * 00009 ****************************************************************************** 00010 * Copyright (c) 1999, Les Technologies SoftMap Inc. 00011 * 00012 * Permission is hereby granted, free of charge, to any person obtaining a 00013 * copy of this software and associated documentation files (the "Software"), 00014 * to deal in the Software without restriction, including without limitation 00015 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00016 * and/or sell copies of the Software, and to permit persons to whom the 00017 * Software is furnished to do so, subject to the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be included 00020 * in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00023 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00024 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00025 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00026 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00027 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00028 * DEALINGS IN THE SOFTWARE. 00029 ****************************************************************************/ 00030 00031 #ifndef _OGR_SPATIALREF_H_INCLUDED 00032 #define _OGR_SPATIALREF_H_INCLUDED 00033 00034 #include "ogr_srs_api.h" 00035 00042 /************************************************************************/ 00043 /* OGR_SRSNode */ 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 void ClearChildren(); 00069 int NeedsQuoting() const; 00070 00071 public: 00072 OGR_SRSNode(const char * = NULL); 00073 ~OGR_SRSNode(); 00074 00075 int IsLeafNode() const { return nChildren == 0; } 00076 00077 int GetChildCount() const { return nChildren; } 00078 OGR_SRSNode *GetChild( int ); 00079 const OGR_SRSNode *GetChild( int ) const; 00080 00081 OGR_SRSNode *GetNode( const char * ); 00082 const OGR_SRSNode *GetNode( const char * ) const; 00083 00084 void InsertChild( OGR_SRSNode *, int ); 00085 void AddChild( OGR_SRSNode * ); 00086 int FindChild( const char * ) const; 00087 void DestroyChild( int ); 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 /* OGRSpatialReference */ 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 OGRErr ValidateProjection(); 00139 int IsAliasFor( const char *, const char * ); 00140 void GetNormInfo() const; 00141 00142 public: 00143 OGRSpatialReference(const OGRSpatialReference&); 00144 OGRSpatialReference(const char * = NULL); 00145 00146 virtual ~OGRSpatialReference(); 00147 00148 static void DestroySpatialReference(OGRSpatialReference* poSRS); 00149 00150 OGRSpatialReference &operator=(const OGRSpatialReference&); 00151 00152 int Reference(); 00153 int Dereference(); 00154 int GetReferenceCount() const { return nRefCount; } 00155 void Release(); 00156 00157 OGRSpatialReference *Clone() const; 00158 OGRSpatialReference *CloneGeogCS() const; 00159 00160 OGRErr exportToWkt( char ** ) const; 00161 OGRErr exportToPrettyWkt( char **, int = FALSE) const; 00162 OGRErr exportToProj4( char ** ) const; 00163 OGRErr exportToPCI( char **, char **, double ** ) const; 00164 OGRErr exportToUSGS( long *, long *, double **, long * ) const; 00165 OGRErr exportToXML( char **, const char * = NULL ) const; 00166 OGRErr exportToPanorama( long *, long *, long *, long *, 00167 double * ) const; 00168 OGRErr exportToERM( char *pszProj, char *pszDatum, char *pszUnits ); 00169 OGRErr exportToMICoordSys( char ** ) const; 00170 00171 OGRErr importFromWkt( char ** ); 00172 OGRErr importFromProj4( const char * ); 00173 OGRErr importFromEPSG( int ); 00174 OGRErr importFromEPSGA( int ); 00175 OGRErr importFromESRI( char ** ); 00176 OGRErr importFromPCI( const char *, const char * = NULL, 00177 double * = NULL ); 00178 OGRErr importFromUSGS( long iProjSys, long iZone, 00179 double *padfPrjParams, 00180 long iDatum, int bAnglesInPackedDMSFormat = TRUE ); 00181 OGRErr importFromPanorama( long, long, long, double* ); 00182 OGRErr importFromOzi( const char *, const char *, const char * ); 00183 OGRErr importFromWMSAUTO( const char *pszAutoDef ); 00184 OGRErr importFromXML( const char * ); 00185 OGRErr importFromDict( const char *pszDict, const char *pszCode ); 00186 OGRErr importFromURN( const char * ); 00187 OGRErr importFromERM( const char *pszProj, const char *pszDatum, 00188 const char *pszUnits ); 00189 OGRErr importFromUrl( const char * ); 00190 OGRErr importFromMICoordSys( const char * ); 00191 00192 OGRErr morphToESRI(); 00193 OGRErr morphFromESRI(); 00194 00195 OGRErr Validate(); 00196 OGRErr StripCTParms( OGR_SRSNode * = NULL ); 00197 OGRErr StripVertical(); 00198 OGRErr FixupOrdering(); 00199 OGRErr Fixup(); 00200 00201 int EPSGTreatsAsLatLong(); 00202 const char *GetAxis( const char *pszTargetKey, int iAxis, 00203 OGRAxisOrientation *peOrientation ); 00204 OGRErr SetAxes( const char *pszTargetKey, 00205 const char *pszXAxisName, 00206 OGRAxisOrientation eXAxisOrientation, 00207 const char *pszYAxisName, 00208 OGRAxisOrientation eYAxisOrientation ); 00209 00210 // Machinary for accessing parse nodes 00211 OGR_SRSNode *GetRoot() { return poRoot; } 00212 const OGR_SRSNode *GetRoot() const { return poRoot; } 00213 void SetRoot( OGR_SRSNode * ); 00214 00215 OGR_SRSNode *GetAttrNode(const char *); 00216 const OGR_SRSNode *GetAttrNode(const char *) const; 00217 const char *GetAttrValue(const char *, int = 0) const; 00218 00219 OGRErr SetNode( const char *, const char * ); 00220 OGRErr SetNode( const char *, double ); 00221 00222 OGRErr SetLinearUnitsAndUpdateParameters( const char *pszName, 00223 double dfInMeters ); 00224 OGRErr SetLinearUnits( const char *pszName, double dfInMeters ); 00225 double GetLinearUnits( char ** = NULL ) const; 00226 00227 OGRErr SetAngularUnits( const char *pszName, double dfInRadians ); 00228 double GetAngularUnits( char ** = NULL ) const; 00229 00230 double GetPrimeMeridian( char ** = NULL ) const; 00231 00232 int IsGeographic() const; 00233 int IsProjected() const; 00234 int IsLocal() const; 00235 int IsSameGeogCS( const OGRSpatialReference * ) const; 00236 int IsSame( const OGRSpatialReference * ) const; 00237 00238 void Clear(); 00239 OGRErr SetLocalCS( const char * ); 00240 OGRErr SetProjCS( const char * ); 00241 OGRErr SetProjection( const char * ); 00242 OGRErr SetGeogCS( const char * pszGeogName, 00243 const char * pszDatumName, 00244 const char * pszEllipsoidName, 00245 double dfSemiMajor, double dfInvFlattening, 00246 const char * pszPMName = NULL, 00247 double dfPMOffset = 0.0, 00248 const char * pszUnits = NULL, 00249 double dfConvertToRadians = 0.0 ); 00250 OGRErr SetWellKnownGeogCS( const char * ); 00251 OGRErr CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS ); 00252 00253 OGRErr SetFromUserInput( const char * ); 00254 00255 OGRErr SetTOWGS84( double, double, double, 00256 double = 0.0, double = 0.0, double = 0.0, 00257 double = 0.0 ); 00258 OGRErr GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const; 00259 00260 double GetSemiMajor( OGRErr * = NULL ) const; 00261 double GetSemiMinor( OGRErr * = NULL ) const; 00262 double GetInvFlattening( OGRErr * = NULL ) const; 00263 00264 OGRErr SetAuthority( const char * pszTargetKey, 00265 const char * pszAuthority, 00266 int nCode ); 00267 00268 OGRErr AutoIdentifyEPSG(); 00269 int GetEPSGGeogCS(); 00270 00271 const char *GetAuthorityCode( const char * pszTargetKey ) const; 00272 const char *GetAuthorityName( const char * pszTargetKey ) const; 00273 00274 const char *GetExtension( const char *pszTargetKey, 00275 const char *pszName, 00276 const char *pszDefault = NULL ) const; 00277 OGRErr SetExtension( const char *pszTargetKey, 00278 const char *pszName, 00279 const char *pszValue ); 00280 00281 int FindProjParm( const char *pszParameter, 00282 const OGR_SRSNode *poPROJCS=NULL ) const; 00283 OGRErr SetProjParm( const char *, double ); 00284 double GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const; 00285 00286 OGRErr SetNormProjParm( const char *, double ); 00287 double GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const; 00288 00289 static int IsAngularParameter( const char * ); 00290 static int IsLongitudeParameter( const char * ); 00291 static int IsLinearParameter( const char * ); 00292 00294 OGRErr SetACEA( double dfStdP1, double dfStdP2, 00295 double dfCenterLat, double dfCenterLong, 00296 double dfFalseEasting, double dfFalseNorthing ); 00297 00299 OGRErr SetAE( double dfCenterLat, double dfCenterLong, 00300 double dfFalseEasting, double dfFalseNorthing ); 00301 00303 OGRErr SetBonne( double dfStdP1, double dfCentralMeridian, 00304 double dfFalseEasting, double dfFalseNorthing ); 00305 00307 OGRErr SetCEA( double dfStdP1, double dfCentralMeridian, 00308 double dfFalseEasting, double dfFalseNorthing ); 00309 00311 OGRErr SetCS( double dfCenterLat, double dfCenterLong, 00312 double dfFalseEasting, double dfFalseNorthing ); 00313 00315 OGRErr SetEC( double dfStdP1, double dfStdP2, 00316 double dfCenterLat, double dfCenterLong, 00317 double dfFalseEasting, double dfFalseNorthing ); 00318 00320 OGRErr SetEckert( int nVariation, double dfCentralMeridian, 00321 double dfFalseEasting, double dfFalseNorthing ); 00322 00323 OGRErr SetEckertIV( double dfCentralMeridian, 00324 double dfFalseEasting, double dfFalseNorthing ); 00325 00326 OGRErr SetEckertVI( double dfCentralMeridian, 00327 double dfFalseEasting, double dfFalseNorthing ); 00328 00330 OGRErr SetEquirectangular(double dfCenterLat, double dfCenterLong, 00331 double dfFalseEasting, double dfFalseNorthing ); 00333 OGRErr SetEquirectangular2( double dfCenterLat, double dfCenterLong, 00334 double dfPseudoStdParallel1, 00335 double dfFalseEasting, double dfFalseNorthing ); 00336 00338 OGRErr SetGEOS( double dfCentralMeridian, double dfSatelliteHeight, 00339 double dfFalseEasting, double dfFalseNorthing ); 00340 00342 OGRErr SetGH( double dfCentralMeridian, 00343 double dfFalseEasting, double dfFalseNorthing ); 00344 00346 OGRErr SetGS( double dfCentralMeridian, 00347 double dfFalseEasting, double dfFalseNorthing ); 00348 00350 OGRErr SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong, 00351 double dfScale, 00352 double dfFalseEasting, double dfFalseNorthing ); 00353 00355 OGRErr SetGnomonic(double dfCenterLat, double dfCenterLong, 00356 double dfFalseEasting, double dfFalseNorthing ); 00357 00358 OGRErr SetHOM( double dfCenterLat, double dfCenterLong, 00359 double dfAzimuth, double dfRectToSkew, 00360 double dfScale, 00361 double dfFalseEasting, double dfFalseNorthing ); 00362 00363 OGRErr SetHOM2PNO( double dfCenterLat, 00364 double dfLat1, double dfLong1, 00365 double dfLat2, double dfLong2, 00366 double dfScale, 00367 double dfFalseEasting, double dfFalseNorthing ); 00368 00370 OGRErr SetIWMPolyconic( double dfLat1, double dfLat2, 00371 double dfCenterLong, 00372 double dfFalseEasting, 00373 double dfFalseNorthing ); 00374 00376 OGRErr SetKrovak( double dfCenterLat, double dfCenterLong, 00377 double dfAzimuth, double dfPseudoStdParallelLat, 00378 double dfScale, 00379 double dfFalseEasting, double dfFalseNorthing ); 00380 00382 OGRErr SetLAEA( double dfCenterLat, double dfCenterLong, 00383 double dfFalseEasting, double dfFalseNorthing ); 00384 00386 OGRErr SetLCC( double dfStdP1, double dfStdP2, 00387 double dfCenterLat, double dfCenterLong, 00388 double dfFalseEasting, double dfFalseNorthing ); 00389 00391 OGRErr SetLCC1SP( double dfCenterLat, double dfCenterLong, 00392 double dfScale, 00393 double dfFalseEasting, double dfFalseNorthing ); 00394 00396 OGRErr SetLCCB( double dfStdP1, double dfStdP2, 00397 double dfCenterLat, double dfCenterLong, 00398 double dfFalseEasting, double dfFalseNorthing ); 00399 00401 OGRErr SetMC( double dfCenterLat, double dfCenterLong, 00402 double dfFalseEasting, double dfFalseNorthing ); 00403 00405 OGRErr SetMercator( double dfCenterLat, double dfCenterLong, 00406 double dfScale, 00407 double dfFalseEasting, double dfFalseNorthing ); 00408 00409 OGRErr SetMercator2SP( double dfStdP1, 00410 double dfCenterLat, double dfCenterLong, 00411 double dfFalseEasting, double dfFalseNorthing ); 00412 00414 OGRErr SetMollweide( double dfCentralMeridian, 00415 double dfFalseEasting, double dfFalseNorthing ); 00416 00418 OGRErr SetNZMG( double dfCenterLat, double dfCenterLong, 00419 double dfFalseEasting, double dfFalseNorthing ); 00420 00422 OGRErr SetOS( double dfOriginLat, double dfCMeridian, 00423 double dfScale, 00424 double dfFalseEasting,double dfFalseNorthing); 00425 00427 OGRErr SetOrthographic( double dfCenterLat, double dfCenterLong, 00428 double dfFalseEasting,double dfFalseNorthing); 00429 00431 OGRErr SetPolyconic( double dfCenterLat, double dfCenterLong, 00432 double dfFalseEasting, double dfFalseNorthing ); 00433 00435 OGRErr SetPS( double dfCenterLat, double dfCenterLong, 00436 double dfScale, 00437 double dfFalseEasting, double dfFalseNorthing); 00438 00440 OGRErr SetRobinson( double dfCenterLong, 00441 double dfFalseEasting, double dfFalseNorthing ); 00442 00444 OGRErr SetSinusoidal( double dfCenterLong, 00445 double dfFalseEasting, double dfFalseNorthing ); 00446 00448 OGRErr SetStereographic( double dfCenterLat, double dfCenterLong, 00449 double dfScale, 00450 double dfFalseEasting,double dfFalseNorthing); 00451 00453 OGRErr SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian, 00454 double dfFalseEasting, double dfFalseNorthing ); 00455 00457 OGRErr SetTM( double dfCenterLat, double dfCenterLong, 00458 double dfScale, 00459 double dfFalseEasting, double dfFalseNorthing ); 00460 00462 OGRErr SetTMVariant( const char *pszVariantName, 00463 double dfCenterLat, double dfCenterLong, 00464 double dfScale, 00465 double dfFalseEasting, double dfFalseNorthing ); 00466 00468 OGRErr SetTMG( double dfCenterLat, double dfCenterLong, 00469 double dfFalseEasting, double dfFalseNorthing ); 00470 00472 OGRErr SetTMSO( double dfCenterLat, double dfCenterLong, 00473 double dfScale, 00474 double dfFalseEasting, double dfFalseNorthing ); 00475 00477 OGRErr SetTPED( double dfLat1, double dfLong1, 00478 double dfLat2, double dfLong2, 00479 double dfFalseEasting, double dfFalseNorthing ); 00480 00482 OGRErr SetVDG( double dfCenterLong, 00483 double dfFalseEasting, double dfFalseNorthing ); 00484 00486 OGRErr SetUTM( int nZone, int bNorth = TRUE ); 00487 int GetUTMZone( int *pbNorth = NULL ) const; 00488 00490 OGRErr SetWagner( int nVariation, double dfCenterLat, 00491 double dfFalseEasting, double dfFalseNorthing ); 00492 00494 OGRErr SetStatePlane( int nZone, int bNAD83 = TRUE, 00495 const char *pszOverrideUnitName = NULL, 00496 double dfOverrideUnit = 0.0 ); 00497 }; 00498 00499 /************************************************************************/ 00500 /* OGRCoordinateTransformation */ 00501 /* */ 00502 /* This is really just used as a base class for a private */ 00503 /* implementation. */ 00504 /************************************************************************/ 00505 00515 class CPL_DLL OGRCoordinateTransformation 00516 { 00517 public: 00518 virtual ~OGRCoordinateTransformation() {} 00519 00520 static void DestroyCT(OGRCoordinateTransformation* poCT); 00521 00522 // From CT_CoordinateTransformation 00523 00525 virtual OGRSpatialReference *GetSourceCS() = 0; 00526 00528 virtual OGRSpatialReference *GetTargetCS() = 0; 00529 00530 // From CT_MathTransform 00531 00547 virtual int Transform( int nCount, 00548 double *x, double *y, double *z = NULL ) = 0; 00549 00565 virtual int TransformEx( int nCount, 00566 double *x, double *y, double *z = NULL, 00567 int *pabSuccess = NULL ) = 0; 00568 00569 }; 00570 00571 OGRCoordinateTransformation CPL_DLL * 00572 OGRCreateCoordinateTransformation( OGRSpatialReference *poSource, 00573 OGRSpatialReference *poTarget ); 00574 00575 #endif /* ndef _OGR_SPATIALREF_H_INCLUDED */