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

📄 tabfeature.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TABFeature.cpp: implementation of the TABFeature class.////////////////////////////////////////////////////////////////////////#include "tabfeature.h"#include "ugk_errhandle.h"#include "ugk_string.h"/********************************************************************** *                   TABFeature::TABFeature() * * Constructor. **********************************************************************/TABFeature::TABFeature(UGKFeatureDefn *poDefnIn):UGKFeature(poDefnIn){	m_nMapInfoType = TAB_GEOM_NONE;	m_bDeletedFlag = FALSE;	SetMBR(0.0, 0.0, 0.0, 0.0);}/********************************************************************** *                   TABFeature::~TABFeature() * * Destructor. **********************************************************************/TABFeature::~TABFeature(){}/********************************************************************** *                     TABFeature::CloneTABFeature() * * Duplicate feature, including stuff specific to each TABFeature type. * * The newly created feature is owned by the caller, and will have it's own * reference to the UGKFeatureDefn. * * It is possible to create the clone with a different UGKFeatureDefn, * in this case, the fields won't be copied of course. * * This method calls the generic TABFeature::CopyTABFeatureBase() and  * then copies any members specific to its own type. **********************************************************************/TABFeature *TABFeature::CloneTABFeature(UGKFeatureDefn *poNewDefn/*=NULL*/){    /*-----------------------------------------------------------------     * Alloc new feature and copy the base stuff     *----------------------------------------------------------------*/    TABFeature *poNew = new TABFeature(poNewDefn ? poNewDefn : GetDefnRef());    CopyTABFeatureBase(poNew);    /*-----------------------------------------------------------------     * And members specific to this class     *----------------------------------------------------------------*/    // Nothing to do for this class    return poNew;}/********************************************************************** *                     TABFeature::CopyTABFeatureBase() *                       拷贝TABFeature成员 * Used by CloneTABFeature() to copy the basic (fields, geometry, etc.) * TABFeature members. * * The newly created feature is owned by the caller, and will have it's own * reference to the UGKFeatureDefn. * * It is possible to create the clone with a different UGKFeatureDefn, * in this case, the fields won't be copied of course. * **********************************************************************/void TABFeature::CopyTABFeatureBase(TABFeature *poDestFeature){    /*-----------------------------------------------------------------     * Copy fields only if UGKFeatureDefn is the same     *----------------------------------------------------------------*/    UGKFeatureDefn *poThisDefnRef = GetDefnRef();    if (poThisDefnRef == poDestFeature->GetDefnRef())    {        for( int i = 0; i < poThisDefnRef->GetFieldCount(); i++ )        {            poDestFeature->SetField( i, GetRawFieldRef( i ) );        }    }    /*-----------------------------------------------------------------     * Copy the geometry     *----------------------------------------------------------------*/    poDestFeature->SetGeometry( GetGeometryRef() );    double dXMin, dYMin, dXMax, dYMax;    GetMBR(dXMin, dYMin, dXMax, dYMax);    poDestFeature->SetMBR(dXMin, dYMin, dXMax, dYMax);    // m_nMapInfoType is not carried but it is not required anyways.    // it will default to TAB_GEOM_NONE}/********************************************************************** *                   TABFeature::SetMBR() * * Set the values for the MBR corners for this feature. **********************************************************************/void TABFeature::SetMBR(double dXMin, double dYMin,                         double dXMax, double dYMax){    m_dXMin = MIN(dXMin, dXMax);    m_dYMin = MIN(dYMin, dYMax);    m_dXMax = MAX(dXMin, dXMax);    m_dYMax = MAX(dYMin, dYMax);}/********************************************************************** *                   TABFeature::GetMBR() * * Return the values for the MBR corners for this feature. **********************************************************************/void TABFeature::GetMBR(double &dXMin, double &dYMin,                         double &dXMax, double &dYMax){    dXMin = m_dXMin;    dYMin = m_dYMin;    dXMax = m_dXMax;    dYMax = m_dYMax;}/********************************************************************** *                   TABFeature::ReadRecordFromDATFile() *                   从DAT文件中读取与该Feature相关的记录 * Fill the fields part of the feature from the contents of the  * table record pointed to by poDATFile. * * It is assumed that poDATFile currently points to the beginning of * the table record and that this feature's UGKFeatureDefn has been  * properly initialized for this table. **********************************************************************/int TABFeature::ReadRecordFromDATFile(TABDATFile *poDATFile){    int         iField, numFields, nValue;    double      dValue;    const char *pszValue;    assert(poDATFile);    numFields = poDATFile->GetNumFields(); //取得字段数目    for(iField=0; iField<numFields; iField++)    {        switch(poDATFile->GetFieldType(iField))//获取字段的类型        {          case TABFChar:            pszValue = poDATFile->ReadCharField(poDATFile->                                                GetFieldWidth(iField));            SetField(iField, pszValue);            break;          case TABFDecimal:            dValue = poDATFile->ReadDecimalField(poDATFile->                                                 GetFieldWidth(iField));            SetField(iField, dValue);            break;          case TABFInteger:            nValue = poDATFile->ReadIntegerField(poDATFile->                                                 GetFieldWidth(iField));            SetField(iField, nValue);            break;          case TABFSmallInt:            nValue = poDATFile->ReadSmallIntField(poDATFile->                                                 GetFieldWidth(iField));            SetField(iField, nValue);            break;          case TABFFloat:            dValue = poDATFile->ReadFloatField(poDATFile->                                                 GetFieldWidth(iField));            SetField(iField, dValue);            break;          case TABFLogical:            pszValue = poDATFile->ReadLogicalField(poDATFile->                                                 GetFieldWidth(iField));            SetField(iField, pszValue);            break;          case TABFDate:            pszValue = poDATFile->ReadDateField(poDATFile->                                                 GetFieldWidth(iField));            SetField(iField, pszValue);            break;          default:            // Other type???  Impossible!            UGKError(ET_Failure, UGKErr_AssertionFailed,                     "Unsupported field type!");        }    }    return 0;}/********************************************************************** *                   TABFeature::WriteRecordToDATFile() * * Write the attribute part of the feature to the .DAT file. * * It is assumed that poDATFile currently points to the beginning of * the table record and that this feature's UGKFeatureDefn has been  * properly initialized for this table. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFeature::WriteRecordToDATFile(TABDATFile *poDATFile,                                     TABINDFile *poINDFile, int *panIndexNo){    int         iField, numFields, nStatus=0;    assert(poDATFile);    assert(panIndexNo || GetDefnRef()->GetFieldCount() == 0);    numFields = poDATFile->GetNumFields();    for(iField=0; nStatus == 0 && iField<numFields; iField++)    {        // Hack for "extra" introduced field.        if( iField >= GetDefnRef()->GetFieldCount() )        {            assert( poDATFile->GetFieldType(iField) == TABFInteger                        && iField == 0 );            nStatus = poDATFile->WriteIntegerField( GetFID(), poINDFile, 0 );            continue;        }        switch(poDATFile->GetFieldType(iField))        {          case TABFChar:            nStatus = poDATFile->WriteCharField(GetFieldAsString(iField),                                      poDATFile->GetFieldWidth(iField),                                                poINDFile, panIndexNo[iField]);            break;          case TABFDecimal:            nStatus = poDATFile->WriteDecimalField(GetFieldAsDouble(iField),                                      poDATFile->GetFieldWidth(iField),                                      poDATFile->GetFieldPrecision(iField),                                             poINDFile, panIndexNo[iField]);            break;          case TABFInteger:            nStatus = poDATFile->WriteIntegerField(GetFieldAsInteger(iField),                                                poINDFile, panIndexNo[iField]);            break;          case TABFSmallInt:            nStatus = poDATFile->WriteSmallIntField(GetFieldAsInteger(iField),                                                poINDFile, panIndexNo[iField]);            break;          case TABFFloat:            nStatus = poDATFile->WriteFloatField(GetFieldAsDouble(iField),                                                poINDFile, panIndexNo[iField]);            break;          case TABFLogical:            nStatus = poDATFile->WriteLogicalField(GetFieldAsString(iField),                                                poINDFile, panIndexNo[iField]);            break;          case TABFDate:            nStatus = poDATFile->WriteDateField(GetFieldAsString(iField),                                                poINDFile, panIndexNo[iField]);            break;          default:            // Other type???  Impossible!            UGKError(ET_Failure, UGKErr_AssertionFailed,                    "Unsupported field type!");        }    }    if (poDATFile->CommitRecordToFile() != 0)        return -1;    return 0;}/********************************************************************** *                   TABFeature::ReadGeometryFromMAPFile() *

⌨️ 快捷键说明

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