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

📄 tabcustompoint.cpp

📁 linux下一款GIS程序源码
💻 CPP
字号:
// tabcustompoint.cpp: implementation of the TABCustomPoint class.////////////////////////////////////////////////////////////////////////#include "tabcustompoint.h"#include "ugk_errhandle.h"#include "ugk_string.h"#include "ugkpoint.h"#include "tabmapobjcustompoint.h"/********************************************************************** *                   TABCustomPoint::TABCustomPoint() * * Constructor. **********************************************************************/TABCustomPoint::TABCustomPoint(UGKFeatureDefn *poDefnIn):                       TABPoint(poDefnIn){	m_nUnknown_ = m_nCustomStyle = 0;}/********************************************************************** *                   TABCustomPoint::~TABCustomPoint() * * Destructor. **********************************************************************/TABCustomPoint::~TABCustomPoint(){}/********************************************************************** *                     TABCustomPoint::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 *TABCustomPoint::CloneTABFeature(UGKFeatureDefn *poNewDefn/*=NULL*/){    /*-----------------------------------------------------------------     * Alloc new feature and copy the base stuff     *----------------------------------------------------------------*/    TABCustomPoint *poNew = new TABCustomPoint(poNewDefn ? poNewDefn :                                                            GetDefnRef());    CopyTABFeatureBase(poNew);    /*-----------------------------------------------------------------     * And members specific to this class     *----------------------------------------------------------------*/    // ITABFeatureSymbol    *(poNew->GetSymbolDefRef()) = *GetSymbolDefRef();    // ITABFeatureFont    *(poNew->GetFontDefRef()) = *GetFontDefRef();    poNew->SetCustomSymbolStyle( GetCustomSymbolStyle() );    return poNew;}/********************************************************************** *                   TABCustomPoint::ReadGeometryFromMAPFile() * * 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 poMAPFile currently points to the beginning of * a map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABCustomPoint::ReadGeometryFromMAPFile(TABMAPFile *poMapFile,                                            TABMAPObjHdr *poObjHdr){    UGKInt32              nX, nY;    double              dX, dY;    UGKGeometry         *poGeometry;    TABMAPObjectBlock   *poObjBlock;    UGKBool               bComprCoord;    /*-----------------------------------------------------------------     * Fetch and validate geometry type     *----------------------------------------------------------------*/    m_nMapInfoType = poMapFile->GetCurObjType();    poObjBlock = poMapFile->GetCurObjBlock();    bComprCoord = (m_nMapInfoType == TAB_GEOM_CUSTOMSYMBOL_C);    /*-----------------------------------------------------------------     * Read object information     *----------------------------------------------------------------*/    if (m_nMapInfoType == TAB_GEOM_CUSTOMSYMBOL ||        m_nMapInfoType == TAB_GEOM_CUSTOMSYMBOL_C )    {        m_nUnknown_    = poObjBlock->ReadByte();  // ???         m_nCustomStyle = poObjBlock->ReadByte();  // 0x01=Show BG,                                                  // 0x02=Apply Color        poObjBlock->ReadIntCoord(bComprCoord, nX, nY);        m_nSymbolDefIndex = poObjBlock->ReadByte();   // Symbol index        poMapFile->ReadSymbolDef(m_nSymbolDefIndex, &m_sSymbolDef);        m_nFontDefIndex = poObjBlock->ReadByte();    // Font index        poMapFile->ReadFontDef(m_nFontDefIndex, &m_sFontDef);    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,           "ReadGeometryFromMAPFile(): unsupported geometry type %d (0x%2.2x)",                 m_nMapInfoType, m_nMapInfoType);        return -1;    }    /*-----------------------------------------------------------------     * Create and fill geometry object     *----------------------------------------------------------------*/    poMapFile->Int2Coordsys(nX, nY, dX, dY);    poGeometry = new UGKPoint(dX, dY);        SetGeometryDirectly(poGeometry);    SetMBR(dX, dY, dX, dY);    return 0;}/********************************************************************** *                   TABCustomPoint::WriteGeometryToMAPFile() * * Write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that poMAPFile currently points to a valid map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABCustomPoint::WriteGeometryToMAPFile(TABMAPFile *poMapFile,                                       TABMAPObjHdr *poObjHdr){    UGKInt32              nX, nY;    UGKGeometry         *poGeom;    UGKPoint            *poPoint;    /*-----------------------------------------------------------------     * We assume that ValidateMapInfoType() was called already and that     * the type in poObjHdr->m_nType is valid.     *----------------------------------------------------------------*/    assert(m_nMapInfoType == poObjHdr->m_nType);    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint)        poPoint = (UGKPoint*)poGeom;    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                 "TABCustomPoint: Missing or Invalid Geometry!");        return -1;    }    poMapFile->Coordsys2Int(poPoint->getX(), poPoint->getY(), nX, nY);    /*-----------------------------------------------------------------     * Copy object information     *----------------------------------------------------------------*/    TABMAPObjCustomPoint *poPointHdr = (TABMAPObjCustomPoint *)poObjHdr;    poPointHdr->m_nX = nX;    poPointHdr->m_nY = nY;    poPointHdr->SetMBR(nX, nY, nX, nY);    poPointHdr->m_nUnknown_ = m_nUnknown_;    poPointHdr->m_nCustomStyle = m_nCustomStyle;// 0x01=Show BG,                                               // 0x02=Apply Color    m_nSymbolDefIndex = poMapFile->WriteSymbolDef(&m_sSymbolDef);    poPointHdr->m_nSymbolId = m_nSymbolDefIndex;      // Symbol index    m_nFontDefIndex = poMapFile->WriteFontDef(&m_sFontDef);    poPointHdr->m_nFontId = m_nFontDefIndex;      // Font index    if (UGKGetLastErrorNo() != 0)        return -1;    return 0;}/********************************************************************** *                   TABCustomPoint::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABCustomPoint::GetStyleString(){    if (m_pszStyleString == NULL)    {        m_pszStyleString = UGKStrdup(GetSymbolStyleString());    }    return m_pszStyleString;}/********************************************************************** * **********************************************************************/int TABCustomPoint::ReadGeometryFromMIFFile(MIDDATAFile *fp){       UGKGeometry         *poGeometry;        char               **papszToken;    const char          *pszLine;    double               dfX,dfY;    papszToken = TokenizeString2(fp->GetSavedLine(),                                     " \t", 0x0001);        if (CountOfList(papszToken) !=3)    {        FreeStrList(papszToken);        return -1;    }    dfX = fp->GetXTrans(atof(papszToken[1]));    dfY = fp->GetYTrans(atof(papszToken[2]));    FreeStrList(papszToken);        papszToken = TokenizeStringComplex(fp->GetLastLine()," ,()\t",                                          TRUE,FALSE);    if (CountOfList(papszToken) !=5)    {                FreeStrList(papszToken);        return -1;    }        SetFontName(papszToken[1]);    SetSymbolColor(atoi(papszToken[2]));    SetSymbolSize(atoi(papszToken[3]));    m_nCustomStyle = atoi(papszToken[4]);        FreeStrList(papszToken);        poGeometry = new UGKPoint(dfX, dfY);        SetGeometryDirectly(poGeometry);    SetMBR(dfX, dfY, dfX, dfY);    /* Go to the first line of the next feature */    while (((pszLine = fp->GetLine()) != NULL) &&            fp->IsValidFeature(pszLine) == FALSE)      ;     return 0; }/********************************************************************** * **********************************************************************/int TABCustomPoint::WriteGeometryToMIFFile(MIDDATAFile *fp){     UGKGeometry         *poGeom;    UGKPoint            *poPoint;     /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint)        poPoint = (UGKPoint*)poGeom;    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                 "TABCustomPoint: Missing or Invalid Geometry!");        return -1;    }     fp->WriteLine("Point %.16g %.16g\n",poPoint->getX(),poPoint->getY());    fp->WriteLine("    Symbol (\"%s\",%d,%d,%d)\n",GetFontNameRef(),                  GetSymbolColor(), GetSymbolSize(),m_nCustomStyle);    return 0; }

⌨️ 快捷键说明

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