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

📄 ogrtigerdatasource.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*                           GetLayerCount()                            *//************************************************************************/int OGRTigerDataSource::GetLayerCount(){    return nLayers;}/************************************************************************//*                                Open()                                *//************************************************************************/int OGRTigerDataSource::Open( const char * pszFilename, int bTestOpen,                              char ** papszLimitedFileList ){    VSIStatBuf      stat;    char            **papszFileList = NULL;    int             i;    pszName = CPLStrdup( pszFilename );/* -------------------------------------------------------------------- *//*      Is the given path a directory or a regular file?                *//* -------------------------------------------------------------------- */    if( CPLStat( pszFilename, &stat ) != 0         || (!VSI_ISDIR(stat.st_mode) && !VSI_ISREG(stat.st_mode)) )    {        if( !bTestOpen )            CPLError( CE_Failure, CPLE_AppDefined,                   "%s is neither a file or directory, Tiger access failed.\n",                      pszFilename );        return FALSE;    }    /* -------------------------------------------------------------------- *//*      Build a list of filenames we figure are Tiger files.            *//* -------------------------------------------------------------------- */    if( VSI_ISREG(stat.st_mode) )    {        char       szModule[128];        pszPath = CPLStrdup( CPLGetPath(pszFilename) );        strncpy( szModule, CPLGetFilename(pszFilename), sizeof(szModule)-1 );        szModule[strlen(szModule)-1] = '\0';        papszFileList = CSLAddString( papszFileList, szModule );    }    else    {        char      **candidateFileList = CPLReadDir( pszFilename );        int         i;        pszPath = CPLStrdup( pszFilename );        for( i = 0;              candidateFileList != NULL && candidateFileList[i] != NULL;              i++ )         {            int nCandidateLen = strlen(candidateFileList[i]);            if( papszLimitedFileList != NULL                 && CSLFindString(papszLimitedFileList,                                 CPLGetBasename(candidateFileList[i])) == -1 )            {                continue;            }            if( nCandidateLen > 4                 && candidateFileList[i][nCandidateLen-4] == '.'                && candidateFileList[i][nCandidateLen-1] == '1')            {                char       szModule[128];                strncpy( szModule, candidateFileList[i],                         strlen(candidateFileList[i])-1 );                szModule[strlen(candidateFileList[i])-1] = '\0';                papszFileList = CSLAddString(papszFileList, szModule);            }        }        CSLDestroy( candidateFileList );        if( CSLCount(papszFileList) == 0 )        {            if( !bTestOpen )                CPLError( CE_Failure, CPLE_OpenFailed,                          "No candidate Tiger files (TGR*.RT1) found in\n"                          "directory: %s",                          pszFilename );            return FALSE;        }    }/* -------------------------------------------------------------------- *//*      Loop over all these files trying to open them.  In testopen     *//*      mode we first read the first 80 characters, to verify that      *//*      it looks like an Tiger file.  Note that we don't keep the file  *//*      open ... we don't want to occupy alot of file handles when      *//*      handling a whole directory.                                     *//* -------------------------------------------------------------------- */    papszModules = NULL;        for( i = 0; papszFileList[i] != NULL; i++ )    {        if( bTestOpen || i == 0 )        {            char        szHeader[500];            FILE        *fp;            char        *pszFilename, *pszRecStart = NULL;            int         bIsGDT = FALSE;            pszFilename = BuildFilename( papszFileList[i], "1" );            fp = VSIFOpen( pszFilename, "rb" );            CPLFree( pszFilename );            if( fp == NULL )                continue;                        if( VSIFRead( szHeader, sizeof(szHeader)-1, 1, fp ) < 1 )            {                VSIFClose( fp );                continue;            }            VSIFClose( fp );            pszRecStart = szHeader;            szHeader[sizeof(szHeader)-1] = '\0';            if( EQUALN(pszRecStart,"Copyright (C)",13)                 && strstr(pszRecStart,"Geographic Data Tech") != NULL )            {                bIsGDT = TRUE;                while( *pszRecStart != '\0'                        && *pszRecStart != 10                        && *pszRecStart != 13 )                    pszRecStart++;                while( *pszRecStart == 10 || *pszRecStart == 13 )                    pszRecStart++;            }                        if( pszRecStart[0] != '1' )                continue;            if( !isdigit(pszRecStart[1]) || !isdigit(pszRecStart[2])                || !isdigit(pszRecStart[3]) || !isdigit(pszRecStart[4]) )                continue;            nVersionCode = atoi(TigerFileBase::GetField( pszRecStart, 2, 5 ));            nVersion = TigerClassifyVersion( nVersionCode );            CPLDebug( "OGR", "Tiger Version Code=%d, Classified as %s ",                       nVersionCode, TigerVersionString(nVersion) );            if(    nVersionCode !=  0                && nVersionCode !=  2                && nVersionCode !=  3                && nVersionCode !=  5                && nVersionCode != 21                 && nVersionCode != 24                && pszRecStart[3]  != '9'                && pszRecStart[3]  != '0'                && !bIsGDT )                continue;            // we could (and should) add a bunch more validation here.        }        papszModules = CSLAddString( papszModules, papszFileList[i] );    }    CSLDestroy( papszFileList );    nModules = CSLCount( papszModules );    if( nModules == 0 )    {        if( !bTestOpen )        {            if( VSI_ISREG(stat.st_mode) )                CPLError( CE_Failure, CPLE_OpenFailed,                          "No TIGER/Line files (TGR*.RT1) found in\n"                          "directory: %s",                          pszFilename );            else                CPLError( CE_Failure, CPLE_OpenFailed,                          "File %s does not appear to be a TIGER/Line .RT1 file.",                          pszFilename );        }        return FALSE;    }/* -------------------------------------------------------------------- *//*      Do we have a user provided version override?                    *//* -------------------------------------------------------------------- */    if( CPLGetConfigOption( "TIGER_VERSION", NULL ) != NULL )    {        const char *pszRequestedVersion =             CPLGetConfigOption( "TIGER_VERSION", NULL );        if( EQUALN(pszRequestedVersion,"TIGER_",6) )        {            int iCode;            for( iCode = 1; iCode < TIGER_Unknown; iCode++ )            {                if( EQUAL(TigerVersionString((TigerVersion)iCode),                          pszRequestedVersion) )                {                    nVersion = (TigerVersion) iCode;                    break;                }            }            if( iCode == TIGER_Unknown )            {                CPLError( CE_Failure, CPLE_AppDefined,                           "Failed to recognise TIGER_VERSION setting: %s",                           pszRequestedVersion );                return FALSE;            }                                      CPLDebug( "OGR", "OVERRIDE Tiger Version %s ",                       TigerVersionString(nVersion) );        }        else        {            nVersionCode = atoi(pszRequestedVersion);            nVersion = TigerClassifyVersion( nVersionCode );            CPLDebug( "OGR",                       "OVERRIDE Tiger Version Code=%d, Classified as %s ",                       nVersionCode, TigerVersionString(nVersion) );        }    }/* -------------------------------------------------------------------- *//*      Create the layers which appear to exist.                        *//* -------------------------------------------------------------------- */    // RT1, RT2, RT3    AddLayer( new OGRTigerLayer( this,                                 new TigerCompleteChain( this,                                                         papszModules[0]) ));    /* should we have kept track of whether we encountered an RT4 file? */    // RT4    AddLayer( new OGRTigerLayer( this,                                 new TigerAltName( this,                                                   papszModules[0]) ));    // RT5    AddLayer( new OGRTigerLayer( this,                                 new TigerFeatureIds( this,                                                      papszModules[0]) ));    // RT6    AddLayer( new OGRTigerLayer( this,                                 new TigerZipCodes( this,                                                    papszModules[0]) ));    // RT7    AddLayer( new OGRTigerLayer( this,                                 new TigerLandmarks( this,                                                     papszModules[0]) ));        // RT8    AddLayer( new OGRTigerLayer( this,                                 new TigerAreaLandmarks( this,                                                     papszModules[0]) ));    // RT9    if (nVersion < TIGER_2002) {      AddLayer( new OGRTigerLayer( this,                                   new TigerKeyFeatures( this,                                                         papszModules[0]) ));    }        // RTA, RTS    AddLayer( new OGRTigerLayer( this,                                 new TigerPolygon( this,                                                   papszModules[0]) ));    // RTB    if (nVersion >= TIGER_2002) {      AddLayer( new OGRTigerLayer( this,                                   new TigerPolygonCorrections( this,                                                                papszModules[0]) ));    }        // RTC    AddLayer( new OGRTigerLayer( this,                                 new TigerEntityNames( this,                                                       papszModules[0]) ));    // RTE    if (nVersion >= TIGER_2002) {      AddLayer( new OGRTigerLayer( this,                                   new TigerPolygonEconomic( this,                                                             papszModules[0]) ));    }    // RTH    AddLayer( new OGRTigerLayer( this,                                 new TigerIDHistory( this,                                                     papszModules[0]) ));        // RTI    AddLayer( new OGRTigerLayer( this,                                 new TigerPolyChainLink( this,                                                       papszModules[0]) ));        // RTP    AddLayer( new OGRTigerLayer( this,                                 new TigerPIP( this,                                               papszModules[0]) ));        // RTR    AddLayer( new OGRTigerLayer( this,                                 new TigerTLIDRange( this,                                                     papszModules[0]) ));        // RTT    if (nVersion >= TIGER_2002) {      AddLayer( new OGRTigerLayer( this,                                   new TigerZeroCellID( this,                                                        papszModules[0]) ));    }    // RTU    if (nVersion >= TIGER_2002) {      AddLayer( new OGRTigerLayer( this,                                   new TigerOverUnder( this,                                                       papszModules[0]) ));

⌨️ 快捷键说明

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