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

📄 ntffilereader.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                             papszTypes, papszValues );    }/* -------------------------------------------------------------------- *//*      Cleanup.                                                        *//* -------------------------------------------------------------------- */    CSLDestroy( papszTypes );    CSLDestroy( papszValues );}                                          /************************************************************************//*                        ApplyAttributeValue()                         *//*                                                                      *//*      Apply the indicated attribute value to an OGRFeature field      *//*      if it exists in the attribute value list given.                 *//************************************************************************/int NTFFileReader::ApplyAttributeValue( OGRFeature * poFeature, int iField,                                        const char * pszAttName,                                        char ** papszTypes,                                        char ** papszValues ){/* -------------------------------------------------------------------- *//*      Find the requested attribute in the name/value pair             *//*      provided.  If not found that's fine, just return with           *//*      notification.                                                   *//* -------------------------------------------------------------------- */    int         iValue;        iValue = CSLFindString( papszTypes, pszAttName );    if( iValue < 0 )        return FALSE;/* -------------------------------------------------------------------- *//*      Process the attribute value ... this really only has a          *//*      useful effect for real numbers.                                 *//* -------------------------------------------------------------------- */    char        *pszAttLongName, *pszAttValue, *pszCodeDesc;    ProcessAttValue( pszAttName, papszValues[iValue],                     &pszAttLongName, &pszAttValue, &pszCodeDesc );/* -------------------------------------------------------------------- *//*      Apply the value to the field using the simple set string        *//*      method.  Leave it to the OGRFeature::SetField() method to       *//*      take care of translation to other types.                        *//* -------------------------------------------------------------------- */    poFeature->SetField( iField, pszAttValue );/* -------------------------------------------------------------------- *//*      Apply the code description if we found one.                     *//* -------------------------------------------------------------------- */    if( pszCodeDesc != NULL )    {        char    szDescFieldName[256];        sprintf( szDescFieldName, "%s_DESC",                  poFeature->GetDefnRef()->GetFieldDefn(iField)->GetNameRef() );        poFeature->SetField( szDescFieldName, pszCodeDesc );    }    return TRUE;}/************************************************************************//*                             SaveRecord()                             *//************************************************************************/void NTFFileReader::SaveRecord( NTFRecord * poRecord ){    CPLAssert( poSavedRecord == NULL );    poSavedRecord = poRecord;}/************************************************************************//*                             ReadRecord()                             *//************************************************************************/NTFRecord *NTFFileReader::ReadRecord(){    if( poSavedRecord != NULL )    {        NTFRecord       *poReturn;        poReturn = poSavedRecord;        poSavedRecord = NULL;        return poReturn;    }    else    {        NTFRecord       *poRecord;        CPLErrorReset();        if( fp != NULL )            nPreSavedPos = VSIFTell( fp );        poRecord = new NTFRecord( fp );        if( fp != NULL )            nPostSavedPos = VSIFTell( fp );        /* ensure termination if we fail to read a record */        if( CPLGetLastErrorType() == CE_Failure )        {            delete poRecord;            poRecord = NULL;        }        return poRecord;    }}/************************************************************************//*                              GetFPPos()                              *//*                                                                      *//*      Return the current file pointer position.                       *//************************************************************************/void NTFFileReader::GetFPPos( long *pnPos, long *pnFID ){    if( poSavedRecord != NULL )        *pnPos = nPreSavedPos;    else        *pnPos = nPostSavedPos;    if( pnFID != NULL )        *pnFID = nSavedFeatureId;}/************************************************************************//*                              SetFPPos()                              *//************************************************************************/int NTFFileReader::SetFPPos( long nNewPos, long nNewFID ){    if( nNewFID == nSavedFeatureId )        return TRUE;    if( poSavedRecord != NULL )    {        delete poSavedRecord;        poSavedRecord = NULL;    }    if( fp != NULL && VSIFSeek( fp, nNewPos, SEEK_SET ) == 0 )    {        nPreSavedPos = nPostSavedPos = nNewPos;        nSavedFeatureId = nNewFID;        return TRUE;    }    else        return FALSE;}/************************************************************************//*                               Reset()                                *//*                                                                      *//*      Reset reading to the first feature record.                      *//************************************************************************/void NTFFileReader::Reset(){    SetFPPos( nStartPos, nBaseFeatureId );    ClearCGroup();}/************************************************************************//*                            ClearCGroup()                             *//*                                                                      *//*      Clear the currently loaded record group.                        *//************************************************************************/void NTFFileReader::ClearCGroup(){    for( int i = 0; apoCGroup[i] != NULL; i++ )        delete apoCGroup[i];    apoCGroup[0] = NULL;    apoCGroup[1] = NULL;}/************************************************************************//*                      DefaultNTFRecordGrouper()                       *//*                                                                      *//*      Default rules for figuring out if a new candidate record        *//*      belongs to a group of records that together form a feature      *//*      (a record group).                                               *//************************************************************************/int DefaultNTFRecordGrouper( NTFFileReader *, NTFRecord ** papoGroup,                             NTFRecord * poCandidate ){/* -------------------------------------------------------------------- *//*      Is this group going to be a CPOLY set?  We can recognise        *//*      this because we get repeating POLY/CHAIN sets without an        *//*      intermediate attribute record.  This is a rather special case!  *//* -------------------------------------------------------------------- */    if( papoGroup[0] != NULL && papoGroup[1] != NULL        && papoGroup[0]->GetType() == NRT_POLYGON        && papoGroup[1]->GetType() == NRT_CHAIN )    {        // We keep going till we get the seed geometry.        int     iRec, bGotCPOLY=FALSE;        for( iRec = 0; papoGroup[iRec] != NULL; iRec++ )         {            if( papoGroup[iRec]->GetType() == NRT_CPOLY )                bGotCPOLY = TRUE;        }        if( bGotCPOLY             && poCandidate->GetType() != NRT_GEOMETRY            && poCandidate->GetType() != NRT_ATTREC )            return FALSE;        /*         * this logic assumes we always get a point geometry with a CPOLY         * but that isn't always true, for instance with BL2000 data.  The         * preceed check will handle this case.         */        if( papoGroup[iRec-1]->GetType() != NRT_GEOMETRY )            return TRUE;        else            return FALSE;    }    /* -------------------------------------------------------------------- *//*      Is this a "feature" defining record?  If so break out if it     *//*      isn't the first record in the group.                            *//* -------------------------------------------------------------------- */    if( papoGroup[0] != NULL         && (poCandidate->GetType() == NRT_NAMEREC            || poCandidate->GetType() == NRT_NODEREC            || poCandidate->GetType() == NRT_LINEREC            || poCandidate->GetType() == NRT_POINTREC            || poCandidate->GetType() == NRT_POLYGON            || poCandidate->GetType() == NRT_CPOLY            || poCandidate->GetType() == NRT_COLLECT            || poCandidate->GetType() == NRT_TEXTREC            || poCandidate->GetType() == NRT_COMMENT) )    {        return FALSE;    }/* -------------------------------------------------------------------- *//*      Do we already have a record of this type?  If so, it likely     *//*      doesn't belong in the group.  Attribute records do repeat in    *//*      some products.                                                  *//* -------------------------------------------------------------------- */    if (poCandidate->GetType() != NRT_ATTREC )    {        int     iRec;        for( iRec = 0; papoGroup[iRec] != NULL; iRec++ )        {            if( poCandidate->GetType() == papoGroup[iRec]->GetType() )                break;        }                   if( papoGroup[iRec] != NULL )            return FALSE;    }    return TRUE;}/************************************************************************//*                          ReadRecordGroup()                           *//*                                                                      *//*      Read a group of records that form a single feature.             *//************************************************************************/NTFRecord **NTFFileReader::ReadRecordGroup(){   NTFRecord     *poRecord;   int            nRecordCount = 0;   ClearCGroup();   /* -------------------------------------------------------------------- *//*      Loop, reading records till we think we have a grouping.         *//* -------------------------------------------------------------------- */   while( (poRecord = ReadRecord()) != NULL && poRecord->GetType() != NRT_VTR )   {       CPLAssert( nRecordCount < MAX_REC_GROUP);       if( nRecordCount >= MAX_REC_GROUP )       {           CPLError( CE_Failure, CPLE_AppDefined,                      "Maximum record group size (%d) exceeded.\n",                      MAX_REC_GROUP );           break;       }       if( !pfnRecordGrouper( this, apoCGroup, poRecord ) )           break;              apoCGroup[nRecordCount++] = poRecord;       apoCGroup[nRecordCount] = NULL;   }   /* -------------------------------------------------------------------- *//*      Push the last record back on the input queue.                   *//* -------------------------------------------------------------------- */   if( poRecord != NULL )       SaveRecord( poRecord );/* -------------------------------------------------------------------- *//*      Return the list, or NULL if we didn't get any records.          *//* -------------------------------------------------------------------- */   if( nRecordCount == 0 )       return NULL;   else       return apoCGroup;}/************************************************************************//*                          GetFeatureClass()                           *//************************************************************************/int NTFFileReader::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;    }}/************************************************************************//*                           ReadOGRFeature()                           *//************************************************************************/OGRFeature * NTFFileReader::ReadOGRFeature( OGRNTFLayer * poTargetLayer ){    OGRNTFLayer *poLayer = NULL;    NTFRecord   **papoGroup;    OGRFeature  *poFeature = NULL;/* -------------------------------------------------------------------- *//*      If this is a raster file, use a custom method to read the       *//*      feature.                                                        *//* -------------------------------------------------------------------- */    if( IsRasterProduct() )        return poRasterLayer->GetNextFeature();

⌨️ 快捷键说明

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