- 积分
- 16498
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-8-18
- 最后登录
- 1970-1-1
|
发表于 2014-6-13 16:39:47
|
显示全部楼层
不知道lz最后解决了没有,以下是自己钻研的结果,可以实现,但是不美观,希望对lz有用
private void TSMI_StationShaded_Click(object sender, EventArgs e)
{
// //connect database
SqlConnection con = new SqlConnection(@"server=10.115.144.3;database=aws2014;uid=sa;pwd=qxt2713929");
string cmd = @"select b.经度,b.纬度,a.区站号,a.RR from dbo.日降水 as a
inner join dbo.台站参数 as b
on a.区站号=b.区站号
where b.地市名='怀化' and a.观测时间='2014-06-02'";
SqlDataAdapter sda = new SqlDataAdapter(cmd, con);
DataTable dt = new DataTable();
sda.Fill(dt);
//
this.Cursor = Cursors.WaitCursor; //就是鼠标样式变成了等待的样式
//read data info
MeteoDataInfo aDataInfo = new MeteoDataInfo();
string aFile = Application.StartupPath + @"\Sample\rain1_2008072220.csv";
aDataInfo.OpenLonLatData(aFile);
////Get station data
//StationData stationData = aDataInfo.GetStationData("Precipitation6h");
StationData stationData = new StationData();
stationData.Data = new double[3, dt.Rows.Count];
stationData.Stations=new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
stationData.Data[0, i] = Convert.ToDouble(dt.Rows[i][0]);
stationData.Data[1, i] = Convert.ToDouble(dt.Rows[i][1]);
stationData.Data[2, i] = Convert.ToDouble(dt.Rows[i][3]);
stationData.Stations.Add(dt.Rows[i][2].ToString());
}
//Interpolate 插值
GridDataSetting aGDP = new GridDataSetting();//老版本为GridDataPara
aGDP.DataExtent.minX = 60;
aGDP.DataExtent.maxX = 140;
aGDP.DataExtent.minY = -20;
aGDP.DataExtent.maxY = 60;
aGDP.XNum = 180;
aGDP.YNum = 180;
//GridInterpolation类已修改为InterpolationSetting类
InterpolationSetting interpS = new InterpolationSetting();
interpS.GridDataSet = aGDP; // original line:gridInterp.GridDataParaV = aGDP;
interpS.InterpolationMethod = InterpolationMethods.IDW_Radius;//原语句为gridInterp.GridInterMethodV = GridInterMethod.IDW_Radius;
interpS.Radius = 2;
interpS.MinPointNum = 1;
double[] X = new double[1];
double[] Y = new double[1];
ContourDraw.CreateGridXY(aGDP, ref X, ref Y); //添加using MeteoInfoC.Drawing;
double[,] S = stationData.Data;
S = ContourDraw.FilterDiscreteData_Radius(S, interpS.Radius, interpS.GridDataSet.DataExtent, stationData.MissingValue);
//original line: S = ContourDraw.FilterDiscreteData_Radius(S, gridInterp.Radius,gridInterp.GridDataParaV.dataExtent, stationData.UNDEF);
GridData gridData = ContourDraw.InterpolateDiscreteData_Radius(S, X, Y, interpS.MinPointNum, interpS.Radius, stationData.MissingValue);
//cteate legend scheme
bool hasNoData = true;
LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(gridData, LegendType.GraduatedColor, ShapeTypes.Polygon, ref hasNoData);
((PolygonBreak)aLS.LegendBreaks[0]).DrawFill = false;
//create layer
VectorLayer aLayer = DrawMeteoData.CreateShadedLayer(gridData, aLS, "Rain", "Rain");
aLayer.IsMaskout = true;//????????????????
//add layer
layersLegend1.ActiveMapFrame.AddLayer(aLayer);
layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
layersLegend1.Refresh();
//change title
LayoutGraphic title = mapLayout1.GetTexts()[0];
title.SetLabelText("MeteoInfo Class Library Demo - Station data shaded layer");
//add or change legend
LayoutLegend aLegend;
if (mapLayout1.GetLegends().Count > 0) aLegend = mapLayout1.GetLegends()[0];
else aLegend = mapLayout1.AddLegend(650, 100);
aLegend.LegendStyle = LegendStyles.Bar_Vertical;
aLegend.LegendLayer = aLayer;
if (tabControl1.SelectedIndex == 1)
{
mapLayout1.PaintGraphics();
}
this.Cursor = Cursors.Default;
}
|
|