📄 tabmultipoint.cpp
字号:
// tabmultioint.cpp: implementation of the TABMultiPoint class.////////////////////////////////////////////////////////////////////////#include "tabmultipoint.h"#include "ugk_errhandle.h"#include "ugk_string.h"#include "ugkpoint.h"#include "ugkmultipoint.h"#include "tabmapobjmultipoint.h"/********************************************************************** * TABMultiPoint::TABMultiPoint() * * Constructor. **********************************************************************/TABMultiPoint::TABMultiPoint(UGKFeatureDefn *poDefnIn): TABFeature(poDefnIn){ m_bCenterIsSet = FALSE;}/********************************************************************** * TABMultiPoint::~TABMultiPoint() * * Destructor. **********************************************************************/TABMultiPoint::~TABMultiPoint(){}/********************************************************************** * TABMultiPoint::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 *TABMultiPoint::CloneTABFeature(UGKFeatureDefn *poNewDefn /*=NULL*/){ /*----------------------------------------------------------------- * Alloc new feature and copy the base stuff *----------------------------------------------------------------*/ TABMultiPoint *poNew = new TABMultiPoint(poNewDefn?poNewDefn:GetDefnRef()); CopyTABFeatureBase(poNew); /*----------------------------------------------------------------- * And members specific to this class *----------------------------------------------------------------*/ // ITABFeatureSymbol *(poNew->GetSymbolDefRef()) = *GetSymbolDefRef(); poNew->m_bCenterIsSet = m_bCenterIsSet; poNew->m_dCenterX = m_dCenterX; poNew->m_dCenterY = m_dCenterY; return poNew;}/********************************************************************** * TABMultiPoint::DumpMIF() * * Dump feature geometry in a format similar to .MIF POINTs. **********************************************************************/void TABMultiPoint::DumpMIF(FILE *fpOut /*=NULL*/){ UGKGeometry *poGeom; UGKMultiPoint *poMPoint; if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint) poMPoint = (UGKMultiPoint*)poGeom; else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Missing or Invalid Geometry!"); return; } /*----------------------------------------------------------------- * Generate output *----------------------------------------------------------------*/ fprintf(fpOut, "MULTIPOINT %d\n", poMPoint->getNumGeometries()); for (int iPoint=0; iPoint < poMPoint->getNumGeometries(); iPoint++) { poGeom = poMPoint->getGeometryRef(iPoint); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { UGKPoint *poPoint = (UGKPoint*)poGeom; fprintf(fpOut, " %g %g\n", poPoint->getX(), poPoint->getY() ); } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Invalid Geometry, expecting UGKPoint!"); return; } } DumpSymbolDef(fpOut); if (m_bCenterIsSet) fprintf(fpOut, "Center %g %g\n", m_dCenterX, m_dCenterY); fflush(fpOut);}/********************************************************************** * TABMultiPoint::GetCenter() * * Returns the center point (or label point?) of the object. Compute one * if it was not explicitly set: * * The default seems to be to use the first point in the collection as * the center.. so we'll use that. * * Returns 0 on success, -1 on error. **********************************************************************/int TABMultiPoint::GetCenter(double &dX, double &dY){ if (!m_bCenterIsSet && GetNumPoints() > 0) { // The default seems to be to use the first point in the collection // as the center... so we'll use that. if (GetXY(0, m_dCenterX, m_dCenterY) == 0) m_bCenterIsSet = TRUE; } if (!m_bCenterIsSet) return -1; dX = m_dCenterX; dY = m_dCenterY; return 0;}/********************************************************************** * TABMultiPoint::GetNumPoints() * * Return the number of points in this multipoint object **********************************************************************/int TABMultiPoint::GetNumPoints(){ UGKGeometry *poGeom; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint) { UGKMultiPoint *poMPoint = (UGKMultiPoint*)poGeom; return poMPoint->getNumGeometries(); } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Missing or Invalid Geometry!"); return 0; } return 0;}/********************************************************************** * TABMultiPoint::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABMultiPoint::GetStyleString(){ if (m_pszStyleString == NULL) { m_pszStyleString = UGKStrdup(GetSymbolStyleString()); } return m_pszStyleString;}/********************************************************************** * TABMultiPoint::GetXY() * * Return this point's X,Y coordinates. **********************************************************************/int TABMultiPoint::GetXY(int i, double &dX, double &dY){ UGKGeometry *poGeom; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint) { UGKMultiPoint *poMPoint = (UGKMultiPoint*)poGeom; if (i >= 0 && i < poMPoint->getNumGeometries() && (poGeom = poMPoint->getGeometryRef(i)) != NULL && wkbFlatten(poGeom->getGeometryType()) == wkbPoint ) { UGKPoint *poPoint = (UGKPoint*)poGeom; dX = poPoint->getX(); dY = poPoint->getY(); } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Missing or Invalid Geometry!"); dX = dY = 0.0; return -1; } return 0;}/********************************************************************** * TABMultiPoint::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 TABMultiPoint::ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *poObjHdr){ UGKInt32 nX, nY; double dX, dY, dXMin, dYMin, dXMax, dYMax; UGKGeometry *poGeometry=NULL; UGKBool bComprCoord = poObjHdr->IsCompressedType(); /*----------------------------------------------------------------- * Fetch and validate geometry type *----------------------------------------------------------------*/ m_nMapInfoType = poObjHdr->m_nType; /*----------------------------------------------------------------- * Read object information *----------------------------------------------------------------*/ if (m_nMapInfoType == TAB_GEOM_MULTIPOINT || m_nMapInfoType == TAB_GEOM_MULTIPOINT_C ) { TABMAPCoordBlock *poCoordBlock; /*------------------------------------------------------------- * Copy data from poObjHdr *------------------------------------------------------------*/ TABMAPObjMultiPoint *poMPointHdr = (TABMAPObjMultiPoint *)poObjHdr; // MBR poMapFile->Int2Coordsys(poMPointHdr->m_nMinX, poMPointHdr->m_nMinY, dXMin, dYMin); poMapFile->Int2Coordsys(poMPointHdr->m_nMaxX, poMPointHdr->m_nMaxY, dXMax, dYMax); m_nSymbolDefIndex = poMPointHdr->m_nSymbolId; // Symbol index poMapFile->ReadSymbolDef(m_nSymbolDefIndex, &m_sSymbolDef); // Centroid/label point poMapFile->Int2Coordsys(poMPointHdr->m_nLabelX, poMPointHdr->m_nLabelY, dX, dY); SetCenter(dX, dY); /*------------------------------------------------------------- * Read Point Coordinates *------------------------------------------------------------*/ UGKMultiPoint *poMultiPoint; poGeometry = poMultiPoint = new UGKMultiPoint(); poCoordBlock = poMapFile->GetCoordBlock(poMPointHdr->m_nCoordBlockPtr); poCoordBlock->SetComprCoordOrigin(poMPointHdr->m_nComprOrgX, poMPointHdr->m_nComprOrgY); for(int iPoint=0; iPoint<poMPointHdr->m_nNumPoints; iPoint++) { if (poCoordBlock->ReadIntCoord(bComprCoord, nX, nY) != 0) { UGKError(ET_Failure, UGKErr_FileIO, "Failed reading coordinate data at offset %d", poMPointHdr->m_nCoordBlockPtr); return -1; } poMapFile->Int2Coordsys(nX, nY, dX, dY); UGKPoint *poPoint = new UGKPoint(dX, dY); if (poMultiPoint->addGeometryDirectly(poPoint) != UGKERR_NONE) { assert(FALSE); // Just in case lower-level lib is modified
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -