📄 tabpoint.cpp
字号:
// tabpoint.cpp: implementation of the TABPoint class.////////////////////////////////////////////////////////////////////////#include "tabpoint.h"#include "ugk_errhandle.h"#include "ugk_string.h"#include "ugkpoint.h"#include "tabmapobjpoint.h"#include "tabfontpoint.h"#include "tabcustompoint.h"/********************************************************************** * TABPoint::TABPoint() * * Constructor. **********************************************************************/TABPoint::TABPoint(UGKFeatureDefn *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(UGKFeatureDefn *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 *----------------------------------------------------------------*/ // ITABFeatureSymbol *(poNew->GetSymbolDefRef()) = *GetSymbolDefRef(); return poNew;}/********************************************************************** * TABPoint::ValidateMapInfoType() * * Check the feature's geometry part and return the corresponding * mapinfo object type code. The m_nMapInfoType member will also * be updated for further calls to GetMapInfoType(); * * Returns TAB_GEOM_NONE if the geometry is not compatible with what * is expected for this object class. **********************************************************************/int TABPoint::ValidateMapInfoType(TABMAPFile *poMapFile /*=NULL*/){ UGKGeometry *poGeom; /*----------------------------------------------------------------- * Fetch and validate geometry * __TODO__ For now we always write in uncompressed format (until we * find that this is not correct... note that at this point the * decision to use compressed/uncompressed will likely be based on * the distance between the point and the object block center in * integer coordinates being > 32767 or not... remains to be verified) *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { switch(GetFeatureClass()) { case TABFCFontPoint: m_nMapInfoType = TAB_GEOM_FONTSYMBOL; break; case TABFCCustomPoint: m_nMapInfoType = TAB_GEOM_CUSTOMSYMBOL; break; case TABFCPoint: default: m_nMapInfoType = TAB_GEOM_SYMBOL; break; } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPoint: Missing or Invalid Geometry!"); m_nMapInfoType = TAB_GEOM_NONE; } return m_nMapInfoType;}/********************************************************************** * TABPoint::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 TABPoint::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_SYMBOL_C); /*----------------------------------------------------------------- * Read object information *----------------------------------------------------------------*/ if (m_nMapInfoType == TAB_GEOM_SYMBOL || m_nMapInfoType == TAB_GEOM_SYMBOL_C ) { //然后是4/8字节的坐标(具体取决于是否压缩坐标) poObjBlock->ReadIntCoord(bComprCoord, nX, nY); m_nSymbolDefIndex = poObjBlock->ReadByte(); // Symbol index //一个字节的符号索引 poMapFile->ReadSymbolDef(m_nSymbolDefIndex, &m_sSymbolDef); } 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;}/********************************************************************** * TABPoint::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 TABPoint::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, "TABPoint: Missing or Invalid Geometry!"); return -1; } poMapFile->Coordsys2Int(poPoint->getX(), poPoint->getY(), nX, nY); /*----------------------------------------------------------------- * Copy object information *----------------------------------------------------------------*/ TABMAPObjPoint *poPointHdr = (TABMAPObjPoint *)poObjHdr; poPointHdr->m_nX = nX; poPointHdr->m_nY = nY; poPointHdr->SetMBR(nX, nY, nX, nY); m_nSymbolDefIndex = poMapFile->WriteSymbolDef(&m_sSymbolDef); poPointHdr->m_nSymbolId = m_nSymbolDefIndex; // Symbol index if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABPoint::GetX() * * Return this point's X coordinate. **********************************************************************/double TABPoint::GetX(){ UGKGeometry *poGeom; UGKPoint *poPoint=NULL; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) poPoint = (UGKPoint*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPoint: Missing or Invalid Geometry!"); return 0.0; } return poPoint->getX();}/********************************************************************** * TABPoint::GetY() * * Return this point's Y coordinate. **********************************************************************/double TABPoint::GetY(){ UGKGeometry *poGeom; UGKPoint *poPoint=NULL; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) poPoint = (UGKPoint*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPoint: Missing or Invalid Geometry!"); return 0.0; } return poPoint->getY();}/********************************************************************** * TABPoint::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABPoint::GetStyleString(){ if (m_pszStyleString == NULL) { m_pszStyleString = UGKStrdup(GetSymbolStyleString()); } return m_pszStyleString;}/********************************************************************** * TABPoint::DumpMIF() * * Dump feature geometry in a format similar to .MIF POINTs. **********************************************************************/void TABPoint::DumpMIF(FILE *fpOut /*=NULL*/){ UGKGeometry *poGeom; UGKPoint *poPoint; if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) poPoint = (UGKPoint*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPoint: Missing or Invalid Geometry!"); return; } /*----------------------------------------------------------------- * Generate output *----------------------------------------------------------------*/ fprintf(fpOut, "POINT %g %g\n", poPoint->getX(), poPoint->getY() ); DumpSymbolDef(fpOut); /*----------------------------------------------------------------- * Handle stuff specific to derived classes *----------------------------------------------------------------*/ if (GetFeatureClass() == TABFCFontPoint) { TABFontPoint *poFeature = (TABFontPoint *)this; fprintf(fpOut, " m_nFontStyle = 0x%2.2x (%d)\n", poFeature->GetFontStyleTABValue(), poFeature->GetFontStyleTABValue()); poFeature->DumpFontDef(fpOut); } if (GetFeatureClass() == TABFCCustomPoint) { TABCustomPoint *poFeature = (TABCustomPoint *)this; fprintf(fpOut, " m_nUnknown_ = 0x%2.2x (%d)\n", poFeature->m_nUnknown_, poFeature->m_nUnknown_); fprintf(fpOut, " m_nCustomStyle = 0x%2.2x (%d)\n", poFeature->GetCustomSymbolStyle(), poFeature->GetCustomSymbolStyle()); poFeature->DumpFontDef(fpOut); } fflush(fpOut);}/********************************************************************** * **********************************************************************/int TABPoint::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 = NULL; // Read optional SYMBOL line... pszLine = fp->GetLastLine(); papszToken = TokenizeStringComplex(pszLine," ,()\t", TRUE,FALSE); if (CountOfList(papszToken) == 4 && EQUAL(papszToken[0], "SYMBOL") ) { SetSymbolNo(atoi(papszToken[1])); SetSymbolColor(atoi(papszToken[2])); SetSymbolSize(atoi(papszToken[3])); } FreeStrList(papszToken); papszToken = NULL; // scan until we reach 1st line of next feature // Since SYMBOL is optional, we have to test IsValidFeature() on that // line as well. while (pszLine && fp->IsValidFeature(pszLine) == FALSE) { pszLine = fp->GetLine(); } poGeometry = new UGKPoint(dfX, dfY); SetGeometryDirectly(poGeometry); SetMBR(dfX, dfY, dfX, dfY); return 0; }/********************************************************************** * **********************************************************************/int TABPoint::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, "TABPoint: Missing or Invalid Geometry!"); return -1; } fp->WriteLine("Point %.16g %.16g\n",poPoint->getX(),poPoint->getY()); fp->WriteLine(" Symbol (%d,%d,%d)\n",GetSymbolNo(),GetSymbolColor(), GetSymbolSize()); return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -