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

📄 ugkfeature.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        return szTempBuffer;    }    else if( poFDefn->GetType() == OFTIntegerList )    {        char    szItem[32];        int     i, nCount = pauFields[iField].IntegerList.nCount;        sprintf( szTempBuffer, "(%d:", nCount );        for( i = 0; i < nCount; i++ )        {            sprintf( szItem, "%d", pauFields[iField].IntegerList.paList[i] );            if( strlen(szTempBuffer) + strlen(szItem) + 6                > sizeof(szTempBuffer) )            {                break;            }                        if( i > 0 )                strcat( szTempBuffer, "," );                        strcat( szTempBuffer, szItem );        }        if( i < nCount )            strcat( szTempBuffer, ",...)" );        else            strcat( szTempBuffer, ")" );                return szTempBuffer;    }    else if( poFDefn->GetType() == OFTRealList )    {        char    szItem[40];        char    szFormat[64];        int     i, nCount = pauFields[iField].RealList.nCount;        if( poFDefn->GetWidth() != 0 )        {            sprintf( szFormat, "%%%d.%df",                     poFDefn->GetWidth(), poFDefn->GetPrecision() );        }        else            strcpy( szFormat, "%.16g" );                sprintf( szTempBuffer, "(%d:", nCount );        for( i = 0; i < nCount; i++ )        {            sprintf( szItem, szFormat, pauFields[iField].RealList.paList[i] );            if( strlen(szTempBuffer) + strlen(szItem) + 6                > sizeof(szTempBuffer) )            {                break;            }                        if( i > 0 )                strcat( szTempBuffer, "," );                        strcat( szTempBuffer, szItem );        }        if( i < nCount )            strcat( szTempBuffer, ",...)" );        else            strcat( szTempBuffer, ")" );                return szTempBuffer;    }    else if( poFDefn->GetType() == OFTStringList )    {        int     i, nCount = pauFields[iField].StringList.nCount;        sprintf( szTempBuffer, "(%d:", nCount );        for( i = 0; i < nCount; i++ )        {            const char  *pszItem = pauFields[iField].StringList.paList[i];                        if( strlen(szTempBuffer) + strlen(pszItem)  + 6                > sizeof(szTempBuffer) )            {                break;            }            if( i > 0 )                strcat( szTempBuffer, "," );                        strcat( szTempBuffer, pszItem );        }        if( i < nCount )            strcat( szTempBuffer, ",...)" );        else            strcat( szTempBuffer, ")" );                return szTempBuffer;    }    else        return "";}/************************************************************************//*                       GetFieldAsIntegerList()                        *//************************************************************************//** * Fetch field value as a list of integers. * * Currently this method only works for OFTIntegerList fields. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * @param pnCount an integer to put the list count (number of integers) into. * * @return the field value.  This list is internal, and should not be * modified, or freed.  It's lifetime may be very brief.  If *pnCount is zero * on return the returned pointer may be NULL or non-NULL. */const int *UGKFeature::GetFieldAsIntegerList( int iField, int *pnCount ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return NULL;        if( !IsFieldSet(iField) )        return NULL;        if( poFDefn->GetType() == OFTIntegerList )    {        if( pnCount != NULL )            *pnCount = pauFields[iField].IntegerList.nCount;        return pauFields[iField].IntegerList.paList;    }    else    {        if( pnCount != NULL )            *pnCount = 0;                return NULL;    }}/************************************************************************//*                        GetFieldAsDoubleList()                        *//************************************************************************//** * Fetch field value as a list of doubles. * * Currently this method only works for OFTRealList fields. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * @param pnCount an integer to put the list count (number of doubles) into. * * @return the field value.  This list is internal, and should not be * modified, or freed.  It's lifetime may be very brief.  If *pnCount is zero * on return the returned pointer may be NULL or non-NULL. */const double *UGKFeature::GetFieldAsDoubleList( int iField, int *pnCount ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return NULL;        if( !IsFieldSet(iField) )        return NULL;        if( poFDefn->GetType() == OFTRealList )    {        if( pnCount != NULL )            *pnCount = pauFields[iField].RealList.nCount;        return pauFields[iField].RealList.paList;    }    else    {        if( pnCount != NULL )            *pnCount = 0;                return NULL;    }}/************************************************************************//*                        GetFieldAsStringList()                        *//************************************************************************//** * Fetch field value as a list of strings. * * Currently this method only works for OFTStringList fields. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * * @return the field value.  This list is internal, and should not be * modified, or freed.  It's lifetime may be very brief. */char **UGKFeature::GetFieldAsStringList( int iField ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return NULL;        if( !IsFieldSet(iField) )        return NULL;        if( poFDefn->GetType() == OFTStringList )    {        return pauFields[iField].StringList.paList;    }    else    {        return NULL;    }}/************************************************************************//*                              SetField()                              *//************************************************************************//**          * Set field to integer value.  * * OFTInteger and OFTReal fields will be set directly.  OFTString fields * will be assigned a string representation of the value, but not necessarily * taking into account formatting constraints on this field.  Other field * types may be unaffected. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * @param nValue the value to assign. */void UGKFeature::SetField( int iField, int nValue ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return;        if( poFDefn->GetType() == OFTInteger )    {        pauFields[iField].Integer = nValue;        pauFields[iField].Set.nMarker2 = 0;    }    else if( poFDefn->GetType() == OFTReal )    {        pauFields[iField].Real = nValue;    }    else if( poFDefn->GetType() == OFTString )    {        char    szTempBuffer[64];        sprintf( szTempBuffer, "%d", nValue );        if( IsFieldSet( iField) )            UGK_Free( pauFields[iField].String );                pauFields[iField].String = UGKStrdup( szTempBuffer );    }    else        /* do nothing for other field types */;}/************************************************************************//*                              SetField()                              *//************************************************************************//** * Set field to double value.  * * OFTInteger and OFTReal fields will be set directly.  OFTString fields * will be assigned a string representation of the value, but not necessarily * taking into account formatting constraints on this field.  Other field * types may be unaffected. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * @param dfValue the value to assign. */void UGKFeature::SetField( int iField, double dfValue ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return;        if( poFDefn->GetType() == OFTReal )    {        pauFields[iField].Real = dfValue;    }    else if( poFDefn->GetType() == OFTInteger )    {        pauFields[iField].Integer = (int) dfValue;        pauFields[iField].Set.nMarker2 = 0;    }    else if( poFDefn->GetType() == OFTString )    {        char    szTempBuffer[128];        sprintf( szTempBuffer, "%.16g", dfValue );        if( IsFieldSet( iField) )            UGK_Free( pauFields[iField].String );        pauFields[iField].String = UGKStrdup( szTempBuffer );    }    else        /* do nothing for other field types */;}/************************************************************************//*                              SetField()                              *//************************************************************************//** * Set field to string value.  * * OFTInteger fields will be set based on an atoi() conversion of the string. * OFTReal fields will be set based on an atof() conversion of the string. * Other field types may be unaffected. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * @param pszValue the value to assign. */void UGKFeature::SetField( int iField, const char * pszValue ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return;        if( poFDefn->GetType() == OFTString )    {        if( IsFieldSet(iField) )            UGK_Free( pauFields[iField].String );                    pauFields[iField].String = UGKStrdup( pszValue );    }    else if( poFDefn->GetType() == OFTInteger )    {        pauFields[iField].Integer = atoi(pszValue);        pauFields[iField].Set.nMarker2 = UGKUnsetMarker;    }    else if( poFDefn->GetType() == OFTReal )    {        pauFields[iField].Real = atof(pszValue);    }    else        /* do nothing for other field types */;}/************************************************************************//*                              SetField()                              *//************************************************************************//** * Set field to list of integers value.  * * This method currently on has an effect of OFTIntegerList fields. * * @param iField the field to set, from 0 to GetFieldCount()-1. * @param nCount the number of values in the list being assigned. * @param panValues the values to assign. */void UGKFeature::SetField( int iField, int nCount, int *panValues ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return;        if( poFDefn->GetType() == OFTIntegerList )    {        UGKField        uField;        uField.IntegerList.nCount = nCount;        uField.IntegerList.paList = panValues;        SetField( iField, &uField );    }}/************************************************************************//*                              SetField()                              *//************************************************************************//** * Set field to list of doubles value.  * * This method currently on has an effect of OFTRealList fields. * * @param iField the field to set, from 0 to GetFieldCount()-1. * @param nCount the number of values in the list being assigned. * @param padfValues the values to assign. */void UGKFeature::SetField( int iField, int nCount, double * padfValues ){    UGKFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    assert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return;        if( poFDefn->GetType() == OFTRealList )    {        UGKField        uField;                uField.RealList.nCount = nCount;        uField.RealList.paList = padfValues;                SetField( iField, &uField );    }

⌨️ 快捷键说明

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