private void DoGenerateContourLines(ICanvas canvas, double resX, double resY, frmPointContour.ContourItem[] contourItems, bool isNeedDisplay, bool isNeedLabel, IDW_Interpolation interpolate, string shpFileName) { IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; try { progress.Reset("正在生成等值线...", 100); progress.Start(false); ContourGenerateTool tool = new ContourGenerateTool(); double[] cvs = ToContourValues(contourItems); ContourLine[] cntLines = tool.Generate(resX, resY, enumDataType.Float, cvs, interpolate, (idx, tip) => { progress.Boost(idx, tip); }); if (cntLines == null || cntLines.Length == 0) { MsgBox.ShowInfo("不存在符合指定条件的等值线!"); return; } double dMinX = interpolate.CoordPointXArr.Min(); double dMaxY = interpolate.CoordPointYArr.Max(); for (int i = 0; i < cntLines.Count(); i++) { ContourLine cntLine = cntLines[i]; ContourLine newCntLine = new ContourLine(cntLine.ContourValue); PointF[] pts = cntLine.Points; for (int j = 0; j < pts.Count(); j++) { pts[j].X = Convert.ToSingle(dMinX + resX * pts[j].X); pts[j].Y = Convert.ToSingle(dMaxY - resY * pts[j].Y); } newCntLine.AddPoints(pts); newCntLine.UpdateEnvelope(); cntLines[i] = newCntLine; } if (shpFileName != null) { TryExport2ShapeFile(canvas, cntLines, shpFileName, progress, isNeedDisplay); } if (isNeedDisplay) { TryDisplay(cntLines, contourItems, isNeedLabel); } } finally { progress.Finish(); } }
public override void Execute(string argument) { //判断当前视图中显示的数据,如果没有点状矢量数据,则返回 ICanvasViewer viewer = _smartSession.SmartWindowManager.ActiveCanvasViewer; if (viewer == null) { return; } ICanvas canvas = viewer.Canvas; if (canvas == null) { return; } IVectorHostLayer vectorHost = canvas.LayerContainer.VectorHost; if (vectorHost == null) { return; } Map map = vectorHost.Map as Map; if (map == null) { return; } CodeCell.AgileMap.Core.ILayer[] layers = map.LayerContainer.Layers; if (layers == null || layers.Length == 0) { return; } CodeCell.AgileMap.Core.FeatureLayer fetL = null; CodeCell.AgileMap.Core.FeatureClass fetc = null; int nCount = 0; for (nCount = 0; nCount < layers.Length; nCount++) { fetL = map.LayerContainer.Layers[nCount] as CodeCell.AgileMap.Core.FeatureLayer; fetc = fetL.Class as CodeCell.AgileMap.Core.FeatureClass; if (fetc.ShapeType == enumShapeType.Point) { break; } } if (nCount == layers.Length) { MessageBox.Show("视图中未显示点状矢量数据!", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Feature[] features = fetc.GetVectorFeatures(); if (features == null || features.Length == 0) { return; } string fileName = null; IDataSource ds = fetc.DataSource as FileDataSource; if (ds != null) { fileName = (ds as FileDataSource).FileUrl; } if (ds == null) { ds = fetc.DataSource as MemoryDataSource; if (ds != null) { fileName = (ds as MemoryDataSource).Name; } } int featureCount = features.Count(); int fieldCount = fetc.FieldNames.Count(); //取出矢量数据中的字段值 Dictionary <string, ArrayList> dicFieldValues = new Dictionary <string, ArrayList>(); for (int i = 0; i < fieldCount; i++) { ArrayList fieldValues = new ArrayList(); for (int j = 0; j < featureCount; j++) { fieldValues.Add(features[j].FieldValues[i]); } dicFieldValues.Add(fetc.FieldNames[i], fieldValues); } for (int i = 0; i < fieldCount; i++) { double temp; if (double.TryParse(features[0].FieldValues[i], out temp)) { } else { dicFieldValues.Remove(features[0].FieldNames[i]); } } //先插值(插值后的点数由计算的defResX值确定)。再根据插值点生成等值线 double defResX = (fetc.FullEnvelope.MaxX - fetc.FullEnvelope.MinX) / 500; using (frmPointContour frm = new frmPointContour()) { frmPointContour.ContourItem[] contourItems = null; frm.DicFieldValues = dicFieldValues; frm.SetShpFile(fileName); bool isNeedDisplay = false; bool isNeedLabel = false; if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //获取坐标值和字段值 contourItems = frm.ContourValues; isNeedDisplay = frm.IsNeedDisplay; isNeedLabel = frm.IsNeedLabel; string selFieldName = frm.GetSelFieldName(); string shpOutFile = string.IsNullOrWhiteSpace(frm.ShpFileName) ? null : frm.ShpFileName; List <double> coordListX = new List <double>(); List <double> coordListY = new List <double>(); List <double> valueList = new List <double>(); for (int i = 0; i < featureCount; i++) { ShapePoint point = features[i].Geometry as ShapePoint; if (point == null) { continue; } coordListX.Add(point.X); coordListY.Add(point.Y); valueList.Add(Convert.ToDouble(dicFieldValues[selFieldName][i])); } //执行生成等值线的操作 IDW_Interpolation interpolation = new IDW_Interpolation(); interpolation.CoordPointXArr = coordListX.ToArray(); interpolation.CoordPointYArr = coordListY.ToArray(); interpolation.PointValueArr = valueList.ToArray(); DoGenerateContourLines(canvas, defResX, defResX, contourItems, isNeedDisplay, isNeedLabel, interpolation, shpOutFile); } } }
public override void Execute(string argument) { //判断当前视图中显示的数据,如果没有点状矢量数据,则返回 ICanvasViewer viewer = _smartSession.SmartWindowManager.ActiveCanvasViewer; if (viewer == null) { return; } ICanvas canvas = viewer.Canvas; if (canvas == null) { return; } IVectorHostLayer vectorHost = canvas.LayerContainer.VectorHost; if (vectorHost == null) { return; } Map map = vectorHost.Map as Map; if (map == null) { return; } CodeCell.AgileMap.Core.ILayer[] layers = map.LayerContainer.Layers; if (layers == null || layers.Length == 0) { return; } CodeCell.AgileMap.Core.FeatureLayer fetL = null; CodeCell.AgileMap.Core.FeatureClass fetc = null; int nCount = 0; for (nCount = 0; nCount < layers.Length; nCount++) { fetL = map.LayerContainer.Layers[nCount] as CodeCell.AgileMap.Core.FeatureLayer; fetc = fetL.Class as CodeCell.AgileMap.Core.FeatureClass; if (fetc.ShapeType == enumShapeType.Point) { break; } } if (nCount == layers.Length) { MessageBox.Show("视图中未显示点状矢量数据!", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Feature[] features = fetc.GetVectorFeatures(); if (features == null || features.Length == 0) { return; } string fileName = null; IDataSource ds = fetc.DataSource as FileDataSource; if (ds != null) { fileName = (ds as FileDataSource).FileUrl; } if (ds == null) { ds = fetc.DataSource as MemoryDataSource; if (ds != null) { fileName = (ds as MemoryDataSource).Name; } } int featureCount = features.Count(); int fieldCount = fetc.FieldNames.Count(); //取出矢量数据中的字段值 Dictionary <string, ArrayList> dicFieldValues = new Dictionary <string, ArrayList>(); for (int i = 0; i < fieldCount; i++) { ArrayList fieldValues = new ArrayList(); for (int j = 0; j < featureCount; j++) { fieldValues.Add(features[j].FieldValues[i]); } dicFieldValues.Add(fetc.FieldNames[i], fieldValues); } for (int i = 0; i < fieldCount; i++) { double temp; if (double.TryParse(features[0].FieldValues[i], out temp)) { } else { dicFieldValues.Remove(features[0].FieldNames[i]); } } //计算矢量数据坐标范围和插值后默认的分辨率大小 double coordXmin, coordXmax, coordYmin, coordYmax; canvas.CoordTransform.Prj2Geo(fetc.FullEnvelope.MinX, fetc.FullEnvelope.MinY, out coordXmin, out coordYmin); canvas.CoordTransform.Prj2Geo(fetc.FullEnvelope.MaxX, fetc.FullEnvelope.MaxY, out coordXmax, out coordYmax); coordXmin = Math.Min(coordXmin, coordXmax); coordXmax = Math.Max(coordXmin, coordXmax); coordYmin = Math.Min(coordYmin, coordYmax); coordYmax = Math.Max(coordYmin, coordYmax); double defResX = (coordXmax - coordXmin) / 1000; ////////////////////////////////////////////////////////////////////////// //插入对话框,获取selFieldName值 ////////////////////////////////////////////////////////////////////////// using (frmPointInterpolation frm = new frmPointInterpolation()) { frm.StartPosition = FormStartPosition.CenterScreen; frm.FieldNames = dicFieldValues.Keys.ToArray(); frm.ResX = defResX; frm.ResY = defResX; frm.ResXmin = (coordXmax - coordXmin) / 10000; frm.ResXmax = (coordXmax - coordXmin) / 50; frm.ResYmin = (coordYmax - coordYmin) / 10000; frm.ResYmax = (coordYmax - coordYmin) / 50; frm.OutputImg = GetOutImgName(fileName); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //获取坐标值和字段值 string selFieldName = frm.GetSelFieldName(); double resolutionX = frm.ResX; double resolutionY = frm.ResY; string outImg = frm.OutputImg; List <double> coordListX = new List <double>(); List <double> coordListY = new List <double>(); List <double> valueList = new List <double>(); double coordX, coordY; for (int i = 0; i < featureCount; i++) { ShapePoint point = features[i].Geometry as ShapePoint; if (point == null) { continue; } canvas.CoordTransform.Prj2Geo(point.X, point.Y, out coordX, out coordY); coordListX.Add(coordX); coordListY.Add(coordY); valueList.Add(Convert.ToDouble(dicFieldValues[selFieldName][i])); } IProgressMonitor progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor; if (progress != null) { progress.Reset("", 100); progress.Start(false); } //执行插值操作 IDW_Interpolation interpolation = new IDW_Interpolation(); interpolation.CoordPointXArr = coordListX.ToArray(); interpolation.CoordPointYArr = coordListY.ToArray(); interpolation.PointValueArr = valueList.ToArray(); if (fetc.SpatialReference != null) { interpolation.DoIDWinterpolation(resolutionX, resolutionY, outImg, "LDF", enumDataType.Double, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } }), fetc.SpatialReference.ToProj4String()); } else { interpolation.DoIDWinterpolation(resolutionX, resolutionY, outImg, "LDF", enumDataType.Double, new Action <int, string>((int progerss, string text) => { if (progress != null) { progress.Boost(progerss, text); } }), null); } if (progress != null) { progress.Finish(); } //对插值后影像进行渲染,并显示到当前视图中 AddRasterLayer(outImg, canvas, valueList.Min(), valueList.Max()); canvas.Refresh(enumRefreshType.All); } } }