public void AddShpLayer(string strVecName) { _shpFileHostLayer.AddData(strVecName, null); CodeCell.AgileMap.Core.IMap map = _shpFileHostLayer.Map as CodeCell.AgileMap.Core.IMap; CodeCell.AgileMap.Core.FeatureLayer fetL = map.LayerContainer.Layers[0] as CodeCell.AgileMap.Core.FeatureLayer; _curShpLayerName = fetL.Name; SimpleMarkerSymbol sym = new SimpleMarkerSymbol(masSimpleMarkerStyle.Circle); sym.Size = new System.Drawing.Size(4, 4); fetL.Renderer = new SimpleFeatureRenderer(sym); CodeCell.AgileMap.Core.FeatureClass fetc = fetL.Class as CodeCell.AgileMap.Core.FeatureClass; CodeCell.AgileMap.Core.Envelope evp = fetc.FullEnvelope.Clone() as CodeCell.AgileMap.Core.Envelope; GeoDo.RSS.Core.DrawEngine.CoordEnvelope cvEvp = new GeoDo.RSS.Core.DrawEngine.CoordEnvelope(evp.MinX, evp.MaxX, evp.MinY, evp.MaxY); this.canvasHost1.Canvas.CurrentEnvelope = cvEvp; this.canvasHost1.Canvas.Refresh(enumRefreshType.All); }
public SimpleVectorObjectHost(string name, ICanvas canvas, string[] fieldNames) { if (fieldNames != null) { _fldNames = fieldNames; } _canvas = canvas; _mapRuntime = (_canvas.LayerContainer.VectorHost as IVectorHostLayer).MapRuntime as IMapRuntime; _datasource = new CodeCell.AgileMap.Core.MemoryDataSource(name, enumShapeType.Polygon, _fldNames); CodeCell.AgileMap.Core.IFeatureClass fetClass = new CodeCell.AgileMap.Core.FeatureClass(_datasource); CodeCell.AgileMap.Core.IFeatureLayer fetLayer = new CodeCell.AgileMap.Core.FeatureLayer(name, fetClass); _layer = fetLayer; IMap map = (_canvas.LayerContainer.VectorHost as IVectorHostLayer).Map as IMap; if (map != null) { map.LayerContainer.Append(fetLayer); } SetLabel(fetLayer); SetRenderer(fetLayer); }
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); } } }