📄 ogrspatialreference.cpp
字号:
CPLDebug( "OGR", "OGRSpatialReference::SetFromUserInput(%s), opened file\n" "but it is to large for our generous buffer. Is it really\n" "just a WKT definition?" ); CPLFree( pszBuffer ); return OGRERR_FAILURE; } pszBuffer[nBytes] = '\0'; pszBufPtr = pszBuffer; while( pszBufPtr[0] == ' ' || pszBufPtr[0] == '\n' ) pszBufPtr++; if( pszBufPtr[0] == '<' ) err = importFromXML( pszBufPtr ); else if( strstr(pszBuffer,"+proj") != NULL || strstr(pszBuffer,"+init") != NULL ) err = importFromProj4( pszBufPtr ); else { err = importFromWkt( &pszBufPtr ); if( err == OGRERR_NONE && bESRI ) err = morphFromESRI(); } CPLFree( pszBuffer ); return err;}/************************************************************************//* OSRSetFromUserInput() *//************************************************************************/OGRErr OSRSetFromUserInput( OGRSpatialReferenceH hSRS, const char *pszDef ){ return ((OGRSpatialReference *) hSRS)->SetFromUserInput( pszDef );}/************************************************************************//* GetSemiMajor() *//************************************************************************//** * Get spheroid semi major axis. * * This method does the same thing as the C function OSRGetSemiMajor(). * * @param pnErr if non-NULL set to OGRERR_FAILURE if semi major axis * can be found. * * @return semi-major axis, or SRS_WGS84_SEMIMAJOR if it can't be found. */double OGRSpatialReference::GetSemiMajor( OGRErr * pnErr ) const{ const OGR_SRSNode *poSpheroid = GetAttrNode( "SPHEROID" ); if( pnErr != NULL ) *pnErr = OGRERR_NONE; if( poSpheroid != NULL && poSpheroid->GetChildCount() >= 3 ) { return atof( poSpheroid->GetChild(1)->GetValue() ); } else { if( pnErr != NULL ) *pnErr = OGRERR_FAILURE; return SRS_WGS84_SEMIMAJOR; }}/************************************************************************//* OSRGetSemiMajor() *//************************************************************************/double OSRGetSemiMajor( OGRSpatialReferenceH hSRS, OGRErr *pnErr ){ return ((OGRSpatialReference *) hSRS)->GetSemiMajor( pnErr );}/************************************************************************//* GetInvFlattening() *//************************************************************************//** * Get spheroid inverse flattening. * * This method does the same thing as the C function OSRGetInvFlattening(). * * @param pnErr if non-NULL set to OGRERR_FAILURE if no inverse flattening * can be found. * * @return inverse flattening, or SRS_WGS84_INVFLATTENING if it can't be found. */double OGRSpatialReference::GetInvFlattening( OGRErr * pnErr ) const{ const OGR_SRSNode *poSpheroid = GetAttrNode( "SPHEROID" ); if( pnErr != NULL ) *pnErr = OGRERR_NONE; if( poSpheroid != NULL && poSpheroid->GetChildCount() >= 3 ) { return atof( poSpheroid->GetChild(2)->GetValue() ); } else { if( pnErr != NULL ) *pnErr = OGRERR_FAILURE; return SRS_WGS84_INVFLATTENING; }}/************************************************************************//* OSRGetInvFlattening() *//************************************************************************/double OSRGetInvFlattening( OGRSpatialReferenceH hSRS, OGRErr *pnErr ){ return ((OGRSpatialReference *) hSRS)->GetInvFlattening( pnErr );}/************************************************************************//* GetSemiMinor() *//************************************************************************//** * Get spheroid semi minor axis. * * This method does the same thing as the C function OSRGetSemiMinor(). * * @param pnErr if non-NULL set to OGRERR_FAILURE if semi minor axis * can be found. * * @return semi-minor axis, or WGS84 semi minor if it can't be found. */double OGRSpatialReference::GetSemiMinor( OGRErr * pnErr ) const{ double dfInvFlattening, dfSemiMajor; dfSemiMajor = GetSemiMajor( pnErr ); dfInvFlattening = GetInvFlattening( pnErr ); if( ABS(dfInvFlattening) < 0.000000000001 ) return dfSemiMajor; else return dfSemiMajor * (1.0 - 1.0/dfInvFlattening);}/************************************************************************//* OSRGetSemiMinor() *//************************************************************************/double OSRGetSemiMinor( OGRSpatialReferenceH hSRS, OGRErr *pnErr ){ return ((OGRSpatialReference *) hSRS)->GetSemiMinor( pnErr );}/************************************************************************//* SetLocalCS() *//************************************************************************//** * Set the user visible LOCAL_CS name. * * This method is the same as the C function OSRSetLocalCS(). * * This method is will ensure a LOCAL_CS node is created as the root, * and set the provided name on it. It must be used before SetLinearUnits(). * * @param pszName the user visible name to assign. Not used as a key. * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetLocalCS( const char * pszName ){ OGR_SRSNode *poCS = GetAttrNode( "LOCAL_CS" ); if( poCS == NULL && GetRoot() != NULL ) { CPLDebug( "OGR", "OGRSpatialReference::SetLocalCS(%s) failed.\n" "It appears an incompatible root node (%s) already exists.\n", GetRoot()->GetValue() ); return OGRERR_FAILURE; } else { SetNode( "LOCAL_CS", pszName ); return OGRERR_NONE; }}/************************************************************************//* OSRSetLocalCS() *//************************************************************************/OGRErr OSRSetLocalCS( OGRSpatialReferenceH hSRS, const char * pszName ){ return ((OGRSpatialReference *) hSRS)->SetLocalCS( pszName );}/************************************************************************//* SetProjCS() *//************************************************************************//** * Set the user visible PROJCS name. * * This method is the same as the C function OSRSetProjCS(). * * This method is will ensure a PROJCS node is created as the root, * and set the provided name on it. If used on a GEOGCS coordinate system, * the GEOGCS node will be demoted to be a child of the new PROJCS root. * * @param pszName the user visible name to assign. Not used as a key. * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetProjCS( const char * pszName ){ OGR_SRSNode *poGeogCS = NULL; OGR_SRSNode *poProjCS = GetAttrNode( "PROJCS" ); if( poRoot != NULL && EQUAL(poRoot->GetValue(),"GEOGCS") ) { poGeogCS = poRoot; poRoot = NULL; } if( poProjCS == NULL && GetRoot() != NULL ) { CPLDebug( "OGR", "OGRSpatialReference::SetProjCS(%s) failed.\n" "It appears an incompatible root node (%s) already exists.\n", GetRoot()->GetValue() ); return OGRERR_FAILURE; } SetNode( "PROJCS", pszName ); if( poGeogCS != NULL ) poRoot->InsertChild( poGeogCS, 1 ); return OGRERR_NONE;}/************************************************************************//* OSRSetProjCS() *//************************************************************************/OGRErr OSRSetProjCS( OGRSpatialReferenceH hSRS, const char * pszName ){ return ((OGRSpatialReference *) hSRS)->SetProjCS( pszName );}/************************************************************************//* SetProjection() *//************************************************************************/OGRErr OGRSpatialReference::SetProjection( const char * pszProjection ){ OGR_SRSNode *poGeogCS = NULL; OGRErr eErr; if( poRoot != NULL && EQUAL(poRoot->GetValue(),"GEOGCS") ) { poGeogCS = poRoot; poRoot = NULL; } if( !GetAttrNode( "PROJCS" ) ) { SetNode( "PROJCS", "unnamed" ); } eErr = SetNode( "PROJCS|PROJECTION", pszProjection ); if( eErr != OGRERR_NONE ) return eErr; if( poGeogCS != NULL ) poRoot->InsertChild( poGeogCS, 1 ); return OGRERR_NONE;}/************************************************************************//* SetProjParm() *//************************************************************************//** * Set a projection parameter value. * * Adds a new PARAMETER under the PROJCS with the indicated name and value. * * This method is the same as the C function OSRSetProjParm(). * * Please check http://www.remotesensing.org/geotiff/proj_list pages for * legal parameter names for specific projections. * * * @param pszParmName the parameter name, which should be selected from * the macros in ogr_srs_api.h, such as SRS_PP_CENTRAL_MERIDIAN. * * @param dfValue value to assign. * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetProjParm( const char * pszParmName, double dfValue ){ OGR_SRSNode *poPROJCS = GetAttrNode( "PROJCS" ); OGR_SRSNode *poParm; char szValue[64]; if( poPROJCS == NULL ) return OGRERR_FAILURE; OGRPrintDouble( szValue, dfValue );/* -------------------------------------------------------------------- *//* Try to find existing parameter with this name. *//* -------------------------------------------------------------------- */ for( int iChild = 0; iChild < poPROJCS->GetChildCount(); iChild++ ) { poParm = poPROJCS->GetChild( iChild ); if( EQUAL(poParm->GetValue(),"PARAMETER") && poParm->GetChildCount() == 2 && EQUAL(poParm->GetChild(0)->GetValue(),pszParmName) ) { poParm->GetChild(1)->SetValue( szValue ); return OGRERR_NONE; } } /* -------------------------------------------------------------------- *//* Otherwise create a new parameter and append. *//* -------------------------------------------------------------------- */ poParm = new OGR_SRSNode( "PARAMETER" ); poParm->AddChild( new OGR_SRSNode( pszParmName ) ); poParm->AddChild( new OGR_SRSNode( szValue ) ); poPROJCS->AddChild( poParm ); return OGRERR_NONE;}/************************************************************************//* OSRSetProjParm() *//************************************************************************/OGRErr OSRSetProjParm( OGRSpatialReferenceH hSRS, const char * pszParmName, double dfValue ){ return ((OGRSpatialReference *) hSRS)->SetProjParm( pszParmName, dfValue );}/*****************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -