- 积分
- 418
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-8-4
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2013-2-3 14:28:47
|
显示全部楼层
本帖最后由 记忆碎片 于 2013-2-3 14:31 编辑
MeteoInfo 发表于 2013-2-3 10:10
看了一下,你的数据其实是格点数据,建议你把它改成格点数据格式,比如GrADS的二进制,或者简单的Surfer文 ...
果然是问题出在插值参数设置上,按照上述的代码,将差值部分代码修改为下示代码,插值后效果好多了就。
代码:
- /// <summary>
- /// 需要原文件格式“stationID,Longitude,Latitude,Value”
- /// </summary>
- /// <param name="_targetLayersLegend"></param>
- /// <param name="_targetMapLayout"></param>
- /// <param name="fileSource"></param>
- public static void DrawStationShadedNew(LayersLegend _targetLayersLegend,MapLayout _targetMapLayout,string fileSource)
- {
- //Read data info
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- string aFile = fileSource;
- aDataInfo.OpenLonLatData(aFile);
- //Get station data
- StationData stationData = aDataInfo.GetStationData("Value");
- //Interpolate
- GridDataSetting aGDP = new GridDataSetting();
- aGDP.DataExtent.minX = 121;//x最小值
- aGDP.DataExtent.maxX = 122;//x最大值
- aGDP.DataExtent.minY = 28;//y最小值
- aGDP.DataExtent.maxY = 29;//y最大值
- aGDP.XNum = 81;//列数
- aGDP.YNum = 81;//行数
- InterpolationSetting gridInterp = new InterpolationSetting();
- gridInterp.GridDataSet = aGDP;
- gridInterp.InterpolationMethod = InterpolationMethods.IDW_Neighbors;//差值方法
- gridInterp.Radius = 3;//差值半径
- gridInterp.MinPointNum = 1;
- double[] X = new double[1];
- double[] Y = new double[1];
- ContourDraw.CreateGridXY(gridInterp.GridDataSet, ref X, ref Y);
- double[,] S = stationData.Data;
- S = ContourDraw.FilterDiscreteData_Radius(S, gridInterp.Radius,
- gridInterp.GridDataSet.DataExtent, stationData.UNDEF);
- GridData gridData = ContourDraw.InterpolateDiscreteData_Radius(S,
- X, Y, gridInterp.MinPointNum, gridInterp.Radius, stationData.UNDEF);
- //Create 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 = new VectorLayer(ShapeTypes.Polygon);
- aLayer = DrawMeteoData.CreateShadedLayer(gridData, aLS, "Ng", "Ng");
- aLayer.IsMaskout = true;
- //Add layer
- _targetLayersLegend.ActiveMapFrame.AddLayer(aLayer);
- _targetLayersLegend.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
- _targetLayersLegend.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = _targetMapLayout.GetTexts()[0];
- aTitle.SetLabelText("Station Ng Layer");
- //Add or change the legend in layout
- LayoutLegend aLegend;
- if (_targetMapLayout.GetLegends().Count > 0)
- aLegend = _targetMapLayout.GetLegends()[0];
- else
- aLegend = _targetMapLayout.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
- aLegend.LegendLayer = aLayer;
- //if (tabControl1.SelectedIndex == 1)
- _targetMapLayout.PaintGraphics();
- }
插值图层后,再Maskout,然后效果图如下:
插值效果图
差值细节图
接下来的待完成工作:
1 自动化找到数据中的行数、列数、经纬度最大、最小值。
等把这部分功能完成后。抽空把内容整合起来分享给大家。现在虽然方法都有了,不过太零散 呵呵 再次感谢王老师一路的指导。
|
|