实例介绍
【实例简介】
ArcGis Engine 示例
【实例截图】
【核心代码】
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
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 XiaoTiao
{
public partial class Form1 : Form
{
private bool bCanDrag;//鹰眼地图上的矩形可移动的标志
private IPoint pMoveRectPoint;//记录在移动鹰眼地图上的矩形框时鼠标的位置
private IEnvelope pEnv;//记录数据视图的Extent
IMapDocument mapDocument;
public Form1()
{
InitializeComponent();
}
private void btnLayer_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
featureLayer.Name = "zml";
axTOCControl1.Update();
}
private void button1_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
featureLayer.MaximumScale = 20000000;
featureLayer.MinimumScale = 20000000000;
axMapControl1.Refresh();
}
private void button2_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
featureLayer.Visible = true;
axMapControl1.Refresh();
}
private void button3_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
featureLayer.Visible = false;
axMapControl1.Refresh();
}
private void button4_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
IFieldEdit fieldEdit = new FieldClass();
fieldEdit.Name_2 = "zml";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
fieldEdit.Length_2 = 10;
featureClass.AddField(fieldEdit as IField);
MessageBox.Show("添加完成");
}
private void button5_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
IFields fields = featureClass.Fields;
for (int i = 0; i < fields.FieldCount; i )
{
IField field = fields.get_Field(i);
if (field.Name == "zml")
{
featureClass.DeleteField(field);
}
MessageBox.Show("删除完成");
}
}
private void button6_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
// IFields fields = featureClass.Fields;
IFeature feature = featureClass.GetFeature(0);
MessageBox.Show($"{ feature.get_Value(0)}");
}
private void button7_Click(object sender, EventArgs e)
{
ICommand command = new ControlsAddDataCommandClass();
command.OnCreate(axMapControl1.Object);
command.OnClick();
}
private void button8_Click(object sender, EventArgs e)
{
if (axMapControl1.CurrentTool != null && (axMapControl1.CurrentTool as ControlsMapZoomInToolClass) != null)
{
axMapControl1.CurrentTool = null;
}
else
{
ESRI.ArcGIS.SystemUI.ICommand command;
ESRI.ArcGIS.SystemUI.ITool tool = new ControlsMapZoomInToolClass();
axMapControl1.CurrentTool = tool;
command = tool as ESRI.ArcGIS.SystemUI.ICommand;
command.OnCreate(axMapControl1.Object);
command.OnClick();
}
}
private void button9_Click(object sender, EventArgs e)
{
if (axMapControl1.CurrentTool != null && (axMapControl1.CurrentTool as ControlsMapZoomOutToolClass) != null)
{
axMapControl1.CurrentTool = null;
}
else
{
ESRI.ArcGIS.SystemUI.ICommand command;
ESRI.ArcGIS.SystemUI.ITool tool = new ControlsMapZoomOutToolClass();
axMapControl1.CurrentTool = tool;
command = tool as ESRI.ArcGIS.SystemUI.ICommand;
command.OnCreate(axMapControl1.Object);
command.OnClick();
}
}
private void button10_Click(object sender, EventArgs e)
{
ICommand command = new ControlsMapFullExtentCommand();
command.OnCreate(axMapControl1.Object);
command.OnClick();
}
private void button11_Click(object sender, EventArgs e)
{
if (axMapControl1.CurrentTool != null && (axMapControl1.CurrentTool as ControlsMapPanToolClass) != null)
{
axMapControl1.CurrentTool = null;
}
else
{
ESRI.ArcGIS.SystemUI.ICommand command;
ESRI.ArcGIS.SystemUI.ITool tool = new ControlsMapPanToolClass();
axMapControl1.CurrentTool = tool;
command = tool as ESRI.ArcGIS.SystemUI.ICommand;
command.OnCreate(axMapControl1.Object);
command.OnClick();
}
}
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
//得到当前视图范围
IEnvelope pEnvelop = (IEnvelope)e.newEnvelope;
DrawRectangle(pEnvelop);
}
#region 获取RGB颜色
private IRgbColor GetRgbColor(int intR, int intG, int intB)
{
IRgbColor pRgbColor = null;
if (intR < 0 || intR > 255 || intG < 0 || intG > 255 || intB < 0 || intB > 255)
{
return pRgbColor;
}
pRgbColor = new RgbColorClass();
pRgbColor.Red = intR;
pRgbColor.Green = intG;
pRgbColor.Blue = intB;
return pRgbColor;
}
#endregion
#region 鹰眼中矩形框绘制的方法封装
private void DrawRectangle(IEnvelope pEnvelop)
{
//在绘制前,清除鹰眼中之前绘制的矩形框
IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();
//得到当前视图范围
IRectangleElement pRectangleElement = new RectangleElementClass();
IElement pElement = pRectangleElement as IElement;
pElement.Geometry = pEnvelop;
//设置矩形框(实质为中间透明度面)
IRgbColor pColor = new RgbColorClass();
pColor = GetRgbColor(255, 0, 0);
pColor.Transparency = 255;
ILineSymbol pOutLine = new SimpleLineSymbolClass();
pOutLine.Width = 1;
pOutLine.Color = pColor;
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pColor = new RgbColorClass();
pColor.Transparency = 0;
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutLine;
//向鹰眼中添加矩形框
IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;
pFillShapeElement.Symbol = pFillSymbol;
pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0);
//刷新
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
#endregion
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
if (axMapControl2.LayerCount > 0)
{
axMapControl2.ClearLayers();
}
//设置鹰眼和axMapControl1中地图的坐标系统一致
axMapControl2.SpatialReference = axMapControl1.SpatialReference;
for (int i = axMapControl1.LayerCount - 1; i >= 0; i--)
{
//是鹰眼视图与数据视图的图层上下顺序保持一致
ILayer pLayer = axMapControl1.get_Layer(i);
if (pLayer is IGroupLayer || pLayer is ICompositeLayer)
{
ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer;
for (int j = pCompositeLayer.Count - 1; j >= 0; j--)
{
ILayer pSubLayer = pCompositeLayer.get_Layer(i);
IFeatureLayer pFeatureLayer = pSubLayer as IFeatureLayer;
if (pFeatureLayer != null)
{
if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint && pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint)
{
axMapControl2.AddLayer(pLayer);
}
}
}
}
else
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer != null)
{
if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint && pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint)
{
axMapControl2.AddLayer(pLayer);
}
}
//设置鹰眼地图的全图显示
axMapControl2.Extent = axMapControl1.FullExtent;
pEnv = axMapControl1.Extent as IEnvelope;
DrawRectangle(pEnv);
axMapControl2.ActiveView.Refresh();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
//axMapControl1.LoadMxFile(@"C:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Samples\data\World\World.mxd");
}
private void axMapControl1_OnAfterScreenDraw(object sender, IMapControlEvents2_OnAfterScreenDrawEvent e)
{
//IMap map = axMapControl1.Map;
//for (int i = 0; i < map.LayerCount; i )
//{
// IObjectCopy objectCopy = new ObjectCopyClass();
// object toCopyLayer = axMapControl1.get_Layer(i);
// object layer = objectCopy.Copy(toCopyLayer);
// axMapControl2.AddLayer((ILayer)layer);
//}
//axMapControl2.Extent = axMapControl1.FullExtent;
//axMapControl2.Refresh();
//MessageBox.Show(axMapControl2.LayerCount.ToString());
}
private void button12_Click(object sender, EventArgs e)
{
if (axMapControl1.CurrentTool != null && (axMapControl1.CurrentTool as ControlsSelectToolClass) != null)
{
axMapControl1.CurrentTool = null;
}
else
{
ESRI.ArcGIS.SystemUI.ICommand command;
ESRI.ArcGIS.SystemUI.ITool tool = new ControlsSelectToolClass();
axMapControl1.CurrentTool = tool;
command = tool as ESRI.ArcGIS.SystemUI.ICommand;
command.OnCreate(axMapControl1.Object);
command.OnClick();
}
}
#region 鹰眼视图的OnMouseUp事件
private void axMapControl2_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
{
if (e.button == 1 && pMoveRectPoint != null)
{
if (e.mapX == pMoveRectPoint.X && e.mapY == pMoveRectPoint.Y)
{
axMapControl1.CenterAt(pMoveRectPoint);
}
bCanDrag = false;
}
}
#endregion
#region 鹰眼视图的OnMouseMove事件
private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
if (pEnv == null)
{ }
else if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax)
{
//如果鼠标移动到矩形框中,鼠标编程小手,表示可以移动
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHand;
if (e.button == 2)//如果在内部点点击鼠标右键,将鼠标演示设置为默认样式
{
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
axMapControl1.AutoKeyboardScrolling = true;
axMapControl1.AutoMouseWheel = true;
}
}
else
{
//在其位置将鼠标设为默认样式
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
axMapControl1.AutoKeyboardScrolling = true;
axMapControl1.AutoMouseWheel = true;
}
if (bCanDrag)
{
double Dx, Dy;//记录鼠标移动的距离
Dx = e.mapX - pMoveRectPoint.X;
Dy = e.mapY - pMoveRectPoint.Y;
pEnv.Offset(Dx, Dy);//根据偏移量更改pEnv位置
pMoveRectPoint.PutCoords(e.mapX, e.mapY);
DrawRectangle(pEnv);
axMapControl1.Extent = pEnv;
}
}
#endregion
#region 鹰眼视图的OnMouseDown事件
private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (axMapControl2.Map.LayerCount > 0)
{
//按下鼠标左键,移动矩形框
if (e.button == 1)
{
//如果指针落在鹰眼的矩形框中,标记可移动
if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax)
{
bCanDrag = true;
}
pMoveRectPoint = new PointClass();
pMoveRectPoint.PutCoords(e.mapX, e.mapY);//记录点击的第一个点的坐标
axMapControl1.AutoKeyboardScrolling = true;
axMapControl1.AutoMouseWheel = true;
}
//按下鼠标右键,绘制矩形框
else if (e.button == 2)
{
IEnvelope pEnvelop = axMapControl2.TrackRectangle();
IPoint pTemPoint = new PointClass();
pTemPoint.PutCoords(pEnvelop.XMin pEnvelop.Width / 2, pEnvelop.YMin pEnvelop.Height / 2);
axMapControl1.Extent = pEnvelop;
//矩形框的高度和数据视图的高度不一定成正比,这里做一个中心调整
axMapControl1.CenterAt(pTemPoint);
axMapControl1.AutoKeyboardScrolling = true;
axMapControl1.AutoMouseWheel = true;
}
}
}
#endregion
private void button13_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
if (geoFeatureLayer != null)
{
ISimpleRenderer simpleRenderer = new SimpleRendererClass();
ISymbol symbol = new SimpleMarkerSymbolClass();
IMarkerSymbol simpleMarkerSymbol = symbol as IMarkerSymbol;
IColor color = new RgbColorClass();
color.RGB = 255;
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Size = 5;
simpleRenderer.Symbol = symbol;
simpleRenderer.Label = "zml";
geoFeatureLayer.Renderer = simpleRenderer as IFeatureRenderer;
axTOCControl1.Update();
axMapControl1.Refresh();
}
}
private void button14_Click(object sender, EventArgs e)
{
if (axMapControl1.LayerCount > 0)
axMapControl1.DeleteLayer(0);
}
private void button15_Click(object sender, EventArgs e)
{
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
IPolyline polyline = new PolylineClass();
IPoint point = new PointClass();
point.PutCoords(500, 800);
polyline.FromPoint = point;
point.PutCoords(300, 200);
polyline.ToPoint = point;
IRgbColor rgbColor = new RgbColorClass() { };
rgbColor.Blue = 255;
rgbColor.Red = 255;
rgbColor.Green = 0;
simpleLineSymbol.Width = 1;
simpleLineSymbol.Color = rgbColor;
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDot;
ISymbol symbol = simpleLineSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPXOrPen;
IActiveView activeView = this.axMapControl1.ActiveView;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolyline(polyline);
activeView.ScreenDisplay.FinishDrawing();
activeView.ScreenDisplay.FinishDrawing();
}
private void button16_Click(object sender, EventArgs e)
{
UID uID;
IEnvelope envelope;
IMapSurround mapSurround;
IGraphicsContainer graphicsContainer;
IMapFrame mapFrame;
IMapSurroundFrame mapSurroundFrame;
IElement element;
ITrackCancel trackCancel;
uID = new UIDClass();
uID.Value = "esriCarto.legend";
envelope = new EnvelopeClass();
envelope.PutCoords(1,1,2,2);
// graphicsContainer
}
private void button17_Click(object sender, EventArgs e)
{
mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass();
try
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = openFileDialog.FileName;
mapDocument.Open(filePath, "");
for (int i = 0; i < mapDocument.MapCount; i )
{
axMapControl1.Map = mapDocument.get_Map(i);
}
axMapControl1.Refresh();
}
else
{
mapDocument = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button18_Click(object sender, EventArgs e)
{
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.CheckFileExists = true;
pOpenFileDialog.Title = "打开Shape文件";
pOpenFileDialog.Filter = "Shape文件(*.shp)|*.shp";
pOpenFileDialog.ShowDialog();
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
string pFullPath = pOpenFileDialog.FileName;
if (pFullPath == "") return;
int pIndex = pFullPath.LastIndexOf("\\");
string pFilePath = pFullPath.Substring(0, pIndex); //文件路径
string pFileName = pFullPath.Substring(pIndex 1); //文件名
//实例化ShapefileWorkspaceFactory工作空间,打开Shape文件
pWorkspaceFactory = new ShapefileWorkspaceFactory();
pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);
//创建并实例化要素集
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName);
pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
//ClearAllData(); //新增删除数据
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
private void button19_Click(object sender, EventArgs e)
{
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.CheckFileExists = true;
pOpenFileDialog.Title = "打开Raster文件";
pOpenFileDialog.Filter = "栅格文件 (*.*)|*.bmp;*.tif;*.jpg;*.img|(*.bmp)|*.bmp|(*.tif)|*.tif|(*.jpg)|*.jpg|(*.img)|*.img";
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();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pPath, 0);
IRasterWorkspace pRasterWorkspace = pWorkspace 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);
ILayer pLayer = pRasterLayer as ILayer;
axMapControl1.AddLayer(pLayer, 0);
}
private void button20_Click(object sender, EventArgs e)
{
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.Filter = "CAD(*.dwg)|*.dwg";
pOpenFileDialog.Title = "打开CAD数据文件";
pOpenFileDialog.ShowDialog();
string pFullPath = pOpenFileDialog.FileName;
if (pFullPath == "")
{
return;
}
//获取文件名和文件路径
int pIndex = pFullPath.LastIndexOf("\\");
string pFilePath = pFullPath.Substring(0, pIndex);
string pFileName = pFullPath.Substring(pIndex 1);
//打开CAD数据集
pWorkspaceFactory = new CadWorkspaceFactoryClass(); //using ESRI.ArcGIS.DataSourcesFile;
pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);
//打开一个要素集
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pFileName);
//IFeatureClassContainer可以管理IFeatureDataset中的每个要素类
IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset;
//对CAD文件中的要素进行遍历处理
for (int i = 0; i < pFeatClassContainer.ClassCount; i )
{
IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
//如果是注记,则添加注记层
if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
{
pFeatureLayer = new CadAnnotationLayerClass();
pFeatureLayer.Name = pFeatClass.AliasName;
pFeatureLayer.FeatureClass = pFeatClass;
axMapControl1.Map.AddLayer(pFeatureLayer);
}
else //如果是点、线、面则添加要素层
{
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.Name = pFeatClass.AliasName;
pFeatureLayer.FeatureClass = pFeatClass;
axMapControl1.Map.AddLayer(pFeatureLayer);
}
axMapControl1.ActiveView.Refresh();
}
}
private void button21_Click(object sender, EventArgs e)
{
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;
//获取当前路径和文件名
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
string strFullPath = dlg.FileName;
if (strFullPath == "") return;
//打开personGeodatabase,并添加图层
IWorkspaceFactory pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
//打开工作空间并遍历数据集
IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(strFullPath, 0);
IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();
//如果数据集是IFeatureDataset,则遍历它下面的子类
if (pDataset is IFeatureDataset)
{
pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(strFullPath, 0);
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IDataset pDataset1 = pEnumDataset1.Next();
//如果子类是FeatureClass,则添加到axMapControl1中
if (pDataset1 is IFeatureClass)
{
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
}
}
}
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论