📄 tabmultipoint.cpp
字号:
} } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "ReadGeometryFromMAPFile(): unsupported geometry type %d (0x%2.2x)", m_nMapInfoType, m_nMapInfoType); return -1; } SetGeometryDirectly(poGeometry); SetMBR(dXMin, dYMin, dXMax, dYMax); return 0;}/********************************************************************** * TABMultiPoint::ReadGeometryFromMIFFile **********************************************************************/int TABMultiPoint::ReadGeometryFromMIFFile(MIDDATAFile *fp){ UGKPoint *poPoint; UGKMultiPoint *poMultiPoint; char **papszToken; const char *pszLine; int nNumPoint, i; double dfX,dfY; UGKEnvelope sEnvelope; papszToken = TokenizeString2(fp->GetLastLine(), " \t", 0x0001); if (CountOfList(papszToken) !=2) { FreeStrList(papszToken); return -1; } nNumPoint = atoi(papszToken[1]); poMultiPoint = new UGKMultiPoint; FreeStrList(papszToken); papszToken = NULL; // Get each point and add them to the multipoint feature for(i=0; i<nNumPoint; i++) { pszLine = fp->GetLine(); papszToken = TokenizeString2(fp->GetLastLine(), " \t", 0x0001); if (CountOfList(papszToken) !=2) { FreeStrList(papszToken); return -1; } dfX = fp->GetXTrans(atof(papszToken[0])); dfY = fp->GetXTrans(atof(papszToken[1])); poPoint = new UGKPoint(dfX, dfY); if ( poMultiPoint->addGeometryDirectly( poPoint ) != UGKERR_NONE) { assert(FALSE); // Just in case UGK is modified } // Set center if(i == 0) { SetCenter( dfX, dfY ); } } if( SetGeometryDirectly( poMultiPoint ) != UGKERR_NONE) { assert(FALSE); // Just in case UGK is modified } poMultiPoint->getEnvelope(&sEnvelope); SetMBR(sEnvelope.MinX, sEnvelope.MinY, sEnvelope.MaxX,sEnvelope.MaxY); // Read optional SYMBOL line... while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { 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])); } } return 0; }/********************************************************************** * TABMultiPoint::SetCenter() * * Set the X,Y coordinates to use as center point (or label point?) **********************************************************************/void TABMultiPoint::SetCenter(double dX, double dY){ m_dCenterX = dX; m_dCenterY = dY; m_bCenterIsSet = TRUE;}/********************************************************************** * TABMultiPoint::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 TABMultiPoint::ValidateMapInfoType(TABMAPFile *poMapFile /*=NULL*/){ UGKGeometry *poGeom; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint) { m_nMapInfoType = TAB_GEOM_MULTIPOINT; } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Missing or Invalid Geometry!"); m_nMapInfoType = TAB_GEOM_NONE; } /*----------------------------------------------------------------- * Decide if coordinates should be compressed or not. *----------------------------------------------------------------*/ ValidateCoordType(poMapFile); return m_nMapInfoType;}/********************************************************************** * TABMultiPoint::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 TABMultiPoint::WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *poObjHdr){ UGKInt32 nX, nY; UGKGeometry *poGeom; UGKMultiPoint *poMPoint; /*----------------------------------------------------------------- * We assume that ValidateMapInfoType() was called already and that * the type in poObjHdr->m_nType is valid. *----------------------------------------------------------------*/ assert(m_nMapInfoType == poObjHdr->m_nType); TABMAPObjMultiPoint *poMPointHdr = (TABMAPObjMultiPoint *)poObjHdr; /*----------------------------------------------------------------- * 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 -1; } poMPointHdr->m_nNumPoints = poMPoint->getNumGeometries(); /*----------------------------------------------------------------- * Write data to coordinate block *----------------------------------------------------------------*/ int iPoint, nStatus; TABMAPCoordBlock *poCoordBlock; UGKBool bCompressed = poObjHdr->IsCompressedType(); poCoordBlock = poMapFile->GetCurCoordBlock(); poCoordBlock->StartNewFeature(); poMPointHdr->m_nCoordBlockPtr = poCoordBlock->GetCurAddress(); poCoordBlock->SetComprCoordOrigin(m_nComprOrgX, m_nComprOrgY); for(iPoint=0, nStatus=0; nStatus == 0 && iPoint < poMPointHdr->m_nNumPoints; iPoint++) { poGeom = poMPoint->getGeometryRef(iPoint); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { UGKPoint *poPoint = (UGKPoint*)poGeom; poMapFile->Coordsys2Int(poPoint->getX(), poPoint->getY(), nX, nY); if (iPoint == 0) { // Default to the first point, we may use explicit value below poMPointHdr->m_nLabelX = nX; poMPointHdr->m_nLabelY = nY; } if ((nStatus = poCoordBlock->WriteIntCoord(nX, nY, bCompressed)) != 0) { // Failed ... error message has already been produced return nStatus; } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Invalid Geometry, expecting UGKPoint!"); return -1; } } /*----------------------------------------------------------------- * Copy object information *----------------------------------------------------------------*/ // Compressed coordinate origin (useful only in compressed case!) poMPointHdr->m_nComprOrgX = m_nComprOrgX; poMPointHdr->m_nComprOrgY = m_nComprOrgY; poMPointHdr->m_nCoordDataSize = poCoordBlock->GetFeatureDataSize(); poMPointHdr->SetMBR(m_nXMin, m_nYMin, m_nXMax, m_nYMax); // Center/label point (default value already set above) double dX, dY; if (GetCenter(dX, dY) != -1) { poMapFile->Coordsys2Int(dX, dY, poMPointHdr->m_nLabelX, poMPointHdr->m_nLabelY); } m_nSymbolDefIndex = poMapFile->WriteSymbolDef(&m_sSymbolDef); poMPointHdr->m_nSymbolId = m_nSymbolDefIndex; // Symbol index if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * **********************************************************************/int TABMultiPoint::WriteGeometryToMIFFile(MIDDATAFile *fp){ UGKGeometry *poGeom; UGKPoint *poPoint; UGKMultiPoint *poMultiPoint; int nNumPoints, iPoint; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint) { poMultiPoint = (UGKMultiPoint*)poGeom; nNumPoints = poMultiPoint->getNumGeometries(); fp->WriteLine("MultiPoint %d\n", nNumPoints); for(iPoint=0; iPoint < nNumPoints; iPoint++) { /*------------------------------------------------------------ * Validate each point *-----------------------------------------------------------*/ poGeom = poMultiPoint->getGeometryRef(iPoint); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { poPoint = (UGKPoint*)poGeom; fp->WriteLine("%.16g %.16g\n",poPoint->getX(),poPoint->getY()); } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABMultiPoint: Missing or Invalid Geometry!"); return -1; } } // Write symbol fp->WriteLine(" Symbol (%d,%d,%d)\n",GetSymbolNo(),GetSymbolColor(), GetSymbolSize()); } return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -