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

📄 ntffilereader.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {        static char      szRealString[30];        const char *pszDecimalPortion;        int       nWidth, nPrecision;        for( pszDecimalPortion = psAttDesc->finter;              *pszDecimalPortion != ',' && *pszDecimalPortion != '\0';             pszDecimalPortion++ ) {}        nWidth = strlen(pszRawValue);        nPrecision = atoi(pszDecimalPortion+1);        strncpy( szRealString, pszRawValue, nWidth - nPrecision );        szRealString[nWidth-nPrecision] = '.';        strcpy( szRealString+nWidth-nPrecision+1,                 pszRawValue+nWidth-nPrecision );                *ppszAttValue = szRealString;    }/* -------------------------------------------------------------------- *//*      If it is an integer, we just reformat to get rid of leading     *//*      zeros.                                                          *//* -------------------------------------------------------------------- */    else if( psAttDesc->finter[0] == 'I' )    {        static char    szIntString[30];        sprintf( szIntString, "%d", atoi(pszRawValue) );        *ppszAttValue = szIntString;    }/* -------------------------------------------------------------------- *//*      Otherwise we take the value directly.                           *//* -------------------------------------------------------------------- */    else    {        *ppszAttValue = (char *) pszRawValue;    }/* -------------------------------------------------------------------- *//*      Handle processing code values into code descriptions, if        *//*      applicable.                                                     *//* -------------------------------------------------------------------- */    if( ppszCodeDesc == NULL )    {    }    else if( psAttDesc->poCodeList != NULL )    {        *ppszCodeDesc = (char *)psAttDesc->poCodeList->Lookup( *ppszAttValue );    }    else    {        *ppszCodeDesc = NULL;    }    return TRUE;}/************************************************************************//*                        ApplyAttributeValues()                        *//*                                                                      *//*      Apply a series of attribute values to a feature from generic    *//*      attribute records.                                              *//************************************************************************/void NTFFileReader::ApplyAttributeValues( OGRFeature * poFeature,                                          NTFRecord ** papoGroup, ... ){    char        **papszTypes = NULL, **papszValues = NULL;/* -------------------------------------------------------------------- *//*      Extract attribute values from record group.                     *//* -------------------------------------------------------------------- */    if( !ProcessAttRecGroup( papoGroup, &papszTypes, &papszValues ) )        return;    /* -------------------------------------------------------------------- *//*      Handle attribute pairs                                          *//* -------------------------------------------------------------------- */    va_list     hVaArgs;    const char  *pszAttName;        va_start(hVaArgs, papoGroup);    while( (pszAttName = va_arg(hVaArgs, const char *)) != NULL )    {        int     iField = va_arg(hVaArgs, int);        ApplyAttributeValue( poFeature, iField, pszAttName,                             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;}/************************************************************************/

⌨️ 快捷键说明

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