?? mitab_feature_mif.cpp
字號(hào):
TABGenerateArc(poRing, 45, dXMax - dXRadius, dYMax - dYRadius, dXRadius, dYRadius, 0.0, PI/2.0); TABGenerateArc(poRing, 45, dXMin + dXRadius, dYMax - dYRadius, dXRadius, dYRadius, PI/2.0, PI); TABCloseRing(poRing); } else { poRing->addPoint(dXMin, dYMin); poRing->addPoint(dXMax, dYMin); poRing->addPoint(dXMax, dYMax); poRing->addPoint(dXMin, dYMax); poRing->addPoint(dXMin, dYMin); } poPolygon->addRingDirectly(poRing); SetGeometryDirectly(poPolygon); while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { papszToken = CSLTokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CSLCount(papszToken) > 1) { if (EQUALN(papszToken[0],"PEN",3)) { if (CSLCount(papszToken) == 4) { SetPenWidthMIF(atoi(papszToken[1])); SetPenPattern(atoi(papszToken[2])); SetPenColor(atoi(papszToken[3])); } } else if (EQUALN(papszToken[0],"BRUSH", 5)) { if (CSLCount(papszToken) >=3) { SetBrushFGColor(atoi(papszToken[2])); SetBrushPattern(atoi(papszToken[1])); if (CSLCount(papszToken) == 4) SetBrushBGColor(atoi(papszToken[3])); else SetBrushTransparent(TRUE); } } } CSLDestroy(papszToken); papszToken = NULL; } return 0; } /********************************************************************** * **********************************************************************/int TABRectangle::WriteGeometryToMIFFile(MIDDATAFile *fp){ OGRGeometry *poGeom; OGRPolygon *poPolygon; OGREnvelope sEnvelope; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon) poPolygon = (OGRPolygon*)poGeom; else { CPLError(CE_Failure, CPLE_AssertionFailed, "TABRectangle: Missing or Invalid Geometry!"); return -1; } /*----------------------------------------------------------------- * Note that we will simply use the rectangle's MBR and don't really * read the polygon geometry... this should be OK unless the * polygon geometry was not really a rectangle. *----------------------------------------------------------------*/ poPolygon->getEnvelope(&sEnvelope); if (m_bRoundCorners == TRUE) { fp->WriteLine("Roundrect %.16g %.16g %.16g %.16g %.16g\n", sEnvelope.MinX, sEnvelope.MinY, sEnvelope.MaxX, sEnvelope.MaxY, m_dRoundXRadius*2.0); } else { fp->WriteLine("Rect %.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; }/********************************************************************** * **********************************************************************/int TABEllipse::ReadGeometryFromMIFFile(MIDDATAFile *fp){ const char *pszLine; char **papszToken; double dXMin, dYMin, dXMax, dYMax; OGRPolygon *poPolygon; OGRLinearRing *poRing; papszToken = CSLTokenizeString2(fp->GetLastLine(), " \t", CSLT_HONOURSTRINGS); if (CSLCount(papszToken) != 5) { CSLDestroy(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])); CSLDestroy(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 OGRPolygon; poRing = new OGRLinearRing(); /*----------------------------------------------------------------- * For the OGR 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 = CSLTokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CSLCount(papszToken) > 1) { if (EQUALN(papszToken[0],"PEN",3)) { if (CSLCount(papszToken) == 4) { SetPenWidthMIF(atoi(papszToken[1])); SetPenPattern(atoi(papszToken[2])); SetPenColor(atoi(papszToken[3])); } } else if (EQUALN(papszToken[0],"BRUSH", 5)) { if (CSLCount(papszToken) >= 3) { SetBrushFGColor(atoi(papszToken[2])); SetBrushPattern(atoi(papszToken[1])); if (CSLCount(papszToken) == 4) SetBrushBGColor(atoi(papszToken[3])); else SetBrushTransparent(TRUE); } } } CSLDestroy(papszToken); papszToken = NULL; } return 0; }/********************************************************************** * **********************************************************************/int TABEllipse::WriteGeometryToMIFFile(MIDDATAFile *fp){ OGRGeometry *poGeom; OGREnvelope sEnvelope; poGeom = GetGeometryRef(); if ( (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ) || (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint ) ) poGeom->getEnvelope(&sEnvelope); else { CPLError(CE_Failure, CPLE_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; }/********************************************************************** * **********************************************************************/int TABArc::ReadGeometryFromMIFFile(MIDDATAFile *fp){ const char *pszLine; OGRLineString *poLine; char **papszToken; double dXMin,dXMax, dYMin,dYMax; int numPts; papszToken = CSLTokenizeString2(fp->GetLastLine(), " \t", CSLT_HONOURSTRINGS); if (CSLCount(papszToken) == 5) { dXMin = fp->GetXTrans(atof(papszToken[1])); dXMax = fp->GetXTrans(atof(papszToken[3])); dYMin = fp->GetYTrans(atof(papszToken[2])); dYMax = fp->GetYTrans(atof(papszToken[4])); CSLDestroy(papszToken); papszToken = CSLTokenizeString2(fp->GetLine(), " \t", CSLT_HONOURSTRINGS); if (CSLCount(papszToken) != 2) { CSLDestroy(papszToken); return -1; } m_dStartAngle = atof(papszToken[0]); m_dEndAngle = atof(papszToken[1]); } else if (CSLCount(papszToken) == 7) { dXMin = fp->GetXTrans(atof(papszToken[1])); dXMax = fp->GetXTrans(atof(papszToken[3])); dYMin = fp->GetYTrans(atof(papszToken[2])); dYMax = fp->GetYTrans(atof(papszToken[4])); m_dStartAngle = atof(papszToken[5]); m_dEndAngle = atof(papszToken[6]); } else { CSLDestroy(papszToken); return -1; } CSLDestroy(papszToken); papszToken = NULL; /*------------------------------------------------------------- * Start/End angles * Since the angles are specified for integer coordinates, and * that these coordinates can have the X axis reversed, we have to * adjust the angle values for the change in the X axis * direction. * * This should be necessary only when X axis is flipped. * __TODO__ Why is order of start/end values reversed as well??? *------------------------------------------------------------*/ if (fp->GetXMultiplier() <= 0.0) { m_dStartAngle = 360.0 - m_dStartAngle; m_dEndAngle = 360.0 - m_dEndAngle; } 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 ); /*----------------------------------------------------------------- * Create and fill geometry object * For the OGR geometry, we generate an arc with 2 degrees line * segments. *----------------------------------------------------------------*/ poLine = new OGRLineString; if (m_dEndAngle < m_dStartAngle) numPts = (int) ABS( ((m_dEndAngle+360.0)-m_dStartAngle)/2.0 ) + 1; else numPts = (int) ABS( (m_dEndAngle-m_dStartAngle)/2.0 ) + 1; numPts = MAX(2, numPts); TABGenerateArc(poLine, numPts, m_dCenterX, m_dCenterY, m_dXRadius, m_dYRadius, m_dStartAngle*PI/180.0, m_dEndAngle*PI/180.0); SetMBR(dXMin, dYMin, dXMax, dYMax); SetGeometryDirectly(poLine); while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { papszToken = CSLTokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CSLCount(papszToken) > 1) { if (EQUALN(papszToken[0],"PEN",3)) { if (CSLCount(papszToken) == 4) { SetPenWidthMIF(atoi(papszToken[1])); SetPenPattern(atoi(papszToken[2])); SetPenColor(atoi(papszToken[3])); } } } CSLDestroy(papszToken); papszToken = NULL; } return 0; }/********************************************************************** * **********************************************************************/int TABArc::WriteGeometryToMIFFile(MIDDATAFile *fp){ /*------------------------------------------------------------- * Start/End angles * Since we ALWAYS produce files in quadrant 1 then we can * ignore the special angle conversion required by flipped axis. *------------------------------------------------------------*/ // Write the Arc's actual MBR fp->WriteLine("Arc %.16g %.16g %.16g %.16g\n", m_dCenterX-m_dXRadius, m_dCenterY-m_dYRadius, m_dCenterX+m_dXRadius, m_dCenterY+m_dYRadius);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -