- 积分
- 2231
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-11-1
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-8-10 12:54:11
|
显示全部楼层
本帖最后由 gengnj 于 2014-8-10 12:56 编辑
private void ReadD4Data(string str4filename)
{
int i = 0;
int j = 0;
int rows = 0;
int cols = 0;
double[,] DataArray = null;
double LonDelt = 0.0;
double LatDelt = 0.0;
double LonStart = 0.0;
double LatStart = 0.0;
double LonEnd = 0.0;
double LatEnd = 0.0;
double Xlb = 0.0;
double Ylb = 0.0;
double Xrt = 0.0;
double Yrt = 0.0;
double XDelt = 0.0;
double YDelt = 0.0;
string alltext = File.ReadAllText(str4filename, System.Text.Encoding.Default);
string[] strs = alltext.Split(" \n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string msg = strs[2];//12年5月22日20点ECMWF_海平面气压23日20点预报
//设置线条颜色
LineColor = Color.Black;
if ((msg.Contains("高度"))||(msg.Contains("变高")))
{
LineColor = Color.Blue;
}
if ((msg.Contains("温度")) || (msg.Contains("变温")))
{
LineColor = Color.Red;
}
if (msg.Contains("湿度"))
{
LineColor = Color.Green;
}
string year = strs[3];
string month = strs[4];
string day = strs[5];
string hour = strs[6];
string validtime = strs[7];//预报时效
string height = strs[8];//高度层
//经纬度格距
LonDelt = Convert.ToSingle(strs[9]);
// MessageBox.Show(strs[10].IndexOf('.').ToString() + "," + strs[10].LastIndexOf('.').ToString());
// 数据容错处理
//12 5 12 20 24 850 2.500 2.500-180.000 180.000 0.000 90.000 145 37
if (strs[10].IndexOf('.') != strs[10].LastIndexOf('.'))
{
LatDelt = Convert.ToSingle(strs[10].Substring(0, strs[10].IndexOf('-')-1));
LonStart = Convert.ToSingle(strs[10].Substring(strs[10].IndexOf('-'), strs[10].Length - strs[10].IndexOf('-')));
LonEnd = Convert.ToSingle(strs[11]);
LatStart = Convert.ToSingle(strs[12]);
LatEnd = Convert.ToSingle(strs[13]);
//经纬度格点个数
cols = Convert.ToInt32(strs[14]);
rows = Convert.ToInt32(strs[15]);
}
else// 规范数据格式
{
LatDelt = Convert.ToSingle(strs[10]);
//起始结束经纬度
LonStart = Convert.ToSingle(strs[11]);
LonEnd = Convert.ToSingle(strs[12]);
LatStart = Convert.ToSingle(strs[13]);
LatEnd = Convert.ToSingle(strs[14]);
//经纬度格点个数
cols = Convert.ToInt32(strs[15]);
rows = Convert.ToInt32(strs[16]);
//等值线间隔、起始、终止值
float fDelta = Convert.ToSingle(strs[17]);
float fStartValue = Convert.ToSingle(strs[18]);
float fEndValue = Convert.ToSingle(strs[19]);
//平滑系数、加粗线值
float fFlatFactor = Convert.ToSingle(strs[20]);
float fBoldValue = Convert.ToSingle(strs[21]);
}
DataArray = new double[rows, cols];
_X = new double[cols];
_Y = new double[rows];
XDelt = LonDelt;
YDelt = LatDelt;
for (i = 0; i <= cols - 1; i++)
{
_X = i * XDelt;
}
for (i = 0; i <= rows - 1; i++)
{
_Y = i * YDelt;
}
string strcontent = File.ReadAllText(str4filename, System.Text.Encoding.Default);
// MessageBox.Show(strcontent);
string[] stritemdata = strcontent.Split(" \n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
// MessageBox.Show(rows.ToString());
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
//12 5 12 20 24 999 2.500 2.500-180.000 180.000 0.000 90.000
if (strs[10].IndexOf('.') != strs[10].LastIndexOf('.'))//这个条件判定主要是容错
{
DataArray[i, j] = Convert.ToDouble(stritemdata[21 + (i * cols) + j]);
}
else
{
DataArray[i, j] = Convert.ToDouble(stritemdata[22 + (i * cols) + j]);
}
// if (i == 0)
// MessageBox.Show(DataArray[i, j].ToString());
}
}
_gridData = DataArray;
}
private void TracingContourLineMD4(string str4filename)//private void TracingContourLines()
{
// MessageBox.Show(str4filename);
//---- Contour values
int nc = 0;
double m_CStart = 0.0;//画图起始等值线
double m_CEnd = 0.0;//画图结束等值线值
double m_CStep = 0.0;//画图等值线间隔步长
string alltext = File.ReadAllText(str4filename, System.Text.Encoding.Default);
string[] strs = alltext.Split(" \n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
//等值线间隔、起始、终止值
m_CStep = Convert.ToDouble(strs[17]);
m_CStart = Convert.ToDouble(strs[18]);
m_CEnd = Convert.ToDouble(strs[19]);
int cn = (int)(Math.Ceiling((m_CEnd - m_CStart) / m_CStep));
_CValues=new double[cn+1];
for (int i = 0; i < cn ; i++)
{
_CValues = m_CStart + i * m_CStep;
}
_CValues[cn] = m_CEnd;
nc = _CValues.Length;
//---- Colors
_colors= CreateColors(_startColor, _endColor, nc + 1);
double XDelt = 0;
double YDelt = 0;
XDelt = _X[1] - _X[0];
YDelt = _Y[1] - _Y[0];
int[,] S1 = new int[1, 1];
_borders = Contour.TracingBorders(_gridData, _X, _Y, ref S1, _undefData);
_contourLines = Contour.TracingContourLines(_gridData, _X, _Y, nc, _CValues, _undefData, _borders, S1);
}
private Color[] CreateColors(Color sColor, Color eColor, int cNum)
{
Color[] colors = new Color[cNum];
int sR = 0;
int sG = 0;
int sB = 0;
int eR = 0;
int eG = 0;
int eB = 0;
int rStep = 0;
int gStep = 0;
int bStep = 0;
int i = 0;
sR = sColor.R;
sG = sColor.G;
sB = sColor.B;
eR = eColor.R;
eG = eColor.G;
eB = eColor.B;
rStep = Convert.ToInt32((eR - sR) / cNum);
gStep = Convert.ToInt32((eG - sG) / cNum);
bStep = Convert.ToInt32((eB - sB) / cNum);
for (i = 0; i <= colors.Length - 1; i++)
{
colors = Color.FromArgb(sR + i * rStep, sG + i * gStep, sB + i * bStep);
}
return colors;
}
protected override void doRender(System.Drawing.Graphics g, Gengjj.Micaps.Coordinates.ICoordinate Coord)
{
// MessageBox.Show("R");
// this.axMap1.Refresh();
// g.SmoothingMode = Style.SmoothingMode;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = Style.TextRenderingHint;
ReadD4Data(LoadParam);
TracingContourLineMD4(LoadParam);
int i = 0;
int j = 0;
wContour.PolyLine aline = default(wContour.PolyLine);
List<PointD> newPList = new List<PointD>();
double aValue = 0;
Color aColor = default(Color);
Pen aPen = default(Pen);
wContour.PointD aPoint = default(wContour.PointD);
// Point[] Points = null;
PointF[] Pointfs = null;//经纬度坐标点
// PointF[] Pointfs_end = null;
PointF[] PointProjfs = null;//经纬度转换为投影坐标后的坐标点
int sX = 0;
int sY = 0;
// TracingContourLineMD4(LoadParam);//for micaps 4
// SmoothLines();
// TracingPolygons();//填充颜色用,可以去掉
////处理结束
//if (m_FillColor == false)
// {
List<PolyLine> drawLines = _contourLines;
MessageBox.Show(_contourLines.Count.ToString());
for (i = 0; i <=drawLines.Count - 1; i++)
{
//MessageBox.Show("J");
aline =drawLines;
aValue = aline.Value;
//确定本条等值线的颜色 下面这条语句造成各条线为渐变色
aColor = _colors[Array.IndexOf(_CValues, aValue)];
newPList = aline.PointList;
//此处点为经纬度坐标
// Points = new Point[newPList.Count];
Pointfs = new PointF[newPList.Count];
PointProjfs = new PointF[newPList.Count];//经过投影后的屏幕坐标
// Pointfs_end = new PointF[newPList.Count];
PointF pt_begin = new PointF();
PointF pt_end = new PointF();
for (j = 0; j <= newPList.Count - 1; j++)
{
aPoint = (wContour.PointD)newPList[j];
// Points[j] = new Point((int)aPoint.X, (int)aPoint.Y);
Pointfs[j] = new PointF((float)aPoint.X, (float)aPoint.Y);
PointProjfs[j] = Coord.WorldToScreen(Pointfs[j]);
if (j == 0)
pt_begin = PointProjfs[j];
if (j == newPList.Count - 1)
pt_end = PointProjfs[j];
// Point ab1 = Point.Round(abFloat);
// Points[j] = Point.Round(Pointfs[j]);
}
//设置等值线画线颜色
aPen = new Pen(Color.Black);
//等值线颜色为渐变色
aPen.Color = aColor;
//等值线颜色为单一色
aPen.Color = LineColor;
//e.Graphics.DrawLines(aPen, Points);
g.DrawLines(aPen, PointProjfs);
// g.DrawLines(aPen, Pointfs_end);
Font drawFont = new Font("Arial", 8);
//设置标注线条数值的颜色
SolidBrush drawBrush = new SolidBrush(LineColor); //new SolidBrush(Color.Red);
}
}
} |
|