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

📄 ogrntfdatasource.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            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 NTF 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.                                     *//* -------------------------------------------------------------------- */    int         i;    papoNTFFileReader = (NTFFileReader **)        CPLCalloc(sizeof(void*), CSLCount(papszFileList));        for( i = 0; papszFileList[i] != NULL; i++ )    {        if( bTestOpen )        {            char        szHeader[80];            FILE        *fp;            int         j;            fp = VSIFOpen( papszFileList[i], "rb" );            if( fp == NULL )                continue;                        if( VSIFRead( szHeader, 80, 1, fp ) < 1 )            {                VSIFClose( fp );                continue;            }            VSIFClose( fp );                        if( !EQUALN(szHeader,"01",2) )                continue;            for( j = 0; j < 80; j++ )            {                if( szHeader[j] == 10 || szHeader[j] == 13 )                    break;            }            if( j == 80 || szHeader[j-1] != '%' )                continue;        }        NTFFileReader   *poFR;        poFR = new NTFFileReader( this );        if( !poFR->Open( papszFileList[i] ) )        {            delete poFR;            CSLDestroy( papszFileList );                        return FALSE;        }        poFR->SetBaseFID( nNTFFileCount * 1000000 + 1 );        poFR->Close();        EnsureTileNameUnique( poFR );        papoNTFFileReader[nNTFFileCount++] = poFR;    }    CSLDestroy( papszFileList );    if( nNTFFileCount == 0 )        return FALSE;/* -------------------------------------------------------------------- *//*      Establish generic layers.                                       *//* -------------------------------------------------------------------- */    EstablishGenericLayers();    /* -------------------------------------------------------------------- *//*      Loop over all the files, collecting a unique feature class      *//*      listing.                                                        *//* -------------------------------------------------------------------- */    for( int iSrcFile = 0; iSrcFile < nNTFFileCount; iSrcFile++ )    {        NTFFileReader   *poSrcReader = papoNTFFileReader[iSrcFile];                for( int iSrcFC = 0; iSrcFC < poSrcReader->GetFCCount(); iSrcFC++ )        {            int         iDstFC;            char       *pszSrcFCName, *pszSrcFCNum;            poSrcReader->GetFeatureClass( iSrcFC, &pszSrcFCNum, &pszSrcFCName);                        for( iDstFC = 0; iDstFC < nFCCount; iDstFC++ )            {                if( EQUAL(pszSrcFCNum,papszFCNum[iDstFC]) )                    break;            }            if( iDstFC >= nFCCount )            {                nFCCount++;                papszFCNum = CSLAddString(papszFCNum,pszSrcFCNum);                papszFCName = CSLAddString(papszFCName,pszSrcFCName);            }        }    }/* -------------------------------------------------------------------- *//*      Create a new layer specifically for feature classes.            *//* -------------------------------------------------------------------- */    if( nFCCount > 0 )        poFCLayer = new OGRNTFFeatureClassLayer( this );    else        poFCLayer = NULL;        return TRUE;}/************************************************************************//*                            ResetReading()                            *//*                                                                      *//*      Cleanup, and start over.                                        *//************************************************************************/void OGRNTFDataSource::ResetReading(){    for( int i = 0; i < nNTFFileCount; i++ )        papoNTFFileReader[i]->Close();    iCurrentReader = -1;    nCurrentPos = -1;    nCurrentFID = 1;    iCurrentFC = 0;}/************************************************************************//*                           GetNextFeature()                           *//************************************************************************/OGRFeature *OGRNTFDataSource::GetNextFeature(){    OGRFeature  *poFeature = NULL;/* -------------------------------------------------------------------- *//*      If we have already read all the conventional features, we       *//*      should try and return feature class features.                   */    /* -------------------------------------------------------------------- */    if( iCurrentReader == nNTFFileCount )    {        if( iCurrentFC < nFCCount )            return poFCLayer->GetFeature( iCurrentFC++ );        else            return NULL;    }/* -------------------------------------------------------------------- *//*      Do we need to open a file?                                      *//* -------------------------------------------------------------------- */    if( iCurrentReader == -1 )    {        iCurrentReader++;        nCurrentPos = -1;    }    if( papoNTFFileReader[iCurrentReader]->GetFP() == NULL )    {        papoNTFFileReader[iCurrentReader]->Open();    }/* -------------------------------------------------------------------- *//*      Ensure we are reading on from the same point we were reading    *//*      from for the last feature, even if some other access            *//*      mechanism has moved the file pointer.                           *//* -------------------------------------------------------------------- */    if( nCurrentPos != -1 )        papoNTFFileReader[iCurrentReader]->SetFPPos( nCurrentPos,                                                     nCurrentFID );        /* -------------------------------------------------------------------- *//*      Read a feature.  If we get NULL the file must be all            *//*      consumed, advance to the next file.                             *//* -------------------------------------------------------------------- */    poFeature = papoNTFFileReader[iCurrentReader]->ReadOGRFeature();    if( poFeature == NULL )    {        papoNTFFileReader[iCurrentReader]->Close();        if( GetOption("CACHING") != NULL            && EQUAL(GetOption("CACHING"),"OFF") )            papoNTFFileReader[iCurrentReader]->DestroyIndex();        iCurrentReader++;        nCurrentPos = -1;        nCurrentFID = 1;        poFeature = GetNextFeature();    }    else    {        papoNTFFileReader[iCurrentReader]->GetFPPos(&nCurrentPos,                                                    &nCurrentFID);    }    return poFeature;}/************************************************************************//*                          GetFeatureClass()                           *//************************************************************************/int OGRNTFDataSource::GetFeatureClass( int iFCIndex,                                       char ** ppszFCId,                                       char ** ppszFCName ){    if( iFCIndex < 0 || iFCIndex >= nFCCount )    {        *ppszFCId = NULL;        *ppszFCName = NULL;        return FALSE;    }    else    {        *ppszFCId = papszFCNum[iFCIndex];        *ppszFCName = papszFCName[iFCIndex];        return TRUE;    }}/************************************************************************//*                             SetOptions()                             *//************************************************************************/void OGRNTFDataSource::SetOptionList( char ** papszNewOptions ){    CSLDestroy( papszOptions );    papszOptions = CSLDuplicate( papszNewOptions );}/************************************************************************//*                             GetOption()                              *//************************************************************************/const char *OGRNTFDataSource::GetOption( const char * pszOption ){    return CSLFetchNameValue( papszOptions, pszOption );}/************************************************************************//*                        EnsureTileNameUnique()                        *//*                                                                      *//*      This method is called with an NTFFileReader to ensure that      *//*      it's tilename is unique relative to all the readers already     *//*      assigned to this data source.  If not, a unique name is         *//*      selected for it and assigned.  This method should not be        *//*      called with readers that are allready attached to the data      *//*      source.                                                         *//************************************************************************/void OGRNTFDataSource::EnsureTileNameUnique( NTFFileReader *poNewReader ){    int       iSequenceNumber = -1;    int       bIsUnique;    char      szCandidateName[11];    szCandidateName[10] = '\0';    do    {        bIsUnique = TRUE;        if( iSequenceNumber++ == -1 )            strncpy( szCandidateName, poNewReader->GetTileName(), 10 );        else            sprintf( szCandidateName, "%010d", iSequenceNumber );        for( int iReader = 0; iReader < nNTFFileCount && bIsUnique; iReader++ )        {            if( strcmp( szCandidateName,                         GetFileReader( iReader )->GetTileName() ) == 0 )                bIsUnique = FALSE;        }    } while( !bIsUnique );    if( iSequenceNumber > 0 )    {        poNewReader->OverrideTileName( szCandidateName );        CPLError( CE_Warning, CPLE_AppDefined,                   "Forcing TILE_REF to `%s' on file %s\n"                  "to avoid conflict with other tiles in this data source.",                  szCandidateName, poNewReader->GetFilename() );    }}

⌨️ 快捷键说明

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