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

📄 mitab_feature.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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!            CPLError(CE_Failure, CPLE_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 OGRFeatureDefn 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;    CPLAssert(poDATFile);    CPLAssert(panIndexNo || GetDefnRef()->GetFieldCount() == 0);    numFields = poDATFile->GetNumFields();    for(iField=0; nStatus == 0 && iField<numFields; iField++)    {        // Hack for "extra" introduced field.        if( iField >= GetDefnRef()->GetFieldCount() )        {            CPLAssert( 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!            CPLError(CE_Failure, CPLE_AssertionFailed,                     "Unsupported field type!");        }    }    if (poDATFile->CommitRecordToFile() != 0)        return -1;    return 0;}/********************************************************************** *                   TABFeature::ReadGeometryFromMAPFile() * * In derived classes, this method should be reimplemented to * fill the geometry and representation (color, etc...) part of the * feature from the contents of the .MAP object pointed to by poMAPFile. * * It is assumed that before calling ReadGeometryFromMAPFile(), poMAPFile * currently points to the beginning of a map object. * * The current implementation does nothing since instances of TABFeature * objects contain no geometry (i.e. TAB_GEOM_NONE). *  * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::ReadGeometryFromMAPFile(TABMAPFile * /*poMapFile*/,                                        TABMAPObjHdr * /*poObjHdr*/){    /*-----------------------------------------------------------------     * Nothing to do... instances of TABFeature objects contain no geometry.     *----------------------------------------------------------------*/    return 0;}/********************************************************************** *                   TABFeature::ValidateCoordType() * * Checks the feature envelope to establish if the feature should be * written using Compressed coordinates or not and adjust m_nMapInfoType * accordingly. Calling this method also sets (initializes) m_nXMin, m_nYMin,  * m_nXMax, m_nYMax * * This function should be used only by the ValidateMapInfoType()  * implementations. * * Returns TRUE if coord. should be compressed, FALSE otherwise **********************************************************************/GBool TABFeature::ValidateCoordType(TABMAPFile * poMapFile){    GBool bCompr = FALSE;    OGRGeometry *poGeom;    poGeom = GetGeometryRef();    /*-------------------------------------------------------------     * Decide if coordinates should be compressed or not.     *------------------------------------------------------------*/    if (poGeom && poMapFile)    {        OGREnvelope oEnv;        poGeom->getEnvelope(&oEnv);        poMapFile->Coordsys2Int(oEnv.MinX, oEnv.MinY, m_nXMin, m_nYMin);        poMapFile->Coordsys2Int(oEnv.MaxX, oEnv.MaxY, m_nXMax, m_nYMax);        if ((m_nXMax - m_nXMin) < 65536 && (m_nYMax-m_nYMin) < 65536)        {            bCompr = TRUE;        }        m_nComprOrgX = (m_nXMin + m_nXMax) / 2;        m_nComprOrgY = (m_nYMin + m_nYMax) / 2;    }    /*-------------------------------------------------------------     * Adjust native type     *------------------------------------------------------------*/    if (bCompr && ((m_nMapInfoType%3) == 2))        m_nMapInfoType--;  // compr = 1, 4, 7, ...    else if (!bCompr && ((m_nMapInfoType%3) == 1))        m_nMapInfoType++;  // non-compr = 2, 5, 8, ...    return bCompr;}/********************************************************************** *                   TABFeature::ForceCoordTypeAndOrigin() * * This function is used by TABCollection::ValidateMapInfoType() to force  * the coord type and compressed origin of all members of a collection  * to be the same. (A replacement for ValidateCoordType() for this  * specific case) **********************************************************************/void TABFeature::ForceCoordTypeAndOrigin(int nMapInfoType, GBool bCompr,                                         GInt32 nComprOrgX, GInt32 nComprOrgY,                                         GInt32 nXMin, GInt32 nYMin,                                          GInt32 nXMax, GInt32 nYMax){    /*-------------------------------------------------------------     * Set Compressed Origin and adjust native type     *------------------------------------------------------------*/    m_nComprOrgX = nComprOrgX;    m_nComprOrgY = nComprOrgY;    m_nMapInfoType = nMapInfoType;    if (bCompr && ((m_nMapInfoType%3) == 2))        m_nMapInfoType--;  // compr = 1, 4, 7, ...    else if (!bCompr && ((m_nMapInfoType%3) == 1))        m_nMapInfoType++;  // non-compr = 2, 5, 8, ...    m_nXMin = nXMin;    m_nYMin = nYMin;    m_nXMax = nXMax;    m_nYMax = nYMax;}/********************************************************************** *                   TABFeature::WriteGeometryToMAPFile() * * * In derived classes, this method should be reimplemented to * write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that before calling WriteGeometryToMAPFile(), poMAPFile * currently points to a valid map object. * * The current implementation does nothing since instances of TABFeature * objects contain no geometry (i.e. TAB_GEOM_NONE). *  * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::WriteGeometryToMAPFile(TABMAPFile * /* poMapFile*/,                                       TABMAPObjHdr * /*poObjHdr*/){    /*-----------------------------------------------------------------     * Nothing to do... instances of TABFeature objects contain no geometry.     *----------------------------------------------------------------*/    return 0;}/********************************************************************** *                   TABFeature::DumpMID() * * Dump feature attributes in a format similar to .MID data records. **********************************************************************/void TABFeature::DumpMID(FILE *fpOut /*=NULL*/){    OGRFeatureDefn      *poDefn = GetDefnRef();    if (fpOut == NULL)        fpOut = stdout;    for( int iField = 0; iField < GetFieldCount(); iField++ )    {        OGRFieldDefn    *poFDefn = poDefn->GetFieldDefn(iField);                fprintf( fpOut, "  %s (%s) = %s\n",                 poFDefn->GetNameRef(),                 OGRFieldDefn::GetFieldTypeName(poFDefn->GetType()),                 GetFieldAsString( iField ) );    }    fflush(fpOut);}/********************************************************************** *                   TABFeature::DumpMIF() * * Dump feature geometry in a format similar to .MIF files. **********************************************************************/void TABFeature::DumpMIF(FILE *fpOut /*=NULL*/){    if (fpOut == NULL)        fpOut = stdout;    /*-----------------------------------------------------------------     * Generate output... not much to do, feature contains no geometry.     *----------------------------------------------------------------*/    fprintf(fpOut, "NONE\n" );    fflush(fpOut);}/*===================================================================== *                      class TABPoint *====================================================================*//********************************************************************** *                   TABPoint::TABPoint() * * Constructor. **********************************************************************/TABPoint::TABPoint(OGRFeatureDefn *poDefnIn):              TABFeature(poDefnIn){}/********************************************************************** *                   TABPoint::~TABPoint() * * Destructor. **********************************************************************/TABPoint::~TABPoint(){}/********************************************************************** *                     TABPoint::CloneTABFeature() * * Duplicate feature, including stuff specific to each TABFeature type. * * This method calls the generic TABFeature::CloneTABFeature() and  * then copies any members specific to its own type. **********************************************************************/TABFeature *TABPoint::CloneTABFeature(OGRFeatureDefn *poNewDefn /*=NULL*/){    /*-----------------------------------------------------------------     * Alloc new feature and copy the base stuff     *----------------------------------------------------------------*/    TABPoint *poNew = new TABPoint(poNewDefn ? poNewDefn : GetDefnRef());    CopyTABFeatureBase(poNew);    /*-----------------------------------------------------------------     * And members specific to this class

⌨️ 快捷键说明

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