📄 tabellipse.cpp
字号:
{ m_dXRadius = ABS(sEnvelope.MaxX - sEnvelope.MinX) / 2.0; m_dYRadius = ABS(sEnvelope.MaxY - sEnvelope.MinY); } poMapFile->Coordsys2Int(dXCenter - m_dXRadius, dYCenter - m_dYRadius, poRectHdr->m_nMinX, poRectHdr->m_nMinY); poMapFile->Coordsys2Int(dXCenter + m_dXRadius, dYCenter + m_dYRadius, poRectHdr->m_nMaxX, poRectHdr->m_nMaxY); m_nPenDefIndex = poMapFile->WritePenDef(&m_sPenDef); poRectHdr->m_nPenId = m_nPenDefIndex; // Pen index m_nBrushDefIndex = poMapFile->WriteBrushDef(&m_sBrushDef); poRectHdr->m_nBrushId = m_nBrushDefIndex; // Brush index if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABEllipse::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABEllipse::GetStyleString(){ if (m_pszStyleString == NULL) { // Since GetPen/BrushStyleString() use CPLSPrintf(), we need // to use temporary buffers char *pszPen = UGKStrdup(GetPenStyleString()); char *pszBrush = UGKStrdup(GetBrushStyleString()); m_pszStyleString = UGKStrdup(UGKSPrintf("%s;%s", pszBrush, pszPen)); UGK_Free(pszPen); UGK_Free(pszBrush); } return m_pszStyleString;}/********************************************************************** * TABEllipse::DumpMIF() * * Dump feature geometry in a format similar to .MIF REGIONs. **********************************************************************/void TABEllipse::DumpMIF(FILE *fpOut /*=NULL*/){ UGKGeometry *poGeom; UGKPolygon *poPolygon = NULL; int i, numPoints; if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Output ELLIPSE parameters *----------------------------------------------------------------*/ double dXMin, dYMin, dXMax, dYMax; GetMBR(dXMin, dYMin, dXMax, dYMax); fprintf(fpOut, "(ELLIPSE %g %g %g %g)\n", dXMin, dYMin, dXMax, dYMax); /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon) { /*------------------------------------------------------------- * Generate ellipse output as a region * We could also output as an ELLIPSE in a real MIF generator *------------------------------------------------------------*/ int iRing, numIntRings; poPolygon = (UGKPolygon*)poGeom; numIntRings = poPolygon->getNumInteriorRings(); fprintf(fpOut, "REGION %d\n", numIntRings+1); // In this loop, iRing=-1 for the outer ring. for(iRing=-1; iRing < numIntRings; iRing++) { UGKLinearRing *poRing; if (iRing == -1) poRing = poPolygon->getExteriorRing(); else poRing = poPolygon->getInteriorRing(iRing); if (poRing == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABEllipse: Object Geometry contains NULL rings!"); return; } numPoints = poRing->getNumPoints(); fprintf(fpOut, " %d\n", numPoints); for(i=0; i<numPoints; i++) fprintf(fpOut, "%g %g\n",poRing->getX(i),poRing->getY(i)); } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABEllipse: Missing or Invalid Geometry!"); return; } // Finish with PEN/BRUSH/etc. clauses DumpPenDef(); DumpBrushDef(); fflush(fpOut);}/********************************************************************** * **********************************************************************/int TABEllipse::ReadGeometryFromMIFFile(MIDDATAFile *fp){ const char *pszLine; char **papszToken; double dXMin, dYMin, dXMax, dYMax; UGKPolygon *poPolygon; UGKLinearRing *poRing; papszToken = TokenizeString2(fp->GetLastLine(), " \t", 0x0001); if (CountOfList(papszToken) != 5) { FreeStrList(papszToken); return -1; } dXMin = fp->GetXTrans(atof(papszToken[1])); dXMax = fp->GetXTrans(atof(papszToken[3])); dYMin = fp->GetYTrans(atof(papszToken[2])); dYMax = fp->GetYTrans(atof(papszToken[4])); FreeStrList(papszToken); papszToken = NULL; /*----------------------------------------------------------------- * Save info about the ellipse def. inside class members *----------------------------------------------------------------*/ m_dCenterX = (dXMin + dXMax) / 2.0; m_dCenterY = (dYMin + dYMax) / 2.0; m_dXRadius = ABS( (dXMax - dXMin) / 2.0 ); m_dYRadius = ABS( (dYMax - dYMin) / 2.0 ); SetMBR(dXMin, dYMin, dXMax, dYMax); /*----------------------------------------------------------------- * Create and fill geometry object *----------------------------------------------------------------*/ poPolygon = new UGKPolygon; poRing = new UGKLinearRing(); /*----------------------------------------------------------------- * For the UGK geometry, we generate an ellipse with 2 degrees line * segments. *----------------------------------------------------------------*/ TABGenerateArc(poRing, 180, m_dCenterX, m_dCenterY, m_dXRadius, m_dYRadius, 0.0, 2.0*PI); TABCloseRing(poRing); poPolygon->addRingDirectly(poRing); SetGeometryDirectly(poPolygon); while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { papszToken = TokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CountOfList(papszToken) > 1) { if (EQUALN(papszToken[0],"PEN",3)) { if (CountOfList(papszToken) == 4) { SetPenWidthMIF(atoi(papszToken[1])); SetPenPattern(atoi(papszToken[2])); SetPenColor(atoi(papszToken[3])); } } else if (EQUALN(papszToken[0],"BRUSH", 5)) { if (CountOfList(papszToken) >= 3) { SetBrushFGColor(atoi(papszToken[2])); SetBrushPattern(atoi(papszToken[1])); if (CountOfList(papszToken) == 4) SetBrushBGColor(atoi(papszToken[3])); else SetBrushTransparent(TRUE); } } } FreeStrList(papszToken); papszToken = NULL; } return 0; }/********************************************************************** * **********************************************************************/int TABEllipse::WriteGeometryToMIFFile(MIDDATAFile *fp){ UGKGeometry *poGeom; UGKEnvelope sEnvelope; poGeom = GetGeometryRef(); if ( (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ) || (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint ) ) poGeom->getEnvelope(&sEnvelope); else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABEllipse: Missing or Invalid Geometry!"); return -1; } fp->WriteLine("Ellipse %.16g %.16g %.16g %.16g\n",sEnvelope.MinX, sEnvelope.MinY, sEnvelope.MaxX,sEnvelope.MaxY); if (GetPenPattern()) fp->WriteLine(" Pen (%d,%d,%d)\n",GetPenWidthMIF(),GetPenPattern(), GetPenColor()); if (GetBrushPattern()) { if (GetBrushTransparent() == 0) fp->WriteLine(" Brush (%d,%d,%d)\n",GetBrushPattern(), GetBrushFGColor(),GetBrushBGColor()); else fp->WriteLine(" Brush (%d,%d)\n",GetBrushPattern(), GetBrushFGColor()); } return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -