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

📄 ogrfeature.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        if( poFDefn->GetType() == OFTInteger )        return pauFields[iField].Integer;    else if( poFDefn->GetType() == OFTReal )        return (int) pauFields[iField].Real;    else if( poFDefn->GetType() == OFTString )    {        if( pauFields[iField].String == NULL )            return 0;        else            return atoi(pauFields[iField].String);    }    else        return 0;}/************************************************************************//*                      OGR_F_GetFieldAsInteger()                       *//************************************************************************//** * Fetch field value as integer. * * OFTString features will be translated using atoi().  OFTReal fields * will be cast to integer.   Other field types, or errors will result in * a return value of zero. * * This function is the same as the CPP method OGRFeature::GetFieldAsInteger(). * * @param hFeat handle to the feature that owned the field. * @param iField the field to fetch, from 0 to GetFieldCount()-1. * * @return the field value. */int OGR_F_GetFieldAsInteger( OGRFeatureH hFeat, int iField ){    return ((OGRFeature *)hFeat)->GetFieldAsInteger(iField);}/************************************************************************//*                          GetFieldAsDouble()                          *//************************************************************************//** * Fetch field value as a double. * * OFTString features will be translated using atof().  OFTInteger fields * will be cast to double.   Other field types, or errors will result in * a return value of zero. * * This method is the same as the C function OGR_F_GetFieldAsDouble(). * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * * @return the field value. */double OGRFeature::GetFieldAsDouble( int iField ){    OGRFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );        CPLAssert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return 0.0;    if( !IsFieldSet(iField) )        return 0.0;        if( poFDefn->GetType() == OFTReal )        return pauFields[iField].Real;    else if( poFDefn->GetType() == OFTInteger )        return pauFields[iField].Integer;    else if( poFDefn->GetType() == OFTString )    {        if( pauFields[iField].String == NULL )            return 0;        else            return atof(pauFields[iField].String);    }    else        return 0.0;}/************************************************************************//*                       OGR_F_GetFieldAsDouble()                       *//************************************************************************//** * Fetch field value as a double. * * OFTString features will be translated using atof().  OFTInteger fields * will be cast to double.   Other field types, or errors will result in * a return value of zero. * * This function is the same as the CPP method OGRFeature::GetFieldAsDouble(). * * @param hFeat handle to the feature that owned the field. * @param iField the field to fetch, from 0 to GetFieldCount()-1. * * @return the field value. */double OGR_F_GetFieldAsDouble( OGRFeatureH hFeat, int iField ){    return ((OGRFeature *)hFeat)->GetFieldAsDouble(iField);}/************************************************************************//*                          GetFieldAsString()                          *//************************************************************************//** * Fetch field value as a string. * * OFTReal and OFTInteger fields will be translated to string using * sprintf(), but not necessarily using the established formatting rules. * Other field types, or errors will result in a return value of zero. * * This method is the same as the C function OGR_F_GetFieldAsString(). * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * * @return the field value.  This string is internal, and should not be * modified, or freed.  It's lifetime may be very brief.  */const char *OGRFeature::GetFieldAsString( int iField ){    OGRFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    static char         szTempBuffer[80];    CPLAssert( poFDefn != NULL || iField == -1 );    if( poFDefn == NULL )        return "";        if( !IsFieldSet(iField) )        return "";        if( poFDefn->GetType() == OFTString )    {        if( pauFields[iField].String == NULL )            return "";        else            return pauFields[iField].String;    }    else if( poFDefn->GetType() == OFTInteger )    {        sprintf( szTempBuffer, "%d", pauFields[iField].Integer );        return szTempBuffer;    }    else if( poFDefn->GetType() == OFTReal )    {        char    szFormat[64];        if( poFDefn->GetWidth() != 0 )        {            sprintf( szFormat, "%%%d.%df",                     poFDefn->GetWidth(), poFDefn->GetPrecision() );        }        else            strcpy( szFormat, "%.16g" );                sprintf( szTempBuffer, szFormat, pauFields[iField].Real );                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 "";}/************************************************************************//*                       OGR_F_GetFieldAsString()                       *//************************************************************************//** * Fetch field value as a string. * * OFTReal and OFTInteger fields will be translated to string using * sprintf(), but not necessarily using the established formatting rules. * Other field types, or errors will result in a return value of zero. * * This function is the same as the CPP method OGRFeature::GetFieldAsString(). * * @param hFeat handle to the feature that owned the field. * @param iField the field to fetch, from 0 to GetFieldCount()-1. * * @return the field value.  This string is internal, and should not be * modified, or freed.  It's lifetime may be very brief.  */const char *OGR_F_GetFieldAsString( OGRFeatureH hFeat, int iField ){    return ((OGRFeature *)hFeat)->GetFieldAsString(iField);}/************************************************************************//*                       GetFieldAsIntegerList()                        *//************************************************************************//** * Fetch field value as a list of integers. * * Currently this method only works for OFTIntegerList fields. * * This method is the same as the C function OGR_F_GetFieldAsIntegerList(). * * @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 *OGRFeature::GetFieldAsIntegerList( int iField, int *pnCount ){    OGRFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    CPLAssert( 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;    }}/************************************************************************//*                    OGR_F_GetFieldAsIntegerList()                     *//************************************************************************//** * Fetch field value as a list of integers. * * Currently this function only works for OFTIntegerList fields. * * This function is the same as the CPP method  * OGRFeature::GetFieldAsIntegerList(). * * @param hFeat handle to the feature that owned the field. * @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 *OGR_F_GetFieldAsIntegerList( OGRFeatureH hFeat, int iField,                                   int *pnCount ){    return ((OGRFeature *)hFeat)->GetFieldAsIntegerList(iField, pnCount);}/************************************************************************//*                        GetFieldAsDoubleList()                        *//************************************************************************//** * Fetch field value as a list of doubles. * * Currently this method only works for OFTRealList fields. * * This method is the same as the C function OGR_F_GetFieldAsDoubleList(). * * @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 *OGRFeature::GetFieldAsDoubleList( int iField, int *pnCount ){    OGRFieldDefn        *poFDefn = poDefn->GetFieldDefn( iField );    CPLAssert( 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;    }}/************************************************************************/

⌨️ 快捷键说明

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