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

📄 ogr_srs_esri.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 4 页
字号:
static const char* RemapSpheroidName(const char* pszName){  if (strcmp(pszName, "WGS 84") == 0)    return "WGS 1984";  if (strcmp(pszName, "WGS 72") == 0)    return "WGS 1972";  return pszName;}/************************************************************************//*                           ESRIToUSGSZone()                           *//*                                                                      *//*      Convert ESRI style state plane zones to USGS style state        *//*      plane zones.                                                    *//************************************************************************/static int ESRIToUSGSZone( int nESRIZone ){    int         nPairs = sizeof(anUsgsEsriZones) / (2*sizeof(int));    int         i;        for( i = 0; i < nPairs; i++ )    {        if( anUsgsEsriZones[i*2+1] == nESRIZone )            return anUsgsEsriZones[i*2];    }    return 0;}/************************************************************************//*                          MorphNameToESRI()                           *//*                                                                      *//*      Make name ESRI compatible. Convert spaces and special           *//*      characters to underscores and then strip down.                  *//************************************************************************/static void MorphNameToESRI( char ** ppszName ){    int         i, j;    char        *pszName = *ppszName;/* -------------------------------------------------------------------- *//*      Translate non-alphanumeric values to underscores.               *//* -------------------------------------------------------------------- */    for( i = 0; pszName[i] != '\0'; i++ )    {        if( !(pszName[i] >= 'A' && pszName[i] <= 'Z')            && !(pszName[i] >= 'a' && pszName[i] <= 'z')            && !(pszName[i] >= '0' && pszName[i] <= '9') )        {            pszName[i] = '_';        }    }/* -------------------------------------------------------------------- *//*      Remove repeated and trailing underscores.                       *//* -------------------------------------------------------------------- */    for( i = 1, j = 0; pszName[i] != '\0'; i++ )    {        if( pszName[j] == '_' && pszName[i] == '_' )            continue;        pszName[++j] = pszName[i];    }    if( pszName[j] == '_' )        pszName[j] = '\0';    else        pszName[j+1] = '\0';}/************************************************************************//*                     CleanESRIDatumMappingTable()                     *//************************************************************************/CPL_C_START void CleanupESRIDatumMappingTable(){    if( papszDatumMapping == NULL )        return;    if( papszDatumMapping != apszDefaultDatumMapping )    {        CSLDestroy( papszDatumMapping );        papszDatumMapping = NULL;    }}CPL_C_END/************************************************************************//*                       InitDatumMappingTable()                        *//************************************************************************/static void InitDatumMappingTable(){    if( papszDatumMapping != NULL )        return;/* -------------------------------------------------------------------- *//*      Try to open the datum.csv file.                                 *//* -------------------------------------------------------------------- */    const char  *pszFilename = CSVFilename("gdal_datum.csv");    FILE * fp = VSIFOpen( pszFilename, "rb" );/* -------------------------------------------------------------------- *//*      Use simple default set if we can't find the file.               *//* -------------------------------------------------------------------- */    if( fp == NULL )    {        papszDatumMapping = apszDefaultDatumMapping;        return;    }/* -------------------------------------------------------------------- *//*      Figure out what fields we are interested in.                    *//* -------------------------------------------------------------------- */    char **papszFieldNames = CSVReadParseLine( fp );    int  nDatumCodeField = CSLFindString( papszFieldNames, "DATUM_CODE" );    int  nEPSGNameField = CSLFindString( papszFieldNames, "DATUM_NAME" );    int  nESRINameField = CSLFindString( papszFieldNames, "ESRI_DATUM_NAME" );    CSLDestroy( papszFieldNames );    if( nDatumCodeField == -1 || nEPSGNameField == -1 || nESRINameField == -1 )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "Failed to find required field in gdal_datum.csv in InitDatumMappingTable(), using default table setup." );                papszDatumMapping = apszDefaultDatumMapping;        return;    }    /* -------------------------------------------------------------------- *//*      Read each line, adding a detail line for each.                  *//* -------------------------------------------------------------------- */    int nMappingCount = 0;    const int nMaxDatumMappings = 1000;    char **papszFields;    papszDatumMapping = (char **)CPLCalloc(sizeof(char*),nMaxDatumMappings*3);    for( papszFields = CSVReadParseLine( fp );         papszFields != NULL;         papszFields = CSVReadParseLine( fp ) )    {        int nFieldCount = CSLCount(papszFields);        CPLAssert( nMappingCount+1 < nMaxDatumMappings );        if( MAX(nEPSGNameField,MAX(nDatumCodeField,nESRINameField))             < nFieldCount             && nMaxDatumMappings > nMappingCount+1 )        {            papszDatumMapping[nMappingCount*3+0] =                 CPLStrdup( papszFields[nDatumCodeField] );            papszDatumMapping[nMappingCount*3+1] =                 CPLStrdup( papszFields[nESRINameField] );            papszDatumMapping[nMappingCount*3+2] =                 CPLStrdup( papszFields[nEPSGNameField] );            OGREPSGDatumNameMassage( &(papszDatumMapping[nMappingCount*3+2]) );            nMappingCount++;        }        CSLDestroy( papszFields );    }    VSIFClose( fp );    papszDatumMapping[nMappingCount*3+0] = NULL;    papszDatumMapping[nMappingCount*3+1] = NULL;    papszDatumMapping[nMappingCount*3+2] = NULL;}/************************************************************************//*                         OSRImportFromESRI()                          *//************************************************************************/OGRErr OSRImportFromESRI( OGRSpatialReferenceH hSRS, char **papszPrj ){    return ((OGRSpatialReference *) hSRS)->importFromESRI( papszPrj );}/************************************************************************//*                              OSR_GDV()                               *//*                                                                      *//*      Fetch a particular parameter out of the parameter list, or      *//*      the indicated default if it isn't available.  This is a         *//*      helper function for importFromESRI().                           *//************************************************************************/static double OSR_GDV( char **papszNV, const char * pszField,                        double dfDefaultValue ){    int         iLine;    if( papszNV == NULL || papszNV[0] == NULL )        return dfDefaultValue;    if( EQUALN(pszField,"PARAM_",6) )    {        int     nOffset;        for( iLine = 0;              papszNV[iLine] != NULL && !EQUALN(papszNV[iLine],"Paramet",7);             iLine++ ) {}        for( nOffset=atoi(pszField+6);              papszNV[iLine] != NULL && nOffset > 0;              iLine++ )         {            if( strlen(papszNV[iLine]) > 0 )                nOffset--;        }                while( papszNV[iLine] != NULL && strlen(papszNV[iLine]) == 0 )             iLine++;        if( papszNV[iLine] != NULL )        {            char        **papszTokens, *pszLine = papszNV[iLine];            double      dfValue;                        int         i;                        // Trim comments.            for( i=0; pszLine[i] != '\0'; i++ )            {                if( pszLine[i] == '/' && pszLine[i+1] == '*' )                    pszLine[i] = '\0';            }            papszTokens = CSLTokenizeString(papszNV[iLine]);            if( CSLCount(papszTokens) == 3 )            {                dfValue = ABS(atof(papszTokens[0]))                    + atof(papszTokens[1]) / 60.0                    + atof(papszTokens[2]) / 3600.0;                if( atof(papszTokens[0]) < 0.0 )                    dfValue *= -1;            }            else if( CSLCount(papszTokens) > 0 )                dfValue = atof(papszTokens[0]);            else                dfValue = dfDefaultValue;            CSLDestroy( papszTokens );            return dfValue;        }        else            return dfDefaultValue;    }    else    {        for( iLine = 0;              papszNV[iLine] != NULL &&                  !EQUALN(papszNV[iLine],pszField,strlen(pszField));             iLine++ ) {}        if( papszNV[iLine] == NULL )            return dfDefaultValue;        else            return atof( papszNV[iLine] + strlen(pszField) );    }}/************************************************************************//*                              OSR_GDS()                               *//************************************************************************/static const char*OSR_GDS( char **papszNV, const char * pszField,                            const char *pszDefaultValue ){    int         iLine;    if( papszNV == NULL || papszNV[0] == NULL )        return pszDefaultValue;    for( iLine = 0;          papszNV[iLine] != NULL &&              !EQUALN(papszNV[iLine],pszField,strlen(pszField));         iLine++ ) {}    if( papszNV[iLine] == NULL )        return pszDefaultValue;    else    {        static char     szResult[80];        char    **papszTokens;                papszTokens = CSLTokenizeString(papszNV[iLine]);        if( CSLCount(papszTokens) > 1 )            strncpy( szResult, papszTokens[1], sizeof(szResult));        else            strncpy( szResult, pszDefaultValue, sizeof(szResult));                CSLDestroy( papszTokens );        return szResult;    }}/************************************************************************//*                          importFromESRI()                            *//************************************************************************//** * Import coordinate system from ESRI .prj format(s). * * This function will read the text loaded from an ESRI .prj file, and * translate it into an OGRSpatialReference definition.  This should support * many (but by no means all) old style (Arc/Info 7.x) .prj files, as well * as the newer pseudo-OGC WKT .prj files.  Note that new style .prj files * are in OGC WKT format, but require some manipulation to correct datum * names, and units on some projection parameters.  This is addressed within * importFromESRI() by an automatical call to morphFromESRI().  * * Currently only GEOGRAPHIC, UTM, STATEPLANE, GREATBRITIAN_GRID, ALBERS,  * EQUIDISTANT_CONIC, and TRANSVERSE (mercator) projections are supported * from old style files.  * * At this time there is no equivelent exportToESRI() method.  Writing old * style .prj files is not supported by OGRSpatialReference. However the * morphToESRI() and exportToWkt() methods can be used to generate output * suitable to write to new style (Arc 8) .prj files.  * * This function is the equilvelent of the C function OSRImportFromESRI(). * * @param papszPrj NULL terminated list of strings containing the definition. * * @return OGRERR_NONE on success or an error code in case of failure.  */OGRErr OGRSpatialReference::importFromESRI( char **papszPrj ){    if( papszPrj == NULL || papszPrj[0] == NULL )        return OGRERR_CORRUPT_DATA;

⌨️ 快捷键说明

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