⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrspatialreference.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        SetRoot( new OGR_SRSNode( papszPathTokens[0] ) );    }    poNode = GetRoot();    for( i = 1; papszPathTokens[i] != NULL; i++ )    {        int     j;                for( j = 0; j < poNode->GetChildCount(); j++ )        {            if( EQUAL(poNode->GetChild( j )->GetValue(),papszPathTokens[i]) )            {                poNode = poNode->GetChild(j);                j = -1;                break;            }        }        if( j != -1 )        {            OGR_SRSNode *poNewNode = new OGR_SRSNode( papszPathTokens[i] );            poNode->AddChild( poNewNode );            poNode = poNewNode;        }    }    CSLDestroy( papszPathTokens );    if( pszNewNodeValue != NULL )    {        if( poNode->GetChildCount() > 0 )            poNode->GetChild(0)->SetValue( pszNewNodeValue );        else            poNode->AddChild( new OGR_SRSNode( pszNewNodeValue ) );    }    return OGRERR_NONE;}/************************************************************************//*                          OSRSetAttrValue()                           *//************************************************************************/OGRErr CPL_STDCALL OSRSetAttrValue( OGRSpatialReferenceH hSRS,                         const char * pszPath, const char * pszValue ){    return ((OGRSpatialReference *) hSRS)->SetNode( pszPath, pszValue );}/************************************************************************//*                              SetNode()                               *//************************************************************************/OGRErr OGRSpatialReference::SetNode( const char *pszNodePath,                                     double dfValue ){    char        szValue[64];    if( ABS(dfValue - (int) dfValue) == 0.0 )        sprintf( szValue, "%d", (int) dfValue );    else        // notdef: sprintf( szValue, "%.16g", dfValue );        OGRPrintDouble( szValue, dfValue );    return SetNode( pszNodePath, szValue );}/************************************************************************//*                          SetAngularUnits()                           *//************************************************************************//** * Set the angular units for the geographic coordinate system. * * This method creates a UNITS subnode with the specified values as a * child of the GEOGCS node.  * * This method does the same as the C function OSRSetAngularUnits().  * * @param pszUnitsName the units name to be used.  Some preferred units * names can be found in ogr_srs_api.h such as SRS_UA_DEGREE.  * * @param dfInRadians the value to multiple by an angle in the indicated * units to transform to radians.  Some standard conversion factors can * be found in ogr_srs_api.h.  * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetAngularUnits( const char * pszUnitsName,                                             double dfInRadians ){    OGR_SRSNode *poCS;    OGR_SRSNode *poUnits;    char        szValue[128];    bNormInfoSet = FALSE;    poCS = GetAttrNode( "GEOGCS" );    if( poCS == NULL )        return OGRERR_FAILURE;    OGRPrintDouble( szValue, dfInRadians );    if( poCS->FindChild( "UNIT" ) >= 0 )    {        poUnits = poCS->GetChild( poCS->FindChild( "UNIT" ) );        poUnits->GetChild(0)->SetValue( pszUnitsName );        poUnits->GetChild(1)->SetValue( szValue );    }    else    {        poUnits = new OGR_SRSNode( "UNIT" );        poUnits->AddChild( new OGR_SRSNode( pszUnitsName ) );        poUnits->AddChild( new OGR_SRSNode( szValue ) );                poCS->AddChild( poUnits );    }    return OGRERR_NONE;}/************************************************************************//*                         OSRSetAngularUnits()                         *//************************************************************************/OGRErr OSRSetAngularUnits( OGRSpatialReferenceH hSRS,                            const char * pszUnits, double dfInRadians ){    return ((OGRSpatialReference *) hSRS)->SetAngularUnits( pszUnits,                                                             dfInRadians );}/************************************************************************//*                          GetAngularUnits()                           *//************************************************************************//** * Fetch angular geographic coordinate system units. * * If no units are available, a value of "degree" and SRS_UA_DEGREE_CONV  * will be assumed.  This method only checks directly under the GEOGCS node * for units. * * This method does the same thing as the C function OSRGetAngularUnits(). * * @param ppszName a pointer to be updated with the pointer to the  * units name.  The returned value remains internal to the OGRSpatialReference * and shouldn't be freed, or modified.  It may be invalidated on the next * OGRSpatialReference call.  * * @return the value to multiply by angular distances to transform them to  * radians. */double OGRSpatialReference::GetAngularUnits( char ** ppszName ) const{    const OGR_SRSNode *poCS = GetAttrNode( "GEOGCS" );    if( ppszName != NULL )        *ppszName = "degree";            if( poCS == NULL )        return atof(SRS_UA_DEGREE_CONV);    for( int iChild = 0; iChild < poCS->GetChildCount(); iChild++ )    {        const OGR_SRSNode     *poChild = poCS->GetChild(iChild);                if( EQUAL(poChild->GetValue(),"UNIT")            && poChild->GetChildCount() >= 2 )        {            if( ppszName != NULL )                *ppszName = (char *) poChild->GetChild(0)->GetValue();                        return atof( poChild->GetChild(1)->GetValue() );        }    }    return 1.0;}/************************************************************************//*                         OSRGetAngularUnits()                         *//************************************************************************/double OSRGetAngularUnits( OGRSpatialReferenceH hSRS, char ** ppszName )    {    return ((OGRSpatialReference *) hSRS)->GetAngularUnits( ppszName );}/************************************************************************//*                 SetLinearUnitsAndUpdateParameters()                  *//************************************************************************//** * Set the linear units for the projection. * * This method creates a UNITS subnode with the specified values as a * child of the PROJCS or LOCAL_CS node.   It works the same as the * SetLinearUnits() method, but it also updates all existing linear * projection parameter values from the old units to the new units.  * * @param pszUnitsName the units name to be used.  Some preferred units * names can be found in ogr_srs_api.h such as SRS_UL_METER, SRS_UL_FOOT  * and SRS_UL_US_FOOT.  * * @param dfInMeters the value to multiple by a length in the indicated * units to transform to meters.  Some standard conversion factors can * be found in ogr_srs_api.h.  * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetLinearUnitsAndUpdateParameters(    const char *pszName, double dfInMeters ){    double dfOldInMeters = GetLinearUnits();    OGR_SRSNode *poPROJCS = GetAttrNode( "PROJCS" );    if( dfInMeters == 0.0 )        return OGRERR_FAILURE;    if( dfInMeters == dfOldInMeters || poPROJCS == NULL )        return SetLinearUnits( pszName, dfInMeters );    for( int iChild = 0; iChild < poPROJCS->GetChildCount(); iChild++ )    {        const OGR_SRSNode     *poChild = poPROJCS->GetChild(iChild);                if( EQUAL(poChild->GetValue(),"PARAMETER")            && poChild->GetChildCount() > 1 )        {            char *pszParmName = CPLStrdup(poChild->GetChild(0)->GetValue());                        if( IsLinearParameter( pszParmName ) )            {                double dfOldValue = GetProjParm( pszParmName );                SetProjParm( pszParmName,                              dfOldValue * dfOldInMeters / dfInMeters );            }            CPLFree( pszParmName );        }    }    return SetLinearUnits( pszName, dfInMeters );}/************************************************************************//*                           SetLinearUnits()                           *//************************************************************************//** * Set the linear units for the projection. * * This method creates a UNITS subnode with the specified values as a * child of the PROJCS or LOCAL_CS node.  * * This method does the same as the C function OSRSetLinearUnits().  * * @param pszUnitsName the units name to be used.  Some preferred units * names can be found in ogr_srs_api.h such as SRS_UL_METER, SRS_UL_FOOT  * and SRS_UL_US_FOOT.  * * @param dfInMeters the value to multiple by a length in the indicated * units to transform to meters.  Some standard conversion factors can * be found in ogr_srs_api.h.  * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetLinearUnits( const char * pszUnitsName,                                            double dfInMeters ){    OGR_SRSNode *poCS;    OGR_SRSNode *poUnits;    char        szValue[128];    bNormInfoSet = FALSE;    poCS = GetAttrNode( "PROJCS" );    if( poCS == NULL )        poCS = GetAttrNode( "LOCAL_CS" );    if( poCS == NULL )        return OGRERR_FAILURE;    if( dfInMeters == (int) dfInMeters )        sprintf( szValue, "%d", (int) dfInMeters );    else        //notdef: sprintf( szValue, "%.16g", dfInMeters );        OGRPrintDouble( szValue, dfInMeters );    if( poCS->FindChild( "UNIT" ) >= 0 )    {        poUnits = poCS->GetChild( poCS->FindChild( "UNIT" ) );        poUnits->GetChild(0)->SetValue( pszUnitsName );        poUnits->GetChild(1)->SetValue( szValue );        if( poUnits->FindChild( "AUTHORITY" ) != -1 )            poUnits->DestroyChild( poUnits->FindChild( "AUTHORITY" ) );    }    else    {        poUnits = new OGR_SRSNode( "UNIT" );        poUnits->AddChild( new OGR_SRSNode( pszUnitsName ) );        poUnits->AddChild( new OGR_SRSNode( szValue ) );                poCS->AddChild( poUnits );    }    return OGRERR_NONE;}/************************************************************************//*                         OSRSetLinearUnits()                          *//************************************************************************/OGRErr OSRSetLinearUnits( OGRSpatialReferenceH hSRS,                           const char * pszUnits, double dfInMeters ){    return ((OGRSpatialReference *) hSRS)->SetLinearUnits( pszUnits,                                                            dfInMeters );}/************************************************************************//*                           GetLinearUnits()                           *//************************************************************************//** * Fetch linear projection units.  * * If no units are available, a value of "Meters" and 1.0 will be assumed. * This method only checks directly under the PROJCS or LOCAL_CS node for  * units. * * This method does the same thing as the C function OSRGetLinearUnits()/ * * @param ppszName a pointer to be updated with the pointer to the  * units name.  The returned value remains internal to the OGRSpatialReference * and shouldn't be freed, or modified.  It may be invalidated on the next * OGRSpatialReference call.  * * @return the value to multiply by linear distances to transform them to  * meters. */double OGRSpatialReference::GetLinearUnits( char ** ppszName ) const{    const OGR_SRSNode *poCS = GetAttrNode( "PROJCS" );    if( poCS == NULL )        poCS = GetAttrNode( "LOCAL_CS" );    if( ppszName != NULL )        *ppszName = "unknown";            if( poCS == NULL )        return 1.0;    for( int iChild = 0; iChild < poCS->GetChildCount(); iChild++ )    {        const OGR_SRSNode     *poChild = poCS->GetChild(iChild);                if( EQUAL(poChild->GetValue(),"UNIT")

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -