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

📄 ntffilereader.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* -------------------------------------------------------------------- *//*      Loop looking for a group we can translate, and that if          *//*      needed matches our layer request.                               *//* -------------------------------------------------------------------- */    while( TRUE )    {        if( GetProductId() == NPC_UNKNOWN && nNTFLevel > 2 )            papoGroup = GetNextIndexedRecordGroup( apoCGroup + 1 );        else            papoGroup = ReadRecordGroup();        if( papoGroup == NULL )            break;                poLayer = apoTypeTranslation[papoGroup[0]->GetType()];        if( poLayer == NULL )            continue;        if( poTargetLayer != NULL && poTargetLayer != poLayer )        {            CacheLineGeometryInGroup( papoGroup );            nSavedFeatureId++;            continue;        }        poFeature = poLayer->FeatureTranslate( this, papoGroup );        if( poFeature == NULL )        {            // should this be a real error?            CPLDebug( "NTF",                      "FeatureTranslate() failed for a type %d record group\n"                      "in a %s type file.\n",                      papoGroup[0]->GetType(),                      GetProduct() );        }        else            break;    }/* -------------------------------------------------------------------- *//*      If we got a feature, set the TILE_REF on it.                    *//* -------------------------------------------------------------------- */    if( poFeature != NULL )    {        int             iTileRefField;        iTileRefField = poLayer->GetLayerDefn()->GetFieldCount()-1;            CPLAssert( EQUAL(poLayer->GetLayerDefn()->GetFieldDefn(iTileRefField)->                         GetNameRef(), "TILE_REF") );        poFeature->SetField( iTileRefField, GetTileName() );        poFeature->SetFID( nSavedFeatureId );        nSavedFeatureId++;    }/* -------------------------------------------------------------------- *//*      If we got to the end we can establish our feature count for     *//*      the file.                                                       *//* -------------------------------------------------------------------- */    else    {        CPLAssert( nFeatureCount == -1                   || nFeatureCount == nSavedFeatureId - nBaseFeatureId );        nFeatureCount = nSavedFeatureId - nBaseFeatureId;    }    return( poFeature );}/************************************************************************//*                            TestForLayer()                            *//*                                                                      *//*      Return indicator of whether this file contains any features     *//*      of the indicated layer type.                                    *//************************************************************************/int NTFFileReader::TestForLayer( OGRNTFLayer * poLayer ){    for( int i = 0; i < 100; i++ )    {        if( apoTypeTranslation[i] == poLayer )            return TRUE;    }    return FALSE;}/************************************************************************//*                            FreshenIndex()                            *//*                                                                      *//*      Rebuild the index if it is needed, and currently missing.       *//************************************************************************/void NTFFileReader::FreshenIndex(){    if( !bIndexBuilt && bIndexNeeded )        IndexFile();}/************************************************************************//*                             IndexFile()                              *//*                                                                      *//*      Read all records beyond the section header and build an         *//*      internal index of them.                                         *//************************************************************************/void NTFFileReader::IndexFile(){    NTFRecord   *poRecord;        Reset();    DestroyIndex();    bIndexNeeded = TRUE;    bIndexBuilt = TRUE;    bCacheLines = FALSE;/* -------------------------------------------------------------------- *//*      Process all records after the section header, and before 99     *//*      to put them in the index.                                       *//* -------------------------------------------------------------------- */    while( (poRecord = ReadRecord()) != NULL && poRecord->GetType() != 99 )    {        int     iType = poRecord->GetType();        int     iId = atoi(poRecord->GetField( 3, 8 ));        if( iType < 0 || iType >= 100 )        {            CPLError( CE_Failure, CPLE_AppDefined,                       "Illegal type %d record, skipping.",                       iType );            delete poRecord;            continue;        }/* -------------------------------------------------------------------- *//*      Grow type specific subindex if needed.                          *//* -------------------------------------------------------------------- */        if( anIndexSize[iType] <= iId )        {            int nNewSize = MAX(iId+1,anIndexSize[iType] * 2 + 10);            apapoRecordIndex[iType] = (NTFRecord **)                CPLRealloc(apapoRecordIndex[iType],                           sizeof(void *) * nNewSize);            for( int i = anIndexSize[iType]; i < nNewSize; i++ )                (apapoRecordIndex[iType])[i] = NULL;            anIndexSize[iType] = nNewSize;        }/* -------------------------------------------------------------------- *//*      Put record into type specific subindex based on it's id as      *//*      the key.                                                        *//* -------------------------------------------------------------------- */        if( apapoRecordIndex[iType][iId] != NULL )        {            CPLDebug( "OGR_NTF",                       "Duplicate record with index %d and type %d\n"                      "in NTFFileReader::IndexFile().",                      iId, iType );            delete apapoRecordIndex[iType][iId];        }        (apapoRecordIndex[iType])[iId] = poRecord;    }    if( poRecord != NULL )        delete poRecord;}/************************************************************************//*                            DestroyIndex()                            *//************************************************************************/void NTFFileReader::DestroyIndex(){    for( int i = 0; i < 100; i++ )    {        for( int iId = 0; iId < anIndexSize[i]; iId++ )        {            if( (apapoRecordIndex[i])[iId] != NULL )                delete (apapoRecordIndex[i])[iId];        }        CPLFree( apapoRecordIndex[i] );        apapoRecordIndex[i] = NULL;        anIndexSize[i] = 0;    }    bIndexBuilt = FALSE;}/************************************************************************//*                          GetIndexedRecord()                          *//************************************************************************/NTFRecord * NTFFileReader::GetIndexedRecord( int iType, int iId ){    if( (iType < 0 || iType > 99)        || (iId < 0 || iId >= anIndexSize[iType])         || (apapoRecordIndex[iType])[iId] == NULL )    {        /* If NRT_GEOMETRY3D is an acceptable alternative to 2D */        if( iType == NRT_GEOMETRY )            return GetIndexedRecord( NRT_GEOMETRY3D, iId );        else            return NULL;    }    return (apapoRecordIndex[iType])[iId];}/************************************************************************//*                          AddToIndexGroup()                           *//************************************************************************/static void AddToIndexGroup( NTFRecord **papoGroup, NTFRecord * poRecord ){    int         i;        for( i = 1; papoGroup[i] != NULL; i++ ) {}    papoGroup[i] = poRecord;    papoGroup[i+1] = NULL;}/************************************************************************//*                     GetNextIndexedRecordGroup()                      *//************************************************************************/NTFRecord **NTFFileReader::GetNextIndexedRecordGroup( NTFRecord **                                                      papoPrevGroup ){    int         nPrevType, nPrevId;/* -------------------------------------------------------------------- *//*      What was the identify of our previous anchor record?            *//* -------------------------------------------------------------------- */    if( papoPrevGroup == NULL || papoPrevGroup[0] == NULL )    {        nPrevType = NRT_POINTREC;        nPrevId = 0;        FreshenIndex();    }    else    {        nPrevType = papoPrevGroup[0]->GetType();        nPrevId = atoi(papoPrevGroup[0]->GetField(3,8));    }/* -------------------------------------------------------------------- *//*      Find the next anchor record.                                    *//* -------------------------------------------------------------------- */    NTFRecord   *poAnchor = NULL;        while( nPrevType != 99 && poAnchor == NULL )    {        nPrevId++;        if( nPrevId >= anIndexSize[nPrevType] )        {            do            {                nPrevType++;            }            while( nPrevType != NRT_VTR                   && nPrevType != NRT_NODEREC                   && nPrevType != NRT_TEXTREC                   && nPrevType != NRT_NAMEREC                   && nPrevType != NRT_COLLECT                   && nPrevType != NRT_POLYGON                   && nPrevType != NRT_CPOLY                   && nPrevType != NRT_POINTREC                   && nPrevType != NRT_LINEREC );                        nPrevId = 0;        }        else        {            poAnchor = (apapoRecordIndex[nPrevType])[nPrevId];        }    }    if( poAnchor == NULL )    {        return NULL;    }/* -------------------------------------------------------------------- *//*      Build record group depending on type of anchor and what it      *//*      refers to.                                                      *//* -------------------------------------------------------------------- */    apoCGroup[0] = NULL;    apoCGroup[1] = poAnchor;    apoCGroup[2] = NULL;/* -------------------------------------------------------------------- *//*      Handle POINTREC/LINEREC                                         *//* -------------------------------------------------------------------- */    if( poAnchor->GetType() == NRT_POINTREC         || poAnchor->GetType() == NRT_LINEREC )    {        int             nAttCount = 0;                AddToIndexGroup( apoCGroup,                         GetIndexedRecord( NRT_GEOMETRY,                                           atoi(poAnchor->GetField(9,14)) ) );        if( poAnchor->GetLength() >= 16 )            nAttCount = atoi(poAnchor->GetField(15,16));        for( int iAtt = 0; iAtt < nAttCount; iAtt++ )        {            AddToIndexGroup(                apoCGroup,                GetIndexedRecord( NRT_ATTREC,                                  atoi(poAnchor->GetField(17+6*iAtt,                                                          22+6*iAtt)) ) );        }    }/* -------------------------------------------------------------------- *//*      Handle TEXTREC                                                  *//* -------------------------------------------------------------------- */    else if( poAnchor->GetType() == NRT_TEXTREC )    {        int             nAttCount = 0;        int             nSelCount = 0;        // Add all the text position records.        nSelCount = atoi(poAnchor->GetField(9,10));                for( int iSel = 0; iSel < nSelCount; iSel++ )        {            int iStart = 11 + 12*iSel + 6;                        AddToIndexGroup(                apoCGroup,                GetIndexedRecord( NRT_TEXTPOS,                                  atoi(poAnchor->GetField(iStart,iStart+5)) ));        }        // Add all geometry and TEXR records pointed to by text position        // records.        for( int iRec = 1; apoCGroup[iRec] != NULL; iRec++ )        {            int         nNumTEXR;            NTFRecord  *poRecord = apoCGroup[iRec];                        if( poRecord->GetType() != NRT_TEXTPOS )

⌨️ 快捷键说明

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