东华理工GIS二次开发实验报告(13)
发布时间:2021-06-06
发布时间:2021-06-06
主窗体新建渲染图层菜单,并新建子菜单
C# Code
1 private void 获取渲染器信息ToolStripMenuItem_Click(object sender, EventArgs e) 2 {
3 dataoperator dataOperator = new dataoperator(axMapControl1.Map); 4 ILayer layer = dataOperator.getlayerbyname("World Cities"); 5 MessageBox.Show(MapComposer.getrendertypebylayer(layer)); 6 }
新建MapComposer类并输入以下代码 C# Code
1 using System;
2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text;
5 using ESRI.ArcGIS.esriSystem; 6 using ESRI.ArcGIS.Carto;
7 using ESRI.ArcGIS.Controls; 8 using ESRI.ArcGIS.ADF; 9 using ESRI.ArcGIS.SystemUI; 10 using ESRI.ArcGIS.Geometry; 11 using ESRI.ArcGIS.Display; 12 using ESRI.ArcGIS.Geodatabase;
13 namespace MapControlApplication1 14 {
15 class MapComposer 16 {
17 public static string getrendertypebylayer(ILayer layer) 18 {
19 if(layer == null) 20 return "获取失败";
21 IFeatureLayer ftly = (IFeatureLayer)layer; 22 IGeoFeatureLayer gftly = (IGeoFeatureLayer)layer; 23 IFeatureRenderer ftren = gftly.Renderer; 24 if(ftren is ISimpleRenderer) 25 return "ISimpleRenderer";
26 else if(ftren is IUniqueValueRenderer) 27 return "IUniqueValueRenderer"; 28 else if(ftren is IDotDensityRenderer) 29 return "IDotDensityRenderer"; 30 else if(ftren is IChartRenderer) 31 return "IChartRenderer";
32 else if(ftren is IProportionalSymbolRenderer) 33 return "IProportionalSymbolRenderer"; 34 return "未知或者获取渲染器失败"; 35 }
36 public static ISymbol getsymbolfromlayer(ILayer layer) 37 {
38 if(layer == null) 39 return null;
40 IFeatureLayer ftly = (IFeatureLayer)layer; 41 IFeatureCursor ftcs = ftly.Search(null, false); 42 IFeature ft = ftcs.NextFeature(); 43 if(ft == null) 44 return null;
45 IGeoFeatureLayer gftly = ftly as IGeoFeatureLayer; 46 IFeatureRenderer ftren = gftly.Renderer; 47 if(ftren == null) 48 return null;
49 ISymbol syb = ftren.get_SymbolByFeature(ft); 50 return syb; 51 }
52 public static bool RenderSimply(ILayer layer, IColor color) 53 {
54 if(layer == null || color == null) 55 return false;
56 ISymbol symbol = getsymbolfromlayer(layer);
上一篇:周期问题(三年级奥数)