ArcGIS Engine二次开发
目录
- 1 安装环境配置
- 2 参考资料
- 3 面向对象基础
- 3.1 接口
- 3.2 类
- 3.3 对象
- 3.4 面向对象的三大特性
- 4 对象模型图和ArcGIS Engine开发帮助
- 4.1 对象模型图(OMD)
- 5 核心UI控件
- 5.1 获取图层属性
- 5.2 添加数据
- 5.3 地图放大
- 5.4 地图缩小
- 5.5 地图漫游
- 5.5 全景视图
- 5.6 鹰眼(副视图)
- 5.7 矢量渲染
- 5.8 图层的透明度、亮度和对比度
- 5.9 对矢量数据进行属性查询
- 5.10 矢量数据空间位置查询
- 5.11 绘制缓冲区
- 5.12 在地图上画点、线和面
- 5.13 对矢量数据字段统计
- 6 栅格数据
- 6.1 读取单个栅格像元的值
- 6.2 读取任意选中的像元N*N领域的像元值
- 6.3 更改指定像元的值
- 6.4 对栅格数据进行RGB渲染
- 7 三维开发基础
1 安装环境配置
- VS高版本添加工具
打开自己的注册表编辑器:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\12.0
新建字符串值:ShellFolder和InstallDir如下
2 参考资料
D:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Diagrams
在线参考资料
3 面向对象基础
接口——类——对象
ICar——CarA——myCar
3.1 接口
新建——添加——类——接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Car
{interface Icar{string color { get; set; }void jiaShu();}
}
3.2 类
新建——添加——类——类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Car
{class carA : Icar{private string _color;public string color{get{return _color;}set{_color = value;}}public void jiaShu(){MessageBox.Show("加速中");}}
}
3.3 对象
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace Car
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){Icar car = new carA();car.color = "白色";car.jiaShu();MessageBox.Show("汽车实例化成功!!");}}
}
3.4 面向对象的三大特性
封装:把属性和方法封装在一起,使用时不用在意实现的细节,只关注结果
继承:一个对象获得另一个对象的属性和方法的过程。继承有三种形式:接口和类、接口和接口、类和类
多态:同一操作作用于不同对象,可以有不同的解释,产生不同的结果。重点是重写和重载。
4 对象模型图和ArcGIS Engine开发帮助
4.1 对象模型图(OMD)
对象模型图(Object Model Diagram),是了解和熟悉ArcGIS Engine体系框架的基础
抽象类:不能直接创建新对象,必须通过之类去继承
实例化类:不能直接创建新对象,需要通过其他类的方法或属性来创建
可创建类:唯一可以用New关键字来创建的
5 核心UI控件
Mapcontrol:显示ArcGIS支持的地图数据
Toccontrol:用来控制显示图层
Scenecontrol:用来进行三维显示
Licensecontrol:为ArcGIS Engine程序提供许可服务
ArcGIS Engine10以上许可的添加:
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
5.1 获取图层属性
//引入IFeatureLayer对应的命名空间
using ESRI.ArcGIS.Carto;private void button1_Click(object sender, EventArgs e){try{IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;//设置不显示featureLayer.Visible = false;//更新显示axMapControl1.Refresh();}catch (Exception ex){MessageBox.Show(ex.Message);}}
案例:对矢量图层的字段进行增加、删除和查找
private void button_add_Click(object sender, EventArgs e){IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass featureClass = featureLayer.FeatureClass;IFieldEdit fieldEdit = new FieldClass();fieldEdit.Name_2 = "new";fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;fieldEdit.Length_2 = 10;//添加字段函数featureClass.AddField(fieldEdit as IField);axMapControl1.Refresh();}private void button_delete_Click(object sender, EventArgs e){int fields_length;int fields_length2;IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass featureClass = featureLayer.FeatureClass;IFields fields = featureClass.Fields;//获取图层的字段数fields_length = fields.FieldCount;//输出字段数MessageBox.Show(fields_length.ToString());IField field = fields.get_Field(fields_length - 1);//直接删除最后一个字段featureClass.DeleteField(field);fields_length2 = fields.FieldCount;//输出修改后的字段数MessageBox.Show(fields_length2.ToString());}
读取相应字段的属性值
IFeatureLayer feature = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass featureClass = feature.FeatureClass;IFeature feature1 = featureClass.GetFeature(0);//获取字段索引int index = featureClass.FindField("NAME");//获取值string nm = Convert.ToString(feature1.get_Value(index));MessageBox.Show(nm);
5.2 添加数据
//添加数据private void button1_Click(object sender, EventArgs e){ICommand command = new ControlsAddDataCommandClass();command.OnCreate(axMapControl1.Object);command.OnClick();}
5.3 地图放大
private void button2_Click(object sender, EventArgs e){//添加默认数据axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\第七章(第二讲)\第七章第二讲程序\data", "餐饮_point.shp");//判断是否激活工具if (axMapControl1.CurrentTool == null){//激活工具ESRI.ArcGIS.SystemUI.ICommand identify;ESRI.ArcGIS.SystemUI.ITool identifytool = new ControlsMapZoomInToolClass();axMapControl1.CurrentTool = identifytool;identify = identifytool as ESRI.ArcGIS.SystemUI.ICommand;identify.OnCreate(axMapControl1.Object);identify.OnClick();}else{axMapControl1.CurrentTool = null;}}
5.4 地图缩小
private void button3_Click(object sender, EventArgs e){//添加默认数据axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\第七章(第二讲)\第七章第二讲程序\data", "餐饮_point.shp");//判断是否激活工具if (axMapControl1.CurrentTool == null){//激活工具ESRI.ArcGIS.SystemUI.ICommand identify;ESRI.ArcGIS.SystemUI.ITool identifytool = new ControlsMapZoomOutToolClass();axMapControl1.CurrentTool = identifytool;identify = identifytool as ESRI.ArcGIS.SystemUI.ICommand;identify.OnCreate(axMapControl1.Object);identify.OnClick();}else{axMapControl1.CurrentTool = null;}}
5.5 地图漫游
private void button4_Click(object sender, EventArgs e){//添加默认数据axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\第七章(第二讲)\第七章第二讲程序\data", "餐饮_point.shp");//判断是否激活工具if (axMapControl1.CurrentTool == null){//激活工具ESRI.ArcGIS.SystemUI.ICommand identify;ESRI.ArcGIS.SystemUI.ITool identifytool = new ControlsMapPanToolClass();axMapControl1.CurrentTool = identifytool;identify = identifytool as ESRI.ArcGIS.SystemUI.ICommand;identify.OnCreate(axMapControl1.Object);identify.OnClick();}else{axMapControl1.CurrentTool = null;}}
5.5 全景视图
private void button5_Click(object sender, EventArgs e){ICommand command = new ControlsMapFullExtentCommand();command.OnCreate(axMapControl1.Object);command.OnClick();}
5.6 鹰眼(副视图)
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;//实现axmapcontrol1和axmapcontrol2的同步变化private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e){IMap pmap = axMapControl1.Map;int i;for (i = 0; i < pmap.LayerCount; i++){IObjectCopy objectcopy = new ObjectCopyClass();object toCopyLayer = axMapControl1.get_Layer(pmap.LayerCount - 1 - i);object copiedLayer = objectcopy.Copy(toCopyLayer);axMapControl2.Map.AddLayer(copiedLayer as ILayer);}axMapControl2.Extent = axMapControl1.FullExtent;axMapControl2.Refresh();}private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e){IEnvelope pEnv;pEnv = e.newEnvelope as IEnvelope;IGraphicsContainer graphicscontainer;IActiveView activewer;graphicscontainer = axMapControl2.Map as IGraphicsContainer;activewer = graphicscontainer as IActiveView;graphicscontainer.DeleteAllElements();IElement plement;plement = new RectangleElementClass();plement.Geometry = pEnv;IRgbColor rgbcol = new RgbColorClass();rgbcol.RGB = 255;rgbcol.Transparency = 255;ILineSymbol poutline = new SimpleLineSymbolClass();poutline.Width = 1;poutline.Color = rgbcol;IRgbColor pcolor = new RgbColorClass();pcolor.RGB = 255;pcolor.Transparency = 0;IFillSymbol fillsym = new SimpleFillSymbolClass();fillsym.Color = pcolor;fillsym.Outline = poutline;IFillShapeElement pfillshapeelement;pfillshapeelement = plement as IFillShapeElement;pfillshapeelement.Symbol = fillsym;plement = pfillshapeelement as IElement;graphicscontainer.AddElement(plement, 0);activewer.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);}}
5.7 矢量渲染
//点渲染private void button1_Click(object sender, EventArgs e){//获取图层IFeatureLayer myfealyer = axMapControl1.get_Layer(0) as IFeatureLayer;IGeoFeatureLayer geofeature = myfealyer as IGeoFeatureLayer;//定义一个空样式ISimpleRenderer render = new SimpleRendererClass();ISymbol sybol = new SimpleMarkerSymbolClass();ISimpleMarkerSymbol marksybol = sybol as ISimpleMarkerSymbol;IColor colr = new RgbColorClass();//设置颜色colr.RGB = 255;marksybol.Color = colr;//设置大小marksybol.Size = 10;render.Symbol = sybol;//样式的运用geofeature.Renderer = render as IFeatureRenderer;axTOCControl1.Update();axMapControl1.Refresh();}//线渲染private void button3_Click(object sender, EventArgs e){IFeatureLayer myfealyer = axMapControl1.get_Layer(1) as IFeatureLayer;IGeoFeatureLayer geofeature = myfealyer as IGeoFeatureLayer;ISimpleRenderer render = new SimpleRendererClass();ISymbol sybol = new SimpleLineSymbolClass();ISimpleLineSymbol linesybol = sybol as ISimpleLineSymbol;IColor colr = new RgbColorClass();colr.RGB = 255;linesybol.Color = colr;linesybol.Width = 2;linesybol.Style = esriSimpleLineStyle.esriSLSSolid;render.Symbol = sybol;geofeature.Renderer = render as IFeatureRenderer;axTOCControl1.Update();axMapControl1.Refresh();}//面渲染private void button4_Click(object sender, EventArgs e){IFeatureLayer myfealyer = axMapControl1.get_Layer(2) as IFeatureLayer;IGeoFeatureLayer geofeature = myfealyer as IGeoFeatureLayer;ISimpleRenderer render = new SimpleRendererClass();ILineSymbol sybol = new SimpleLineSymbolClass();IColor colr = new RgbColorClass();colr.RGB = 255;sybol.Color = colr;sybol.Width = 2;ISymbol fisbol = new SimpleFillSymbolClass();ISimpleFillSymbol fillsybol = fisbol as ISimpleFillSymbol;IColor colr1 = new RgbColorClass();colr1.RGB = 25;fillsybol.Color = colr1;fillsybol.Outline = sybol;fillsybol.Style = esriSimpleFillStyle.esriSFSSolid;render.Symbol = fisbol;geofeature.Renderer = render as IFeatureRenderer;axTOCControl1.Update();axMapControl1.Refresh();}
5.8 图层的透明度、亮度和对比度
//透明度调节private void button1_Click(object sender, EventArgs e){if (axMapControl1.LayerCount==0){axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\第十章\第十章\data", "面数据_Identity.shp");axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\第十章\第十章\data", "polygon1.shp");}IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;//接口跳转ILayerEffects layerEffects = featureLayer as ILayerEffects;layerEffects.Transparency = Convert.ToInt16(textBox1.Text);axMapControl1.Refresh();}
5.9 对矢量数据进行属性查询
private void button2_Click(object sender, EventArgs e){IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass featureClass = featureLayer.FeatureClass;IQueryFilter queryFilter = new QueryFilterClass();//设置查询条件queryFilter.WhereClause = "NAME='知味饭店'";IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);IFeature feature = featureCursor.NextFeature();IFeatureSelection featureSelection = featureLayer as IFeatureSelection;//将查询出来的结果进行高亮显示featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);//查询数量统计ISelectionSet selectionSet = featureSelection.SelectionSet;MessageBox.Show(selectionSet.Count.ToString());axMapControl1.Refresh();}
5.10 矢量数据空间位置查询
空间位置关系:相交、相离、包含
//点面包含查询private void button3_Click(object sender, EventArgs e){//获取面图层IFeatureLayer featureLayer = axMapControl1.get_Layer(2) as IFeatureLayer;IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(null, true);IFeature feature = featureCursor.NextFeature();ISpatialFilter spatialFilter = new SpatialFilterClass();spatialFilter.Geometry = feature.ShapeCopy;//空间位置关系:包含spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;//获取点图层IFeatureLayer featureLayer_point = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureSelection featureSelection = featureLayer_point as IFeatureSelection;//高亮显示featureSelection.SelectFeatures(spatialFilter as IQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);axMapControl1.Refresh();}//线面相交查询private void button4_Click(object sender, EventArgs e){//获取面图层IFeatureLayer featureLayer = axMapControl1.get_Layer(2) as IFeatureLayer;IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(null, true);IFeature feature = featureCursor.NextFeature();ISpatialFilter spatialFilter = new SpatialFilterClass();spatialFilter.Geometry = feature.ShapeCopy;//空间位置关系:相交spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;//获取线图层IFeatureLayer featureLayer_point = axMapControl1.get_Layer(1) as IFeatureLayer;IFeatureSelection featureSelection = featureLayer_point as IFeatureSelection;//高亮显示featureSelection.SelectFeatures(spatialFilter as IQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);axMapControl1.Refresh();}
5.11 绘制缓冲区
private void button2_Click(object sender, EventArgs e){IGraphicsContainer graphicsContainer = axMapControl1.Map as IGraphicsContainer;IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(null, true);IFeature feature = featureCursor.NextFeature();IActiveView activeView = axMapControl1.Map as IActiveView;while (feature!=null){ITopologicalOperator topologicalOperator = feature.ShapeCopy as ITopologicalOperator;//设置缓冲区IGeometry geometry = topologicalOperator.Buffer(0.02);IElement element = new PolygonElementClass();element.Geometry = geometry;graphicsContainer.AddElement(element, 0);//刷新页面activeView.Refresh();feature = featureCursor.NextFeature();}}
5.12 在地图上画点、线和面
- Element为图形元素,仅在内存中存在,无法保留在硬盘中,需要用IGraphicsContainer相关方法来实现添加和删除。
- 通过IFeatureClass接口创建的Feature可以保留在图层中和硬盘中。
//方法一://绘制点一共涉及多个事件IPoint point;IGraphicsContainer graphicsContainer;IElement element;IPointCollection point_lineCollection;IPointCollection point_mianCollection;private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e){//生成点point = new PointClass();point.X = e.mapX;point.Y = e.mapY;//生成线object a = Type.Missing;point_lineCollection.AddPoint(point, ref a, ref a);//生成面point_mianCollection.AddPoint(point, ref a, ref a);}//窗体运行事件private void Form1_Load(object sender, EventArgs e){graphicsContainer = axMapControl1.Map as IGraphicsContainer;//注意:实例化对应point_lineCollection = new PolylineClass();point_mianCollection = new PolygonClass();}private void point_Click(object sender, EventArgs e){element = new MarkerElementClass();element.Geometry = point as IGeometry;graphicsContainer.AddElement(element, 0);axMapControl1.Refresh();}private void line_Click(object sender, EventArgs e){//版本9需要类型转换,10以上不用IElement element = new LineElementClass();IPolyline polyline = new PolylineClass();polyline = point_lineCollection as IPolyline;element.Geometry = polyline as IGeometry;graphicsContainer.AddElement(element, 0);axMapControl1.Refresh();}private void polygon_Click(object sender, EventArgs e){IElement element = new PolygonElementClass();IPolygon polygon = new PolygonClass();polygon = point_mianCollection as IPolygon;element.Geometry = polygon as IPolygon;graphicsContainer.AddElement(element, 0);axMapControl1.Refresh();}//方法二:private void button5_Click_1(object sender, EventArgs e){IFeatureLayer felyer = axMapControl1.get_Layer(2) as IFeatureLayer;IFeatureClass feclass = felyer.FeatureClass;//创建一个空的featureIFeature fea = feclass.CreateFeature();//具体赋值fea.Shape = point as IGeometry;fea.Store();axMapControl1.Refresh();}private void button6_Click_1(object sender, EventArgs e){IFeatureLayer felyer = axMapControl1.get_Layer(1) as IFeatureLayer;IFeatureClass feclass = felyer.FeatureClass;IFeature fea = feclass.CreateFeature();IPolyline pline = new PolylineClass();pline = point_lineCollection as IPolyline;fea.Shape = pline as IGeometry;fea.Store();axMapControl1.Refresh();}private void button7_Click_1(object sender, EventArgs e){IFeatureLayer felyer = axMapControl1.get_Layer(0) as IFeatureLayer;IFeatureClass feclass = felyer.FeatureClass;IFeature fea = feclass.CreateFeature();IPolygon polyg = new PolygonClass();polyg = point_mianCollection as IPolygon;fea.Shape = polyg as IGeometry;fea.Store();axMapControl1.Refresh();}private void button1_Click_1(object sender, EventArgs e){if (axMapControl1.LayerCount<=3){axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\十四章\十四章\data", "point.shp");axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\十四章\十四章\data", "line.shp"); axMapControl1.AddShapeFile(@"E:\Secondary_development\C#\资料\十四章\十四章\data", "polygon1.shp");}}
5.13 对矢量数据字段统计
需要用到的接口为IDataStatistics和IStatisticsResults
private void button2_Click(object sender, EventArgs e){IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;//返回全部要素IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(null, true);IDataStatistics dataStatistics = new DataStatisticsClass();dataStatistics.Cursor = featureCursor as ICursor;dataStatistics.Field = "cd";IStatisticsResults statisticsResults = dataStatistics.Statistics;//获取统计值并输出MessageBox.Show(statisticsResults.Maximum.ToString());}
6 栅格数据
常用接口:IRasterLayer、IRaster、IRasterBandCollection、IRasterCursor
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;private void button1_Click(object sender, EventArgs e){OpenFileDialog pOpenFileDialog = new OpenFileDialog();pOpenFileDialog.CheckFileExists = true;pOpenFileDialog.Title = "打开Raster文件";pOpenFileDialog.Filter = "栅格文件 (*.*)|*.bmp;*.tif;*.jpg;*.dat;*.img|(*.bmp)|*.bmp|(*.tif)|*.tif|(*.jpg)|*.jpg|(*.img)|*.img|(*.dat)|*.dat";pOpenFileDialog.ShowDialog();string pRasterFileName = pOpenFileDialog.FileName;if (pRasterFileName == ""){return;}string pPath = System.IO.Path.GetDirectoryName(pRasterFileName);string pFileName = System.IO.Path.GetFileName(pRasterFileName);IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();IRasterWorkspace pRasterWorkspace = pWorkspaceFactory.OpenFromFile(pPath, 0) as IRasterWorkspace;IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName);//影像金字塔判断与创建IRasterPyramid3 pRasPyrmid;pRasPyrmid = pRasterDataset as IRasterPyramid3;if (pRasPyrmid != null){if (!(pRasPyrmid.Present)){pRasPyrmid.Create(); //创建金字塔}}IRaster pRaster;pRaster = pRasterDataset.CreateDefaultRaster();IRasterLayer pRasterLayer;pRasterLayer = new RasterLayerClass();pRasterLayer.CreateFromRaster(pRaster);axMapControl1.AddLayer(pRasterLayer, 0);}
6.1 读取单个栅格像元的值
//全局变量int column;int raw;private void button1_Click(object sender, EventArgs e){ICommand command = new ControlsAddDataCommandClass();command.OnCreate(axMapControl1.Object);command.OnClick();}private void button2_Click(object sender, EventArgs e){IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRaster raster = rasterLayer.Raster;IRaster2 raster2 = raster as IRaster2;object result = raster2.GetPixelValue(0, column, raw);string value = Convert.ToString(result);MessageBox.Show(value);}private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e){IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRaster raster = rasterLayer.Raster;IRaster2 raster2 = raster as IRaster2;//获取相对行列号raster2.MapToPixel(e.mapX, e.mapY, out column, out raw);}
6.2 读取任意选中的像元N*N领域的像元值
遍历每个像元获取像元值
//全局变量int column;int raw;private void button1_Click(object sender, EventArgs e){ICommand command = new ControlsAddDataCommandClass();command.OnCreate(axMapControl1.Object);command.OnClick();}private void button2_Click(object sender, EventArgs e){IPnt pnt = new PntClass();pnt.X = 3;pnt.Y = 3;IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRaster raster = rasterLayer.Raster;IPixelBlock pixelBlock = raster.CreatePixelBlock(pnt);IPnt pnt1 = new PntClass();pnt1.X = column - 1;pnt1.Y = raw - 1;raster.Read(pnt1, pixelBlock);IPixelBlock3 pixelBlock3 = pixelBlock as IPixelBlock3;Array array_value = pixelBlock3.get_PixelData(0) as Array;for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){string value = Convert.ToString(array_value.GetValue(i, j));MessageBox.Show(value);}}}private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e){IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRaster raster = rasterLayer.Raster;IRaster2 raster2 = raster as IRaster2;//获取相对行列号raster2.MapToPixel(e.mapX, e.mapY, out column, out raw);}
6.3 更改指定像元的值
//全局变量int column;int raw;private void button1_Click(object sender, EventArgs e){ICommand command = new ControlsAddDataCommandClass();command.OnCreate(axMapControl1.Object);command.OnClick();}private void button2_Click(object sender, EventArgs e){IPnt pnt = new PntClass();//基于大小为1的栅格像元块修改pnt.X = 1;pnt.Y = 1;IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRaster raster = rasterLayer.Raster;IPixelBlock pixelBlock = raster.CreatePixelBlock(pnt);IPnt pnt1 = new PntClass();pnt1.X = column;pnt1.Y = raw;IRasterEdit rasterEdit = raster as IRasterEdit;IPixelBlock3 pixelBlock3 = pixelBlock as IPixelBlock3;Array array = pixelBlock3.get_PixelData(0) as Array;array.SetValue(Convert.ToInt16(85), 0, 0);//数据传回,实现修改pixelBlock3.set_PixelData(0, array);rasterEdit.Write(pnt1, pixelBlock3 as IPixelBlock);MessageBox.Show("修改完成");axMapControl1.Refresh();}private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e){IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRaster raster = rasterLayer.Raster;IRaster2 raster2 = raster as IRaster2;//获取相对行列号raster2.MapToPixel(e.mapX, e.mapY, out column, out raw);}
6.4 对栅格数据进行RGB渲染
渲染的原理是通过RGB三基色对多波段的栅格进行赋值后得到的效果。
需要用到的接口是:IRasterRGBRenderer、IRaster和IRasterLayer接口。
private void button2_Click(object sender, EventArgs e){IRasterLayer rasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;IRasterRenderer rasterRenderer = new RasterRGBRendererClass();//关联图层和渲染器rasterRenderer.Raster = rasterLayer.Raster;IRasterRGBRenderer rasterRGBRenderer = rasterRenderer as IRasterRGBRenderer;//修改RGB对应的波段rasterRGBRenderer.RedBandIndex = 0;rasterRGBRenderer.GreenBandIndex = 2;rasterRGBRenderer.BlueBandIndex = 1;rasterLayer.Renderer = rasterRGBRenderer as IRasterRenderer;axMapControl1.Refresh();}
7 三维开发基础
//加载工程文件private void button2_Click(object sender, EventArgs e){axSceneControl1.LoadSxFile(@"E:\Secondary_development\C#\资料\第二十二章\第二十二章\data.sxd");}//地图放大private void button1_Click(object sender, EventArgs e){if (axSceneControl1.CurrentTool == null){ESRI.ArcGIS.SystemUI.ICommand identify;ESRI.ArcGIS.SystemUI.ITool identifytool = new ControlsSceneZoomInToolClass();axSceneControl1.CurrentTool = identifytool;identify = identifytool as ESRI.ArcGIS.SystemUI.ICommand;identify.OnCreate(axSceneControl1.Object);identify.OnClick();}else{axSceneControl1.CurrentTool = null;}}//全景视图显示private void button3_Click(object sender, EventArgs e){ESRI.ArcGIS.SystemUI.ICommand command = new ControlsSceneFullExtentCommandClass();command.OnCreate(axSceneControl1.Object);command.OnClick();}
ArcGIS Engine二次开发相关推荐
- 【ArcGIS Engine二次开发】入门基础(2):ArcGIS开发方式(VBA、DLL、Add-in、Engine)对比
文章目录 2.1 使用VBA进行桌面软件开发 2.1.1 VBA开发方式 2.1.1 VBA代码的安全性 2.2 使用DLL进行桌面软件开发 2.2.1 DLL开发方式 2.2.2 DLL功能的应用部 ...
- 利用Arcgis Engine 二次开发的使用和总结
Arcgis Engine 初体验 先放一张第一版系统的图,由于公司机密不能提供源码,但是各个小功能提供源码,为需要的同仁提供些许帮助. 接下来进入正题,将逐一展示利用Arcgis Engine开发的 ...
- 【转载】利用ArcGIS Engine 二次开发的使用和总结
文章目录 ArcGIS Engine 初体验 一.较完全编辑功能GIS程序 二.字段搜索要素和空间搜索要素GIS程序 三.图层重叠搜索GIS程序 四.要素合并.裁剪及检测要素重叠GIS程序 五.自定义 ...
- 【ArcGIS Engine二次开发】入门基础(1):ArcGIS Engine简介及开发环境搭建
文章目录 ArcGIS Engine概述 ArcGIS Engine与ArcObjects的关系 ArcGIS Engine下载及安装 ArcGIS Engine概述 ArcGIS Engine简介 ...
- arcgis engine二次开发python-使用C#配合ArcGIS Engine进行地理信息系统开发
简单的地图读取.展示终于到暑假了...开始认真整理整理相关学习的心得体会咯~ 先把很久之前挖的关于C# 二次开发的坑给填上好了~ 这次先计划用一个月把C# ArcEngine 10.0相关开发的学习心 ...
- Arcgis Engine二次开发(一)AE开发总览
参加工作两年多,打算将两年来的AE(Arcgis Engine,本系列后面统一简称AE)开发经验分享出来.打算把AE的开发做成一个系列,原因主要有两个:一个是AE开发网上资源比较少,让从事开发的码农接 ...
- 基于C#的ArcGIS Engine二次开发的一个简单测试程序
上一篇文章介绍了环境的搭建,现在我们来做出第一个小测试程序. (1)先建一个C#窗体应用程序,我将程序名称改为了ArcGIS_test2. (2)点击"工具"->" ...
- C#+ArcGIS Engine二次开发之鹰眼功能实现的代码
开发系统的时候,一定也会考虑鹰眼的实现,鹰眼对整个研究区域有一个整体的轮廓.所以,鹰眼对一个系统来说还是很有必要的.但是找过网上很多代码,大同小异,可最后出现的成果并不是我想要的,终于,get到了心仪 ...
- Arcgis Engine 二次开发之属性查询
一.类库接口描述 1.IQueryFilter接口 过滤数据通过属性值或者属性之间的关系,一般为其赋WhereClause和SubFields属性. 2.IFeatureClass接口 (1)Sear ...
最新文章
- 在C#中应用哈希表(Hashtable)
- 如何从sdcard读取文件
- python统计元素个数_python怎么统计列表中元素的个数
- 埋在 MySQL 数据库应用中的17个关键问题!
- In English or Chinese?
- 【Geek软技能】程序员,为什么写不好一份简历?
- word 2013 题注、图注、插入图片自动修改大小、批量更新题注编号
- 【数据库系统】关系模型、关系、元组、属性、关系实例
- php制作后台驻留执行 ,同时提前返回逻辑信息进行判断的实例
- unity多人游戏_如何使用Unity 2D和镜像构建多人纸牌游戏(更新)
- 2.WindowsServer2012R2装完的一些友好化设置
- 在线数据库设计ERD-ONLINE
- c#截取两个指定字符串中间的字符串
- if mysql sum 视图_MySQL(Excel透视)
- 计算机图形学--全局光照(屏幕空间:SSDO,SSR)
- 三菱四节传送带控制梯形图_四节传送带控制
- windows虚拟机dhcp服务器,无法访问虚拟机中的DHCP服务器
- 2022山东省安全员C证复训题库模拟考试平台操作
- afx是什么意思呀,什么时候要include呢,这个头文件的作用是??
- 电脑黑屏无法启动怎么办
热门文章
- 【ElementUI】InfiniteScroll 无限滚动组件在部分浏览器中滚动失效 的 解决方案
- 也发个网通客户端Dr.COM的破解版
- 【转】VT在BIOS内已开启,但CPU-v显示未开启
- 意义相对的俗语_ywyuan_新浪博客
- 易维帮助台如何“重新定义客户服务”?
- SpringBoot开发手册
- Java实现桌面鼠标坐标获取
- 从零开始学androidTextView的使用.四.
- k-均值(k-means)聚类
- Data Structures and Other Objects Using C++ (Chapter 1) 学习笔记一