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

📄 ogr_srs_esri.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        int nGCSCode = -1;                if( pszAuthName != NULL && EQUAL(pszAuthName,"EPSG") )            nGCSCode = atoi(GetAuthorityCode("GEOGCS"));        if( nGCSCode == 4326             || EQUAL(pszGeogCSName,"WGS84")             || EQUAL(pszGeogCSName,"WGS 84") )        {            poGeogCS->GetChild(0)->SetValue( "GCS_WGS_1984" );            pszUTMPrefix = "WGS_1984";        }        else if( nGCSCode == 4267                 || EQUAL(pszGeogCSName,"NAD27")                  || EQUAL(pszGeogCSName,"NAD 27") )        {            poGeogCS->GetChild(0)->SetValue( "GCS_North_American_1927" );            pszUTMPrefix = "NAD_1927";        }        else if( nGCSCode == 4269                 || EQUAL(pszGeogCSName,"NAD83")                  || EQUAL(pszGeogCSName,"NAD 83") )        {            poGeogCS->GetChild(0)->SetValue( "GCS_North_American_1983" );            pszUTMPrefix = "NAD_1983";        }/* -------------------------------------------------------------------- *//*      Force Unnamed to Unknown for most common locations.             *//* -------------------------------------------------------------------- */    static char *apszUnknownMapping[] = {         "Unknown", "Unnamed",        NULL, NULL     };    GetRoot()->applyRemapper( "PROJCS",                               apszUnknownMapping+1, apszUnknownMapping+0, 2 );    GetRoot()->applyRemapper( "GEOGCS",                               apszUnknownMapping+1, apszUnknownMapping+0, 2 );    GetRoot()->applyRemapper( "DATUM",                               apszUnknownMapping+1, apszUnknownMapping+0, 2 );    GetRoot()->applyRemapper( "SPHEROID",                               apszUnknownMapping+1, apszUnknownMapping+0, 2 );    GetRoot()->applyRemapper( "PRIMEM",                               apszUnknownMapping+1, apszUnknownMapping+0, 2 );    /* -------------------------------------------------------------------- *//*      If the PROJCS name is unset, use the PROJECTION name in         *//*      place of unknown, or unnamed.  At the request of Peng Gao.      *//* -------------------------------------------------------------------- */    OGR_SRSNode *poNode;    poNode = GetAttrNode( "PROJCS" );    if( poNode != NULL )        poNode = poNode->GetChild( 0 );    if( poNode != NULL         && ( EQUAL(poNode->GetValue(),"unnamed")             || EQUAL(poNode->GetValue(),"unknown")             || EQUAL(poNode->GetValue(),"") ) )    {        if( GetAttrValue( "PROJECTION", 0 ) != NULL )            poNode->SetValue( GetAttrValue( "PROJECTION", 0 ) );    }/* -------------------------------------------------------------------- *//*      Prepare very specific PROJCS names for UTM coordinate           *//*      systems.                                                        *//* -------------------------------------------------------------------- */        int bNorth, nZone;        nZone = GetUTMZone( &bNorth );        if( nZone > 0 && pszUTMPrefix != NULL )        {            char szUTMName[128];            if( bNorth )                sprintf( szUTMName, "%s_UTM_Zone_%dN", pszUTMPrefix, nZone );            else                sprintf( szUTMName, "%s_UTM_Zone_%dS", pszUTMPrefix, nZone );                        OGR_SRSNode *poProjCS = GetAttrNode( "PROJCS" );            if( poProjCS != NULL )                poProjCS->GetChild(0)->SetValue( szUTMName );        }    }/* -------------------------------------------------------------------- *//*      Translate UNIT keywords that are misnamed, or even the wrong    *//*      case.                                                           *//* -------------------------------------------------------------------- */    GetRoot()->applyRemapper( "UNIT",                               apszUnitMapping+1, apszUnitMapping, 2 );/* -------------------------------------------------------------------- *//*      reset constants for decimal degrees to the exact string ESRI    *//*      expects when encountered to ensure a matchup.                   *//* -------------------------------------------------------------------- */    OGR_SRSNode *poUnit = GetAttrNode( "GEOGCS|UNIT" );        if( poUnit != NULL && poUnit->GetChildCount() >= 2         && ABS(GetAngularUnits()-0.0174532925199433) < 0.00000000001 )    {        poUnit->GetChild(0)->SetValue("Degree");        poUnit->GetChild(1)->SetValue("0.017453292519943295");    }/* -------------------------------------------------------------------- *//*      Make sure we reproduce US Feet exactly too.                     *//* -------------------------------------------------------------------- */    poUnit = GetAttrNode( "PROJCS|UNIT" );        if( poUnit != NULL && poUnit->GetChildCount() >= 2         && ABS(GetLinearUnits()- 0.30480060960121924) < 0.000000000000001)    {        poUnit->GetChild(0)->SetValue("Foot_US");        poUnit->GetChild(1)->SetValue("0.30480060960121924");    }/* -------------------------------------------------------------------- *//*      Remap parameters used for Albers and Mercator.                  *//* -------------------------------------------------------------------- */    pszProjection = GetAttrValue("PROJECTION");        if( pszProjection != NULL && EQUAL(pszProjection,"Albers") )        GetRoot()->applyRemapper(             "PARAMETER", apszAlbersMapping + 1, apszAlbersMapping + 0, 2 );    if( pszProjection != NULL         && EQUAL(pszProjection,SRS_PT_EQUIDISTANT_CONIC) )        GetRoot()->applyRemapper(             "PARAMETER", apszECMapping + 1, apszECMapping + 0, 2 );    if( pszProjection != NULL && EQUAL(pszProjection,"Mercator") )        GetRoot()->applyRemapper(             "PARAMETER", apszMercatorMapping + 1, apszMercatorMapping + 0, 2 );    if( pszProjection != NULL         && EQUALN(pszProjection,"Stereographic_",14)        && EQUALN(pszProjection+strlen(pszProjection)-5,"_Pole",5) )        GetRoot()->applyRemapper(             "PARAMETER",             apszPolarStereographicMapping + 1,             apszPolarStereographicMapping + 0, 2 );/* -------------------------------------------------------------------- *//*      Convert SPHEROID name to use underscores instead of spaces.     *//* -------------------------------------------------------------------- */    OGR_SRSNode *poSpheroid;    poSpheroid = GetAttrNode( "SPHEROID" );    if( poSpheroid != NULL )        poSpheroid = poSpheroid->GetChild(0);    if( poSpheroid != NULL )    {        char *pszNewValue = CPLStrdup(RemapSpheroidName(poSpheroid->GetValue()));        MorphNameToESRI( &pszNewValue );        poSpheroid->SetValue( pszNewValue );        CPLFree( pszNewValue );    }    /* -------------------------------------------------------------------- *//*      Try to insert a D_ in front of the datum name.                  *//* -------------------------------------------------------------------- */    OGR_SRSNode *poDatum;    poDatum = GetAttrNode( "DATUM" );    if( poDatum != NULL )        poDatum = poDatum->GetChild(0);    if( poDatum != NULL )    {        if( !EQUALN(poDatum->GetValue(),"D_",2) )        {            char *pszNewValue;            pszNewValue = (char *) CPLMalloc(strlen(poDatum->GetValue())+3);            strcpy( pszNewValue, "D_" );            strcat( pszNewValue, poDatum->GetValue() );            poDatum->SetValue( pszNewValue );            CPLFree( pszNewValue );        }    }    return OGRERR_NONE;}/************************************************************************//*                           OSRMorphToESRI()                           *//************************************************************************/OGRErr OSRMorphToESRI( OGRSpatialReferenceH hSRS ){    return ((OGRSpatialReference *) hSRS)->morphToESRI();}/************************************************************************//*                           morphFromESRI()                            *//*                                                                      *//*      modify this definition from the ESRI definition of WKT to       *//*      the "Standard" definition.                                      *//************************************************************************//** * Convert in place to ESRI WKT format. * * The value nodes of this coordinate system as modified in various manners * more closely map onto the ESRI concept of WKT format.  This includes * renaming a variety of projections and arguments, and stripping out  * nodes note recognised by ESRI (like AUTHORITY and AXIS).  * * This does the same as the C function OSRMorphFromESRI(). * * @return OGRERR_NONE unless something goes badly wrong. */OGRErr OGRSpatialReference::morphFromESRI(){    OGRErr      eErr = OGRERR_NONE;    if( GetRoot() == NULL )        return OGRERR_NONE;/* -------------------------------------------------------------------- *//*      Translate DATUM keywords that are oddly named.                  *//* -------------------------------------------------------------------- */    InitDatumMappingTable();    GetRoot()->applyRemapper( "DATUM",                               papszDatumMapping+1, papszDatumMapping+2, 3 );/* -------------------------------------------------------------------- *//*      Try to remove any D_ in front of the datum name.                *//* -------------------------------------------------------------------- */    OGR_SRSNode *poDatum;    poDatum = GetAttrNode( "DATUM" );    if( poDatum != NULL )        poDatum = poDatum->GetChild(0);    if( poDatum != NULL )    {        if( EQUALN(poDatum->GetValue(),"D_",2) )        {            char *pszNewValue = CPLStrdup( poDatum->GetValue() + 2 );            poDatum->SetValue( pszNewValue );            CPLFree( pszNewValue );        }    }/* -------------------------------------------------------------------- *//*      Split Lambert_Conformal_Conic into 1SP or 2SP form.             *//*                                                                      *//*      See bugzilla.remotesensing.org/show_bug.cgi?id=187              *//* -------------------------------------------------------------------- */    const char *pszProjection = GetAttrValue("PROJECTION");        if( pszProjection != NULL        && EQUAL(pszProjection,"Lambert_Conformal_Conic") )    {        if( GetProjParm( "Scale_Factor", 2.0 ) == 2.0 )            SetNode( "PROJCS|PROJECTION",                      SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP );        else            SetNode( "PROJCS|PROJECTION",                      SRS_PT_LAMBERT_CONFORMAL_CONIC_1SP );    }/* -------------------------------------------------------------------- *//*      If we are remapping Hotine_Oblique_Mercator_Azimuth_Center      *//*      add a rectified_grid_angle parameter - to match the azimuth     *//*      I guess.                                                        *//* -------------------------------------------------------------------- */    if( pszProjection != NULL        && EQUAL(pszProjection,"Hotine_Oblique_Mercator_Azimuth_Center") )    {        SetProjParm( SRS_PP_RECTIFIED_GRID_ANGLE ,                      GetProjParm( SRS_PP_AZIMUTH, 0.0 ) );        FixupOrdering();    }/* -------------------------------------------------------------------- *//*      Remap Albers, Mercator and Polar Stereographic parameters.      *//* -------------------------------------------------------------------- */    if( pszProjection != NULL && EQUAL(pszProjection,"Albers") )        GetRoot()->applyRemapper(             "PARAMETER", apszAlbersMapping + 0, apszAlbersMapping + 1, 2 );    if( pszProjection != NULL         && EQUAL(pszProjection,SRS_PT_EQUIDISTANT_CONIC) )        GetRoot()->applyRemapper(             "PARAMETER", apszECMapping + 0, apszECMapping + 1, 2 );    if( pszProjection != NULL && EQUAL(pszProjection,"Mercator") )        GetRoot()->applyRemapper(             "PARAMETER", apszMercatorMapping + 0, apszMercatorMapping + 1, 2 );    if( pszProjection != NULL         && EQUALN(pszProjection,"Stereographic_",14)         && EQUALN(pszProjection+strlen(pszProjection)-5,"_Pole",5) )        GetRoot()->applyRemapper(             "PARAMETER",             apszPolarStereographicMapping + 0,             apszPolarStereographicMapping + 1, 2 );/* -------------------------------------------------------------------- *//*      Remap south and north polar stereographic to one value.         *//* -------------------------------------------------------------------- */    if( pszProjection != NULL        && EQUALN(pszProjection,"Stereographic_",14)        && EQUALN(pszProjection+strlen(pszProjection)-5,"_Pole",5) )    {        SetNode( "PROJCS|PROJECTION", SRS_PT_POLAR_STEREOGRAPHIC );        pszProjection = GetAttrValue("PROJECTION");    }/* -------------------------------------------------------------------- *//*      Translate PROJECTION keywords that are misnamed.                *//* -------------------------------------------------------------------- */    GetRoot()->applyRemapper( "PROJECTION",                               apszProjMapping, apszProjMapping+1, 2 );    /* -------------------------------------------------------------------- *//*      Translate DATUM keywords that are misnamed.                     *//* -------------------------------------------------------------------- */    InitDatumMappingTable();    GetRoot()->applyRemapper( "DATUM",                               papszDatumMapping+1, papszDatumMapping+2, 3 );    return eErr;}/************************************************************************//*                          OSRMorphFromESRI()                          *//************************************************************************/OGRErr OSRMorphFromESRI( OGRSpatialReferenceH hSRS ){    return ((OGRSpatialReference *) hSRS)->morphFromESRI();}

⌨️ 快捷键说明

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