爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4127|回复: 11

王老师,等值线问题求教。

[复制链接]

新浪微博达人勋

发表于 2015-12-23 19:27:34 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
现在用GRID数据绘制等值线,不知道是哪里数据出问题了。
绘出来的图像成这样。 123.png
107*95数据
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-23 19:37:52 | 显示全部楼层
数据是什么?你是怎么做的?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-23 19:37:55 | 显示全部楼层
数据是什么?你是怎么做的?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-12-23 20:03:31 | 显示全部楼层
数据使用数字预报的格点温度数据,使用方法是你的DEMO的方法。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-12-23 20:10:49 | 显示全部楼层
这是我使用的数据源。

temp.txt

48.93 KB, 下载次数: 3, 下载积分: 金钱 -5

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-23 21:00:21 | 显示全部楼层
rainfull 发表于 2015-12-23 20:10
这是我使用的数据源。

DEMO的方法指的什么?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-12-23 21:53:13 | 显示全部楼层
从你网站下载的DEMO,其中的一个“RandomData”的“GRID”方法。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

0
早起挑战累计收入
发表于 2015-12-23 22:01:16 | 显示全部楼层
rainfull 发表于 2015-12-23 21:53
从你网站下载的DEMO,其中的一个“RandomData”的“GRID”方法。

你还是把代码传上来比较好
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-12-23 22:08:41 | 显示全部楼层
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using wContour;


  12. namespace HimawariCast_Display
  13. {
  14.     class LineContour
  15.     {
  16.         public System.Windows.Forms.PictureBox  PictureBox1 = null;
  17.         public double[,] _gridData = null;
  18.         double[,] _discreteData = null;
  19.         double[] _X = null;
  20.         double[] _Y = null;
  21.         double[] _CValues = null;
  22.         Color[] _colors = null;

  23.         List<List<PointD>> _mapLines = new List<List<PointD>>();
  24.         List<Border> _borders = new List<Border>();
  25.         List<PolyLine> _contourLines = new List<PolyLine>();
  26.         List<PolyLine> _clipContourLines = new List<PolyLine>();
  27.         List<Polygon> _contourPolygons = new List<Polygon>();
  28.         List<Polygon> _clipContourPolygons = new List<Polygon>();
  29.         List<wContour.Legend.lPolygon> _legendPolygons = new List<Legend.lPolygon>();
  30.         List<PolyLine> _streamLines = new List<PolyLine>();
  31.         
  32.         double _undefData = -9999.0;
  33.         List<List<PointD>> _clipLines = new List<List<PointD>>();
  34.         //List<PointD> _clipPList = new List<PointD>();                  
  35.         public Color _startColor = default(Color);
  36.         public Color _endColor = default(Color);
  37.         private int _highlightIdx = 0;

  38.         private double _minX = 0;
  39.         private double _minY = 0;
  40.         private double _maxX = 0;
  41.         private double _maxY = 0;
  42.         private double _scaleX = 1.0;
  43.         private double _scaleY = 1.0;

  44.         public string _dFormat = "0";



  45.         public bool GB_DrawSet = true;
  46.         public bool CB_DiscreteData = false;
  47.         public bool CB_GridData = false;
  48.         public  bool CB_BorderLines = false;
  49.         public  bool CB_ContourLine = false;
  50.         public  bool CB_ContourPolygon = true;
  51.         public bool CB_Clipped = true;
  52.         public bool ChB_Highlight = true;

  53.         public void CreateGridData(int rows, int cols)
  54.         {
  55.             int i = 0;
  56.             int j = 0;
  57.             double XDelt = 0;
  58.             double YDelt = 0;

  59.             //---- Generate X and Y coordinates            
  60.             _X = new double[cols];
  61.             _Y = new double[rows];

  62.             XDelt = this.PictureBox1.Width / cols;
  63.             YDelt = this.PictureBox1.Height / rows;
  64.             for (i = 0; i <= cols - 1; i++)
  65.             {
  66.                 _X[i] = i * XDelt;
  67.             }
  68.             for (i = 0; i <= rows - 1; i++)
  69.             {
  70.                 _Y[i] = i * YDelt;
  71.             }
  72.         }


  73.         public void SetStation(double[] x, double[] y)
  74.         {
  75.             _X = x;
  76.             _Y = y;
  77.         }


  78.         public void SetContourValues(double[] values)
  79.         {
  80.             _CValues = values;
  81.         }
  82.         public void TracingContourLines()
  83.         {
  84.             //---- Contour values
  85.             int nc = _CValues.Length;

  86.             //---- Colors
  87.             _colors = CreateColors(_startColor, _endColor, nc + 1);

  88.             double XDelt = 0;
  89.             double YDelt = 0;
  90.             XDelt = _X[1] - _X[0];
  91.             YDelt = _Y[1] - _Y[0];
  92.             int[,] S1 = new int[1, 1];
  93.             _borders = Contour.TracingBorders(_gridData, _X, _Y, ref S1, _undefData);
  94.             _contourLines = Contour.TracingContourLines(_gridData, _X, _Y, nc, _CValues, _undefData, _borders, S1);
  95.         }
  96.         public void SmoothLines()
  97.         {
  98.             _contourLines = Contour.SmoothLines(_contourLines);
  99.         }
  100.         private Color[] CreateColors(Color sColor, Color eColor, int cNum)
  101.         {
  102.             Color[] colors = new Color[cNum];
  103.             int sR = 0;
  104.             int sG = 0;
  105.             int sB = 0;
  106.             int eR = 0;
  107.             int eG = 0;
  108.             int eB = 0;
  109.             int rStep = 0;
  110.             int gStep = 0;
  111.             int bStep = 0;
  112.             int i = 0;

  113.             sR = sColor.R;
  114.             sG = sColor.G;
  115.             sB = sColor.B;
  116.             eR = eColor.R;
  117.             eG = eColor.G;
  118.             eB = eColor.B;
  119.             rStep = Convert.ToInt32((eR - sR) / cNum);
  120.             gStep = Convert.ToInt32((eG - sG) / cNum);
  121.             bStep = Convert.ToInt32((eB - sB) / cNum);
  122.             for (i = 0; i <= colors.Length - 1; i++)
  123.             {
  124.                 colors[i] = Color.FromArgb(sR + i * rStep, sG + i * gStep, sB + i * bStep);
  125.             }

  126.             return colors;
  127.         }

  128.         public void GetEcllipseClipping()
  129.         {
  130.             _clipLines = new List<List<PointD>>();

  131.             //---- Generate border with ellipse
  132.             double x0 = 0;
  133.             double y0 = 0;
  134.             double a = 0;
  135.             double b = 0;
  136.             double c = 0;
  137.             bool ifX = false;
  138.             x0 = this.PictureBox1.Width / 2;
  139.             y0 = this.PictureBox1.Height / 2;
  140.             double dist = 0;
  141.             dist = 100;
  142.             a = x0 - dist;
  143.             b = y0 - dist / 2;
  144.             if (a > b)
  145.             {
  146.                 ifX = true;
  147.             }
  148.             else
  149.             {
  150.                 ifX = false;
  151.                 c = a;
  152.                 a = b;
  153.                 b = c;
  154.             }

  155.             int i = 0;
  156.             int n = 0;
  157.             n = 100;
  158.             double nx = 0;
  159.             double x1 = 0;
  160.             double y1 = 0;
  161.             double ytemp = 0;
  162.             List<PointD> pList = new List<PointD>();
  163.             List<PointD> pList1 = new List<PointD>();
  164.             wContour.PointD aPoint;
  165.             nx = (x0 * 2 - dist * 2) / n;
  166.             for (i = 1; i <= n; i++)
  167.             {
  168.                 x1 = dist + nx / 2 + (i - 1) * nx;
  169.                 if (ifX)
  170.                 {
  171.                     ytemp = Math.Sqrt((1 - Math.Pow((x1 - x0), 2) / Math.Pow(a, 2)) * Math.Pow(b, 2));
  172.                     y1 = y0 + ytemp;
  173.                     aPoint = new PointD();
  174.                     aPoint.X = x1;
  175.                     aPoint.Y = y1;
  176.                     pList.Add(aPoint);
  177.                     aPoint = new PointD();
  178.                     aPoint.X = x1;
  179.                     y1 = y0 - ytemp;
  180.                     aPoint.Y = y1;
  181.                     pList1.Add(aPoint);
  182.                 }
  183.                 else
  184.                 {
  185.                     ytemp = Math.Sqrt((1 - Math.Pow((x1 - x0), 2) / Math.Pow(b, 2)) * Math.Pow(a, 2));
  186.                     y1 = y0 + ytemp;
  187.                     aPoint = new PointD();
  188.                     aPoint.X = x1;
  189.                     aPoint.Y = y1;
  190.                     pList1.Add(aPoint);
  191.                     aPoint = new PointD();
  192.                     aPoint.X = x1;
  193.                     y1 = y0 - ytemp;
  194.                     aPoint.Y = y1;
  195.                     pList1.Add(aPoint);
  196.                 }
  197.             }

  198.             aPoint = new PointD();
  199.             if (ifX)
  200.             {
  201.                 aPoint.X = x0 - a;
  202.             }
  203.             else
  204.             {
  205.                 aPoint.X = x0 - b;
  206.             }
  207.             aPoint.Y = y0;
  208.             List<PointD> cLine = new List<PointD>();
  209.             cLine.Add(aPoint);
  210.             for (i = 0; i <= pList.Count - 1; i++)
  211.             {
  212.                 cLine.Add(pList[i]);
  213.             }
  214.             aPoint = new PointD();
  215.             aPoint.Y = y0;
  216.             if (ifX)
  217.             {
  218.                 aPoint.X = x0 + a;
  219.             }
  220.             else
  221.             {
  222.                 aPoint.X = x0 + b;
  223.             }
  224.             cLine.Add(aPoint);
  225.             for (i = pList1.Count - 1; i >= 0; i += -1)
  226.             {
  227.                 cLine.Add(pList1[i]);
  228.             }
  229.             cLine.Add(cLine[0]);
  230.             _clipLines.Add(cLine);
  231.         }

  232.         public void ClipLines()
  233.         {
  234.             _clipContourLines = new List<PolyLine>();
  235.             foreach (List<PointD> cLine in _clipLines)
  236.                 _clipContourLines.AddRange(Contour.ClipPolylines(_contourLines, cLine));
  237.         }

  238.         public void ClipPolygons()
  239.         {
  240.             _clipContourPolygons = new List<Polygon>();
  241.             //for (int i = 0; i < _clipLines.Count; i++)
  242.             //    _clipContourPolygons.AddRange(Contour.ClipPolygons(_contourPolygons, _clipLines[i]));

  243.             //_clipContourPolygons.AddRange(Contour.ClipPolygons(_contourPolygons, _clipLines[20]));

  244.             foreach (List<PointD> cLine in _clipLines)
  245.                 _clipContourPolygons.AddRange(Contour.ClipPolygons(_contourPolygons, cLine));
  246.         }

  247.         public void TracingPolygons()
  248.         {
  249.             _contourPolygons = Contour.TracingPolygons(_gridData, _contourLines, _borders, _CValues);
  250.         }

  251.         public void CreateLegend()
  252.         {
  253.             wContour.Legend aLegend = new wContour.Legend();
  254.             wContour.PointD aPoint = new PointD();

  255.             double width = _maxX - _minX;
  256.             aPoint.X = _minX + width / 4;
  257.             aPoint.Y = _minY + width / 100;
  258.             wContour.Legend.legendPara lPara = new Legend.legendPara();
  259.             lPara.startPoint = aPoint;
  260.             lPara.isTriangle = true;
  261.             lPara.isVertical = false;
  262.             lPara.length = width / 2;
  263.             lPara.width = width / 100;
  264.             lPara.contourValues = _CValues;

  265.             _legendPolygons = Legend.CreateLegend(lPara);
  266.         }
  267.         public void ClearObjects()
  268.         {
  269.             _discreteData = null;
  270.             _gridData = null;
  271.             _borders = new List<Border>();
  272.             _contourLines = new List<PolyLine>();
  273.             _contourPolygons = new List<Polygon>();
  274.             _clipLines = new List<List<PointD>>();
  275.             _clipContourLines = new List<PolyLine>();
  276.             _clipContourPolygons = new List<Polygon>();
  277.             _mapLines = new List<List<PointD>>();
  278.             _legendPolygons = new List<Legend.lPolygon>();
  279.             _streamLines = new List<PolyLine>();
  280.         }

  281.         public void SetCoordinate(double minX, double maxX, double minY, double maxY)
  282.         {
  283.             _minX = minX;
  284.             _maxX = maxX;
  285.             _minY = minY;
  286.             _maxY = maxY;
  287.             _scaleX = (this.PictureBox1.Width - 10) / (_maxX - _minX);
  288.             _scaleY = (this.PictureBox1.Height - 10) / (_maxY - _minY);
  289.             //this.PictureBox1.Refresh();
  290.         }

  291.         private void ToScreen(double pX, double pY, ref int sX, ref int sY)
  292.         {
  293.             sX = (int)((pX - _minX) * _scaleX);
  294.             sY = (int)((_maxY - pY) * _scaleY);
  295.         }

  296.         private void ToScreen(double pX, double pY, ref float sX, ref float sY)
  297.         {
  298.             sX = (float)((pX - _minX) * _scaleX);
  299.             sY = (float)((_maxY - pY) * _scaleY);
  300.         }

  301.         private void ToCoordinate(int sX, int sY, ref double pX, ref double pY)
  302.         {
  303.             pX = sX / _scaleX + _minX;
  304.             pY = _maxY - sY / _scaleY;
  305.         }

  306.         public void PaintGraphics(Graphics g)
  307.         {
  308.             int i = 0;
  309.             int j = 0;
  310.             wContour.PolyLine aline = default(wContour.PolyLine);
  311.             List<PointD> newPList = new List<PointD>();
  312.             double aValue = 0;
  313.             Color aColor = default(Color);
  314.             Pen aPen = default(Pen);
  315.             wContour.PointD aPoint = default(wContour.PointD);
  316.             Point[] Points = null;
  317.             int sX = 0;
  318.             int sY = 0;

  319.             //Draw contour polygons
  320.             if (CB_ContourPolygon)
  321.             {
  322.                 List<Polygon> drawPolygons = _contourPolygons;
  323.                 if (CB_Clipped)
  324.                     drawPolygons = _clipContourPolygons;

  325.                 for (i = 0; i < drawPolygons.Count; i++)
  326.                 {
  327.                     DrawPolygon(g, drawPolygons[i], false);
  328.                 }
  329.                 if (ChB_Highlight)
  330.                 {
  331.                     if (_highlightIdx < drawPolygons.Count)
  332.                         DrawPolygon(g, drawPolygons[_highlightIdx], true);
  333.                 }
  334.             }

  335.             //Draw contour lines
  336.             if (CB_ContourLine)
  337.             {
  338.                 List<PolyLine> drawLines = _contourLines;
  339.                 if (CB_Clipped)
  340.                     drawLines = _clipContourLines;

  341.                 for (i = 0; i <= drawLines.Count - 1; i++)
  342.                 {
  343.                     aline = drawLines[i];
  344.                     aValue = aline.Value;
  345.                     aColor = _colors[Array.IndexOf(_CValues, aValue)];
  346.                     newPList = aline.PointList;

  347.                     Points = new Point[newPList.Count];
  348.                     for (j = 0; j <= newPList.Count - 1; j++)
  349.                     {
  350.                         aPoint = (wContour.PointD)newPList[j];
  351.                         ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  352.                         Points[j] = new Point(sX, sY);
  353.                     }
  354.                     aPen = new Pen(Color.Black);
  355.                     aPen.Color = aColor;
  356.                     g.DrawLines(aPen, Points);
  357.                 }
  358.             }

  359.             //Draw border lines
  360.             if (CB_BorderLines)
  361.             {
  362.                 for (i = 0; i < _borders.Count; i++)
  363.                 {
  364.                     Border aBorder = _borders[i];
  365.                     for (j = 0; j < aBorder.LineNum; j++)
  366.                     {
  367.                         BorderLine bLine = aBorder.LineList[j];
  368.                         Points = new Point[bLine.pointList.Count];
  369.                         for (int k = 0; k < bLine.pointList.Count; k++)
  370.                         {
  371.                             aPoint = bLine.pointList[k];
  372.                             ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  373.                             Points[k] = new Point(sX, sY);
  374.                         }
  375.                         g.DrawLines(Pens.Purple, Points);
  376.                         //if (i == 3)
  377.                         //{
  378.                         //    Pen bPen = new Pen(Color.Blue);
  379.                         //    bPen.Width = 2;
  380.                         //    g.DrawLines(bPen, Points);
  381.                         //}
  382.                         //if (i == 3)
  383.                         //    g.DrawString(i.ToString(), new Font("Arial", 8), new SolidBrush(Color.Red), Points[0].X, Points[0].Y);
  384.                     }
  385.                 }
  386.             }

  387.             //Draw clip line
  388.             if (CB_Clipped && _clipLines.Count > 0)
  389.             {
  390.                 foreach (List<PointD> cLine in _clipLines)
  391.                 {
  392.                     Points = new Point[cLine.Count];
  393.                     for (i = 0; i < cLine.Count; i++)
  394.                     {
  395.                         aPoint = cLine[i];
  396.                         ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  397.                         Points[i] = new Point(sX, sY);
  398.                     }
  399.                     g.DrawLines(Pens.Purple, Points);
  400.                 }
  401.             }

  402.             //Draw data points
  403.             Font drawFont = new Font("Arial", 8);
  404.             SolidBrush drawBrush = new SolidBrush(Color.Black);
  405.             if (CB_DiscreteData && _discreteData != null)
  406.             {
  407.                 for (i = 0; i < _discreteData.GetLength(1); i++)
  408.                 {
  409.                     ToScreen(_discreteData[0, i], _discreteData[1, i], ref sX, ref sY);
  410.                     g.DrawEllipse(Pens.Red, sX, sY, 1.5f, 1.5f);
  411.                     //if (_discreteData[2, i] >= 0.1)
  412.                     //    g.DrawString(_discreteData[2, i].ToString(_dFormat), drawFont, drawBrush, sX, sY);
  413.                 }
  414.             }
  415.             if (CB_GridData && _gridData != null)
  416.             {
  417.                 for (i = 0; i < _gridData.GetLength(0); i++)
  418.                 {
  419.                     for (j = 0; j < _gridData.GetLength(1); j++)
  420.                     {
  421.                         ToScreen(_X[j], _Y[i], ref sX, ref sY);
  422.                         if (!DoubleEquals(_gridData[i, j], _undefData))
  423.                         {
  424.                             g.DrawEllipse(Pens.Red, sX, sY, 1.5f, 1.5f);
  425.                             //if (_gridData[i, j] >= 0.1)
  426.                             g.DrawString(_gridData[i, j].ToString(_dFormat), drawFont, drawBrush, sX, sY);
  427.                             //g.DrawString(i.ToString() + "," + j.ToString(), drawFont, drawBrush, sX, sY);
  428.                         }
  429.                         else
  430.                             g.DrawEllipse(Pens.Gray, sX, sY, 1.5f, 1.5f);
  431.                     }
  432.                 }
  433.             }

  434.             //Draw stream lines
  435.             if (_streamLines.Count > 0)
  436.             {
  437.                 for (i = 0; i < _streamLines.Count; i++)
  438.                 {
  439.                     aline = _streamLines[i];
  440.                     aValue = aline.Value;
  441.                     newPList = aline.PointList;

  442.                     PointF[] fPoints = new PointF[newPList.Count];
  443.                     float fX = 0, fY = 0;
  444.                     for (j = 0; j < newPList.Count; j++)
  445.                     {
  446.                         aPoint = (wContour.PointD)newPList[j];
  447.                         ToScreen(aPoint.X, aPoint.Y, ref fX, ref fY);
  448.                         fPoints[j] = new PointF(fX, fY);
  449.                     }
  450.                     aPen = new Pen(Color.Blue);
  451.                     g.DrawLines(aPen, fPoints);

  452.                     int len = 12;
  453.                     for (j = 0; j < fPoints.Length; j++)
  454.                     {
  455.                         if (j > 0 && j < fPoints.Length - 2 && j % len == 0)
  456.                         {
  457.                             //Draw arraw
  458.                             PointF aP = fPoints[j];
  459.                             PointF bPoint = fPoints[j + 1];

  460.                             DrawArrowYaq(g, aP, bPoint);

  461.                             //double U = bPoint.X - aP.X;
  462.                             //double V = bPoint.Y - aP.Y;
  463.                             //double angle = Math.Atan((V) / (U)) * 180 / Math.PI;
  464.                             //angle = angle + 90;
  465.                             //if (U < 0)
  466.                             //    angle = angle + 180;

  467.                             //if (angle >= 360)
  468.                             //    angle = angle - 360;

  469.                             //PointF[] apoints = new PointF[3];
  470.                             //PointF eP1 = new PointF();
  471.                             //double aSize = 8;
  472.                             //eP1.X = (int)(aP.X - aSize * Math.Sin((angle + 20.0) * Math.PI / 180));
  473.                             //eP1.Y = (int)(aP.Y + aSize * Math.Cos((angle + 20.0) * Math.PI / 180));
  474.                             //apoints[0] = eP1;
  475.                             //apoints[1] = aP;
  476.                             ////g.DrawLine(aPen, aP, eP1);

  477.                             //PointF eP2 = new PointF();
  478.                             //eP2.X = (int)(aP.X - aSize * Math.Sin((angle - 20.0) * Math.PI / 180));
  479.                             //eP2.Y = (int)(aP.Y + aSize * Math.Cos((angle - 20.0) * Math.PI / 180));
  480.                             ////g.DrawLine(aPen, aP, eP1);
  481.                             //apoints[2] = eP2;
  482.                             //g.DrawLines(aPen, apoints);
  483.                         }
  484.                     }
  485.                 }
  486.             }

  487.             //Draw map lines
  488.             if (_mapLines.Count > 0)
  489.             {
  490.                 for (i = 0; i < _mapLines.Count; i++)
  491.                 {
  492.                     newPList = _mapLines[i];

  493.                     Points = new Point[newPList.Count];
  494.                     for (j = 0; j <= newPList.Count - 1; j++)
  495.                     {
  496.                         aPoint = newPList[j];
  497.                         ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  498.                         Points[j] = new Point(sX, sY);
  499.                     }
  500.                     aPen = new Pen(Color.Black);
  501.                     aPen.Color = Color.Black;
  502.                     g.DrawLines(aPen, Points);
  503.                     //g.DrawString("0", new Font("Arial", 8), new SolidBrush(Color.Black), Points[0]);
  504.                 }
  505.             }

  506.             //---- Draw legend
  507.             if (CB_ContourPolygon)
  508.             {
  509.                 if (_legendPolygons.Count > 0)
  510.                 {
  511.                     wContour.Legend.lPolygon aLPolygon = default(wContour.Legend.lPolygon);
  512.                     SolidBrush aBrush = new SolidBrush(Color.Black);
  513.                     for (i = 0; i < _legendPolygons.Count; i++)
  514.                     {
  515.                         aLPolygon = _legendPolygons[i];
  516.                         aValue = aLPolygon.value;
  517.                         if (aLPolygon.isFirst)
  518.                         {
  519.                             aColor = _colors[0];
  520.                         }
  521.                         else
  522.                         {
  523.                             aColor = _colors[Array.IndexOf(_CValues, aValue) + 1];
  524.                         }
  525.                         newPList = aLPolygon.pointList;

  526.                         Points = new Point[newPList.Count];
  527.                         for (j = 0; j <= newPList.Count - 1; j++)
  528.                         {
  529.                             aPoint = newPList[j];
  530.                             ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  531.                             Points[j] = new Point(sX, sY);
  532.                         }
  533.                         aBrush.Color = aColor;
  534.                         g.FillPolygon(aBrush, Points);
  535.                         g.DrawPolygon(Pens.Black, Points);

  536.                         Point sPoint = Points[2];
  537.                         if (i < _legendPolygons.Count - 1)
  538.                         {
  539.                             g.DrawString(_CValues[i].ToString("0.0"), drawFont, Brushes.Black, sPoint.X - 10, sPoint.Y - 15);
  540.                         }
  541.                     }
  542.                 }
  543.             }
  544.             //PctureBox1.Image.Save("123.png", System.Drawing.Imaging.ImageFormat.Png);
  545.             //g.Save(
  546.         }

  547.         private static bool DoubleEquals(double a, double b)
  548.         {
  549.             if (Math.Abs(a - b) < 0.000001)
  550.                 return true;
  551.             else
  552.                 return false;
  553.         }


  554.         private float DrawArrowYaq(Graphics GR, PointF p0, PointF p1)
  555.         {


  556.             double dX = p0.X - p1.X;
  557.             double dY = p0.Y - p1.Y;
  558.             double X = p0.X - (dX / 2);
  559.             double Y = p0.Y - (dY / 2);
  560.             float Angle = getAngleYaq(dX, dY);

  561.             RectangleF R = new RectangleF((float)X - 4, (float)Y - 4, 8, 8);

  562.             // Rectangle.r
  563.             //   GR.DrawLine(Pens.Black, SC.TraceFrom, SC.TraceTo);
  564.             //   GR.FillEllipse(Brushes.Red, R);
  565.             //   return;

  566.             float xMid = (float)X;
  567.             float yMid = (float)Y;
  568.             //R = new RectangleF(xMid - 4, yMid - 3, 8, 6);
  569.             PointF[] pt = new PointF[5];
  570.             pt[0] = new PointF(R.X, R.Y);
  571.             pt[1] = new PointF(R.Right, R.Top + (R.Height / 2));
  572.             pt[2] = new PointF(R.Left, R.Bottom);
  573.             pt[3] = new PointF(R.Left + R.Width / 2, pt[1].Y);
  574.             pt[4] = pt[0];

  575.             //      g.DrawLine(Pens.Red, 0, yMid, this.Width, yMid);
  576.             //      g.DrawLine(Pens.Red, xMid, 0, xMid, this.Height);
  577.             //the central point of the rotation
  578.             Matrix Mx = GR.Transform;
  579.             GR.TranslateTransform(xMid, yMid);
  580.             //rotation procedure
  581.             // GR.RotateTransform(Angle + 90);

  582.             Angle = 180 - Angle;
  583.             GR.RotateTransform(-Angle);

  584.             GR.TranslateTransform(-xMid, -yMid);



  585.             GR.FillPolygon(Brushes.Black, pt);
  586.             GR.ResetTransform();
  587.             return Angle;
  588.             //      GR.Transform = Mx;


  589.         }
  590.         public static float getAngleYaq(double uValue, double vValue)
  591.         {
  592.             float angle = (float)(Math.Atan(vValue / uValue) * 180 / Math.PI);
  593.             if (uValue < 0)
  594.             {
  595.                 angle -= 180;
  596.             }
  597.             return angle;
  598.         }

  599.         private void DrawPolygon(Graphics g, Polygon aPolygon, bool isHighlight)
  600.         {
  601.             int j;
  602.             PolyLine aline = aPolygon.OutLine;
  603.             double aValue = aPolygon.LowValue;
  604.             Color aColor = _colors[Array.IndexOf(_CValues, aValue) + 1];
  605.             if (isHighlight)
  606.                 aColor = Color.Green;
  607.             else
  608.             {
  609.                 if (!aPolygon.IsHighCenter)
  610.                 {
  611.                     for (j = 0; j <= _colors.Length - 1; j++)
  612.                     {
  613.                         if (aColor == _colors[j])
  614.                         {
  615.                             aColor = _colors[j - 1];
  616.                         }
  617.                     }
  618.                 }
  619.             }
  620.             List<PointD> newPList = aline.PointList;
  621.             //if (!Contour.IsClockwise(newPList))
  622.             //    newPList.Reverse();

  623.             Point[] Points = new Point[newPList.Count];
  624.             int sX = 0, sY = 0;
  625.             for (j = 0; j <= newPList.Count - 1; j++)
  626.             {
  627.                 PointD aPoint = newPList[j];
  628.                 ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  629.                 Points[j] = new Point(sX, sY);
  630.             }

  631.             GraphicsPath bPath = new GraphicsPath();
  632.             GraphicsPath aPath = new GraphicsPath();
  633.             aPath.AddPolygon(Points);
  634.             bPath.AddLines(Points);
  635.             //Region aRegion = new Region(aPath);
  636.             if (aPolygon.HasHoles)
  637.             {
  638.                 for (int h = 0; h < aPolygon.HoleLines.Count; h++)
  639.                 {
  640.                     newPList = aPolygon.HoleLines[h].PointList;
  641.                     //if (Contour.IsClockwise(newPList))
  642.                     //    newPList.Reverse();
  643.                     Points = new Point[newPList.Count];
  644.                     for (j = 0; j <= newPList.Count - 1; j++)
  645.                     {
  646.                         PointD aPoint = newPList[j];
  647.                         ToScreen(aPoint.X, aPoint.Y, ref sX, ref sY);
  648.                         Points[j] = new Point(sX, sY);
  649.                     }
  650.                     //aPath = new GraphicsPath();
  651.                     aPath.AddPolygon(Points);
  652.                     GraphicsPath cPath = new GraphicsPath();
  653.                     cPath.AddLines(Points);
  654.                     bPath.AddPath(cPath, false);
  655.                     //aRegion.Xor(aPath);
  656.                 }
  657.             }

  658.             Pen aPen = new Pen(Color.Black);
  659.             aPen.Color = aColor;
  660.             SolidBrush aBrush = new SolidBrush(Color.Black);
  661.             aBrush.Color = aColor;
  662.             g.FillPath(aBrush, aPath);
  663.             g.DrawPath(Pens.Black, bPath);
  664.         }

  665.     }
  666.    
  667. }
复制代码
这是我把你的代码copy出来,生成一个类,测试调用方法
  1.         private void DrawLine()
  2.         {
  3.             int layer = 0;
  4.             Int16 element_type = Convert.ToInt16(this.comboBox3.SelectedItem);
  5.             HHKJ.CloudMap.CloudHeader head = new HHKJ.CloudMap.CloudHeader();
  6.             short _Width = 3000;
  7.             short _Height = 3000;

  8.             head.E0 = 140.7;
  9.             head.Prjct = 'E';
  10.             head.Width = _Width;
  11.             head.Height = _Height;
  12.             head.MaxLat = fhead.Latitude;
  13.             head.MaxLon = fhead.Longitude + fhead.Longitudinal * fhead.Intervals_long;
  14.             head.MinLat = fhead.Latitude - fhead.Latitudinal * fhead.Intervals_lat;
  15.             head.MinLon = fhead.Longitude;
  16.             head.Space = 1.25;
  17.             HHKJ.CloudMap.CloudToImage cloud = new HHKJ.CloudMap.CloudToImage();
  18.             cloud.CldHeader = head;
  19.             cloud.Grap = Grap;

  20.             for (int i = 0; i < fhead.Stored; i++)
  21.             {
  22.                 if (e_type[i].E_type == Convert.ToInt16(this.comboBox1.SelectedItem) && e_type[i].Storage == element_type)
  23.                 {
  24.                     layer = i;
  25.                     break;
  26.                 }
  27.             }
  28.             this.pictureBox1.Width = _Width;
  29.             this.pictureBox1.Height = _Height;
  30.             line = new LineContour();
  31.             line._startColor = Color.Yellow;
  32.             line._endColor = Color.Red;

  33.             line.ClearObjects();
  34.             line.PictureBox1 = this.pictureBox1;
  35.             //line.CreateGridData(fhead.Latitudinal, fhead.Longitudinal);

  36.             line.SetCoordinate(-10, pictureBox1.Width, -10, pictureBox1.Height);
  37.             fhead.Latitudinal = 20;
  38.             fhead.Longitudinal = 20;
  39.             line._gridData = new double[fhead.Latitudinal, fhead.Longitudinal];
  40.             double[] _X = new double[fhead.Longitudinal];
  41.             double[] _Y = new double[fhead.Latitudinal];

  42.             double XDelt = this.pictureBox1.Width / fhead.Longitudinal;
  43.             double YDelt = this.pictureBox1.Height / fhead.Latitudinal;
  44.             for (int i = 0; i <= fhead.Longitudinal - 1; i++)
  45.             {
  46.                 _X[i] = i * XDelt;
  47.             }
  48.             for (int i = 0; i <= fhead.Latitudinal - 1; i++)
  49.             {
  50.                 _Y[i] = i * YDelt;
  51.             }


  52.             for (int j = 0; j < fhead.Latitudinal; j++)
  53.             {
  54.                 for (int i = 0; i < fhead.Longitudinal; i++)
  55.                 {
  56.                     line._gridData[j, i] = e_type[layer].Reference + fdata[layer + 66 * this.comboBox2.SelectedIndex].Data[j, i] / (float)e_type[layer].Factor - 273.15f;
  57.                 }
  58.             }
  59.             //for (int j = 0; j < fhead.Latitudinal; j++)
  60.             //{
  61.             //    PointF pf = cloud.LaLoToXY(head, fhead.Latitude - j * fhead.Intervals_lat, fhead.Longitude );
  62.             //    _Y[j] = pf.Y;
  63.             //}
  64.             //for (int i = 0; i < fhead.Longitudinal; i++)
  65.             //{
  66.             //    PointF pf = cloud.LaLoToXY(head, fhead.Latitude , fhead.Longitude + i * fhead.Intervals_long);
  67.             //    _X[i] = pf.X;
  68.             //}
  69.             line.SetStation(_X, _Y);
  70.             double[] values = new double[] {-20,-10,0,10, 20,30,40,50,60,70,80,90,300 ,500};
  71.             line.SetContourValues(values);
  72.             line.TracingContourLines();
  73.             line.SmoothLines();
  74.             line.GetEcllipseClipping();
  75.             line.ClipLines();
  76.             line.TracingPolygons();
  77.             line.ClipPolygons();      
  78.             line._dFormat = "0";


  79.             line.CreateLegend();

  80.             line.CB_GridData = true;
  81.             line.CB_ContourLine = true;
  82.             line.CB_ContourPolygon = false;
  83.             //Bitmap bmp = new Bitmap(_Width, _Height, PixelFormat.Format24bppRgb);
  84.             //Grap = Graphics.FromImage(bmp);
  85.             //Grap.Clear(Color.White);
  86.             //line.PaintGraphics(Grap);

  87.             //pictureBox1.Image = bmp;
  88.             pictureBox1.Refresh();
  89.             //bmp.Save("123.png" ,ImageFormat.Png);
  90.         }
复制代码


密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-23 22:15:18 | 显示全部楼层
rainfull 发表于 2015-12-23 22:08
这是我把你的代码copy出来,生成一个类,测试调用方法

我没时间帮你调程序,Demo程序已经很清楚了,自己研究吧。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表