esriFeatureType

ConstantValueDescription
esriFTSimple1Simple Feature.
esriFTSimpleJunction7Simple Junction Feature.
esriFTSimpleEdge8Simple Edge Feature.
esriFTComplexJunction9Complex Junction Feature.
esriFTComplexEdge10Complex Edge Feature.
esriFTAnnotation11Annotation Feature.
esriFTCoverageAnnotation12Coverage Annotation Feature.
esriFTDimension13Dimension Feature.
esriFTRasterCatalogItem14Raster Catalog Item.
Remarks
Feature type
Real-world object or concept
esriFTSimple Polygons, polylines, and points representing objects or places that have area, such as water bodies; linear objects, such as rivers; and localized positions, such as houses or sample sites.
esriFTSimpleJunction Simple junction feature in a geometric network representing point objects, such as a fuse, service point, or telephone pole.
esriFTSimpleEdge Simple edge feature in a geometric network representing polyline objects, such as primary or secondary overheads.
esriFTComplexJunction Complex junction feature in a geometric network, not in general use.
esriFTComplexEdge Complex edge feature in a geometric network representing polyline objects such as primary overheads, which have midspan connectivity. Network resources flow through complex edge without interruption by midspan connectivity.
esriFTAnnotation Place or object names or identifiers, such as street names, hydrant ID numbers, land values, or elevation.
esriFTCoverageAnnotation Place or object names or identifiers, such as street names, hydrant ID numbers, land values, or elevation. Not supported in geodatabases, only supported in coverage datasets.
esriFTDimension Measurements, such as distances, lengths, widths, and depths.
esriFTRasterCatalogItem
A raster dataset in a raster catalog that has information, such as footprints, names, metadata, and any other user-defined attributes.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; // 添加此行,用于处理路径 using ESRI.ArcGIS.Geometry; // 几何类型(线、点、多边形) using ESRI.ArcGIS.Controls; // ArcGIS控件(DrawTool绘图工具) using ESRI.ArcGIS.Geodatabase; // 要素类、图层相关 //using ESRI.ArcGIS.DataSourcesGDB; // 内存工作空间(临时存储轨迹) using ESRI.ArcGIS.Carto; namespace 李佳怡2023030331 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnAttrQuery_Click(object sender, EventArgs e) { Form2 frm = new Form2(this); frm.Show(); } private void Form1_Load(object sender, EventArgs e) { try { // 添加System.IO命名空间引用(顶部) //using System.IO; string shapeName = "河北省行政区.shp"; string shapePath = Application.StartupPath; string fullPath = Path.Combine(shapePath, shapeName); // 检查文件及配套文件是否存在 if (!File.Exists(fullPath)) { MessageBox.Show("主文件不存在:" + fullPath); return; } if (!File.Exists(Path.ChangeExtension(fullPath, ".shx")) || !File.Exists(Path.ChangeExtension(fullPath, ".dbf"))) { MessageBox.Show("缺少.shx或.dbf配套文件"); return; } // 直接调用AddShapeFile,不接收返回值(兼容void返回类型) axMapControl1.AddShapeFile(shapePath, shapeName); axMapControl1.ActiveView.Refresh(); // 刷新地图显示 MessageBox.Show("Shapefile加载完成"); } catch (Exception ex) { MessageBox.Show("加载失败:" + ex.Message); } } private void btnDrawTrack_Click(object sender, EventArgs e) { if (_trackLayer != null) { axMapControl1.DeleteLayer(_trackLayer); _trackLayer = null; } // 2. 提示用户操作 MessageBox.Show("请在地图上点击绘制轨迹(双击结束)", "操作提示"); // 3. 调用TrackLine()方法,捕获鼠标绘制的线(核心代码) // 执行该代码后,鼠标会变成十字,在地图上点击加点,双击结束 IPolyline trackLine = axMapControl1.TrackLine() as IPolyline; // 4. 判断是否绘制了轨迹 if (trackLine == null || trackLine.IsEmpty) { MessageBox.Show("未绘制任何轨迹", "提示"); return; } // 5. 保存轨迹并添加到地图 _trackPolyline = trackLine; _trackLayer = AddTrackToMap(trackLine); // 6. 刷新地图 axMapControl1.ActiveView.Refresh(); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } // 绘图完成后的回调方法(保存轨迹并显示) private void DrawTool_OnDrawComplete(object drawObject) { // 1. 将绘制的对象转换为线要素(轨迹) _trackPolyline = drawObject as IPolyline; if (_trackPolyline == null) return; // 2. 将轨迹添加到地图并显示 _trackLayer = AddTrackToMap(_trackPolyline); // 3. 刷新地图视图 axMapControl1.ActiveView.Refresh(); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } // ========== 辅助方法:将轨迹添加到地图 ========== private IFeatureLayer AddTrackToMap(IPolyline trackLine) { // 1. 创建内存工作空间(临时存储轨迹,程序关闭后消失) IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.Create("", "TempTrackWorkspace", null, 0); IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; // 2. 定义轨迹图层的字段(仅需几何字段) IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = fields as IFieldsEdit; // 2.1 创建几何字段(存储线要素) IField shapeField = new FieldClass(); IFieldEdit shapeFieldEdit = shapeField as IFieldEdit; shapeFieldEdit.Name_2 = "Shape"; // 字段名 shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; // 字段类型:几何 // 2.2 设置几何字段的空间参考(与地图控件一致) IGeometryDef geometryDef = new GeometryDefClass(); IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit; geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline; // 线要素 geometryDefEdit.SpatialReference_2 = axMapControl1.SpatialReference; // 与地图同坐标系 shapeFieldEdit.GeometryDef_2 = geometryDef; // 2.3 将几何字段添加到字段集合 fieldsEdit.AddField(shapeField); // 3. 创建临时要素类(存储轨迹的要素) IFeatureClass trackFeatureClass = featureWorkspace.CreateFeatureClass( "TrackClass", // 要素类名 fields, // 字段集合 null, // 要素类扩展 null, // 配置关键字 esriFeatureType.esriFTSimple, // 要素类型 "Shape", // 几何字段名 "" // 配置字符串 ); // 4. 创建轨迹要素并添加到要素类 IFeature trackFeature = trackFeatureClass.CreateFeature(); trackFeature.Shape = trackLine; // 设置要素的几何形状为轨迹线 trackFeature.Store(); // 保存要素 // 5. 创建轨迹图层并添加到地图 IFeatureLayer trackLayer = new FeatureLayerClass(); trackLayer.FeatureClass = trackFeatureClass; trackLayer.Name = "用户绘制轨迹"; // 图层名(在TOC中显示) axMapControl1.AddLayer(trackLayer); // 将图层添加到地图 return trackLayer; } private void btnRedrawTrack_Click(object sender, EventArgs e) { // 1. 判断是否有已绘制的轨迹 if (_trackPolyline == null) { MessageBox.Show("请先绘制轨迹再执行重绘操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 2. 清除旧的轨迹图层 if (_trackLayer != null) { axMapControl1.DeleteLayer(_trackLayer); _trackLayer = null; } // 3. 重新添加轨迹到地图 _trackLayer = AddTrackToMap(_trackPolyline); // 4. 刷新地图视图 axMapControl1.ActiveView.Refresh(); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); MessageBox.Show("轨迹重绘完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } // ============================================== } } 这有19个错误,帮我找出来改一下
最新发布
11-28
using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.DataSourcesRaster; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; namespace EngineWindowsApplication1 { public partial class MainForm : Form { private INewLineFeedback pNewLineFeedback; //追踪线对象 private INewPolygonFeedback pNewPolygonFeedback; //追踪面对象 private IPoint pPointPt = null; //鼠标点击点 private IPoint pMovePt = null; //鼠标移动时的当前点 private double dTotalLength = 0; //量测总长度 private double dSegmentLength = 0; //片段距离 private IPointCollection pAreaPointCol = null; //面积量算时画的点进行存储 private string sMapUnits = "未知单位"; //地图单位变量 private object missing = Type.Missing; string pMouseOperate = null; string pMouseOperateBackup = null; IExtentStack pExtentStack; public MainForm() { ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop); ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Engine); this.StartPosition = FormStartPosition.CenterScreen; InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; } private void ClearAllData() { if (mainMapControl.Map != null && mainMapControl.Map.LayerCount > 0) { IMap dataMap = new MapClass(); dataMap.Name = "Map"; mainMapControl.DocumentFilename = string.Empty; mainMapControl.Map = dataMap; } } private void ClearMeasureObject() { //清空线对象 if (pNewLineFeedback != null) { pNewLineFeedback.Stop(); pNewLineFeedback = null; dSegmentLength = 0; dTotalLength = 0; } //清空面对象 if (pNewPolygonFeedback != null) { pNewPolygonFeedback.Stop(); pNewPolygonFeedback = null; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //清空点集中所有点 } //清空量算画的线、面对象 mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null); //结束量算功能 pMouseOperate = string.Empty; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } private string GetMapUnit(esriUnits _esriMapUnit) { string sMapUnits = string.Empty; switch (_esriMapUnit) { case esriUnits.esriCentimeters: sMapUnits = "厘米"; break; case esriUnits.esriDecimalDegrees: sMapUnits = "十进制"; break; case esriUnits.esriDecimeters: sMapUnits = "分米"; break; case esriUnits.esriFeet: sMapUnits = "尺"; break; case esriUnits.esriInches: sMapUnits = "英寸"; break; case esriUnits.esriKilometers: sMapUnits = "千米"; break; case esriUnits.esriMeters: sMapUnits = "米"; break; case esriUnits.esriMiles: sMapUnits = "英里"; break; case esriUnits.esriMillimeters: sMapUnits = "毫米"; break; case esriUnits.esriNauticalMiles: sMapUnits = "海里"; break; case esriUnits.esriPoints: sMapUnits = "点"; break; case esriUnits.esriUnitsLast: sMapUnits = "UnitsLast"; break; case esriUnits.esriUnknownUnits: sMapUnits = "未知单位"; break; case esriUnits.esriYards: sMapUnits = "码"; break; default: break; } return sMapUnits; } private void Form1_Load(object sender, EventArgs e) { this.axTOCControl1.SetBuddyControl(mainMapControl); this.axToolbarControl1.SetBuddyControl(mainMapControl); pAreaPointCol = new MultipointClass(); axToolbarControl1.SetBuddyControl(mainMapControl); axTOCControl2.SetBuddyControl(mainMapControl); } private void tsmiAddMapDoc_Click(object sender, EventArgs e) { } private void tsmiLoadMxFile_Click(object sender, EventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Title = "打开地图文档"; ofd.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt|发布地图文件(*.pmf)|*.pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf"; ofd.Multiselect = false; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { string pFileName = ofd.FileName; if (pFileName == "") { return; } if (mainMapControl.CheckMxFile(pFileName))//检查地图文档有效性 { ClearAllData(); mainMapControl.LoadMxFile(pFileName); mainMapControl.Extent = mainMapControl.FullExtent; mainMapControl.Refresh(); } else { MessageBox.Show(pFileName + "是无效的地图文档!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); return; } } } catch (Exception ex) { MessageBox.Show("打开地图文档失败!\n" + ex.Message, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } } private void tsmiIMapDocument_Click(object sender, EventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Title = "打开地图文档"; ofd.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt|发布地图文件(*.pmf)|*.pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf"; ofd.Multiselect = false; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { string pFileName = ofd.FileName; if (pFileName == "") { return; } if (mainMapControl.CheckMxFile(pFileName)) { IMapDocument pMapDocument = new MapDocument(); //usingESRI.ArcGIS.Carto; pMapDocument.Open(pFileName, ""); mainMapControl.Map = pMapDocument.ActiveView.FocusMap; mainMapControl.Extent = mainMapControl.FullExtent; mainMapControl.ActiveView.Refresh(); } else { MessageBox.Show(pFileName + "是无效的地图文档!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); return; } } } catch (Exception ex) { MessageBox.Show("打开地图文档失败!\n" + ex.Message, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } } private void tsmiControlsOpenDocCommandClass_Click(object sender, EventArgs e) { ICommand command = new ControlsOpenDocCommandClass(); command.OnCreate(mainMapControl.Object); command.OnClick(); } private void mainMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (e.button == 1) { IActiveView pActiveView = mainMapControl.ActiveView; IEnvelope pEnvelope = new EnvelopeClass(); switch (pMouseOperate) { case "ZoomIn": //拉框放大 pEnvelope = mainMapControl.TrackRectangle(); //如果拉框范围为空则返回 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) { return; } //如果有拉框范围,则放大到拉框范围 pActiveView.Extent = pEnvelope; pActiveView.Refresh(); break; case "ZoomOut": //拉框缩小 pEnvelope = mainMapControl.TrackRectangle(); //如果拉框范围为空则退出 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) { return; } //如果有拉框范围,则以拉框范围为中心,缩小倍数为:当前视图范围/拉框范围 else { double dWidth = pActiveView.Extent.Width * pActiveView.Extent.Width / pEnvelope.Width; double dHeight = pActiveView.Extent.Height * pActiveView.Extent.Height / pEnvelope.Height; double dXmin = pActiveView.Extent.XMin - ((pEnvelope.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width / pEnvelope.Width); double dYmin = pActiveView.Extent.YMin - ((pEnvelope.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height / pEnvelope.Height); double dXmax = dXmin + dWidth; double dYmax = dYmin + dHeight; pEnvelope.PutCoords(dXmin, dYmin, dXmax, dYmax); } pActiveView.Extent = pEnvelope; pActiveView.Refresh(); break; case "Pan": //漫游 mainMapControl.Pan(); break; default: break; } } else if (e.button == 2) { pMouseOperate = ""; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } tsslXY.Text = string.Format("({0}, {1}) {2}", e.mapX.ToString("#######.####"), e.mapY.ToString("#######.####"), mainMapControl.MapUnits.ToString().Substring(4)); pPointPt = (mainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { IActiveView pActiveView = mainMapControl.ActiveView; IEnvelope pEnvelope = new EnvelopeClass(); switch (pMouseOperate) { case "MeasureLength": //距离量量测 //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点 if (pNewLineFeedback == null) { //实例化追踪线对象 pNewLineFeedback = new NewLineFeedbackClass(); pNewLineFeedback.Display = (mainMapControl.Map as IActiveView).ScreenDisplay; //设置起点,开始动态线绘制 pNewLineFeedback.Start(pPointPt); dTotalLength = 0; } else //如果追踪线对象不为空,则添加当前鼠标点 { pNewLineFeedback.AddPoint(pPointPt); } //pGeometry = m_PointPt; if (dSegmentLength != 0) { dTotalLength = dTotalLength + dSegmentLength; } break; case "MeasureArea": //面积量测 if (pNewPolygonFeedback == null) { //实例化追踪面对象 pNewPolygonFeedback = new NewPolygonFeedback(); pNewPolygonFeedback.Display = (mainMapControl.Map as IActiveView).ScreenDisplay; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //开始绘制多边形 pNewPolygonFeedback.Start(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } else { pNewPolygonFeedback.AddPoint(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } break; default: break; } } else if (e.button == 2) { pMouseOperate=""; mainMapControl.MousePointer=esriControlsMousePointer. esriPointerDefault ; } } private void tsmiAddShpByMapControl_Click(object sender, EventArgs e) { { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Title = "打开Shapefile文件"; ofd.Filter = "Shapefile文件(*.shp)|*.shp"; ofd.Multiselect = true; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { IWorkspaceFactory pWorkspaceFactory; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; foreach (string file in ofd.FileNames) { if (file != "") { int pIndex = file.LastIndexOf("\\"); string pFilePath = file.Substring(0, pIndex); string pFileName = file.Substring(pIndex + 1); 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; mainMapControl.Map.AddLayer(pFeatureLayer); } } mainMapControl.Extent = mainMapControl.FullExtent; mainMapControl.ActiveView.Refresh(); } } catch (Exception ex) { MessageBox.Show("加载Shapefile文件失败!\n" + ex.Message, "警告"); } } } private void tsmiAddRaster_Click(object sender, EventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Multiselect = true; ofd.RestoreDirectory = true; //存储打开的文件路径 ofd.Title = "打开Raster文件"; ofd.Filter = "TIFF文件(*.tif)|*. tif |JPEG文件(*.jpg)|*.jpg|BMP文件(*.bmp)|*.bmp|IMG文件(*.img)|*.img|栅格文件(*.*)|*.bmp;*.tif;*.jpg;*.img"; if (ofd.ShowDialog() == DialogResult.OK) { foreach (string file in ofd.FileNames) { string pPath = System.IO.Path.GetDirectoryName(file); string pFileName = System.IO.Path.GetFileName(file); 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; mainMapControl.AddLayer(pLayer, 0); } mainMapControl.ActiveView.Refresh(); mainMapControl.Extent = mainMapControl.FullExtent; } } catch (Exception ex) { MessageBox.Show("加载栅格文件失败!\n" + ex.Message, "警告"); } } private void tsmiAddLayer_Click(object sender, EventArgs e) { { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Multiselect = true; ofd.RestoreDirectory = true; ofd.Title = "打开图层文件(.lyr)"; ofd.Filter = "Layer图层文件(*.lyr)|*. lyr"; if (ofd.ShowDialog() == DialogResult.OK) { foreach (string file in ofd.FileNames) mainMapControl.AddLayerFromFile(file); mainMapControl.ActiveView.Refresh(); mainMapControl.Extent = mainMapControl.FullExtent; } } catch (Exception ex) { MessageBox.Show("加载Layer图层数据(.lyr)失败!\n" + ex.ToString(), "警告"); } } } private void 件ToolStripMenuItem_Click(object sender, EventArgs e) { { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Title = "打开Shapefile文件"; ofd.Filter = "Shapefile文件(*.shp)|*.shp"; ofd.Multiselect = true; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { IWorkspaceFactory pWorkspaceFactory; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; foreach (string file in ofd.FileNames) { if (file != "") { int pIndex = file.LastIndexOf("\\"); string pFilePath = file.Substring(0, pIndex); string pFileName = file.Substring(pIndex + 1); 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; mainMapControl.Map.AddLayer(pFeatureLayer); } } mainMapControl.Extent = mainMapControl.FullExtent; mainMapControl.ActiveView.Refresh(); } } catch (Exception ex) { MessageBox.Show("加载Shapefile文件失败!\n" + ex.Message, "警告"); } } } private void 通过MapControl控件加载Shp文件ToolStripMenuItem_Click(object sender, EventArgs e) { { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Title = "打开Shapefile文件"; ofd.Filter = "Shapefile文件(*.shp)|*.shp"; ofd.Multiselect = true; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { IWorkspaceFactory pWorkspaceFactory; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; foreach (string file in ofd.FileNames) { if (file != "") { int pIndex = file.LastIndexOf("\\"); string pFilePath = file.Substring(0, pIndex); string pFileName = file.Substring(pIndex + 1); 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; mainMapControl.Map.AddLayer(pFeatureLayer); } } mainMapControl.Extent = mainMapControl.FullExtent; mainMapControl.ActiveView.Refresh(); } } catch (Exception ex) { MessageBox.Show("加载Shapefile文件失败!\n" + ex.Message, "警告"); } } } private void tsmiAddCADByLayer_Click(object sender, EventArgs e) { try { IWorkspaceFactory pWorkspaceFactory; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; IFeatureClass pFeatureClass; OpenFileDialog ofd = new OpenFileDialog(); ofd.CheckFileExists = true; ofd.Multiselect = true; ofd.RestoreDirectory = true; ofd.Filter = "CAD(*.dwg)|*.dwg"; ofd.Title = "打开CAD数据文件"; if (ofd.ShowDialog() == DialogResult.OK) { foreach (string file in ofd.FileNames) { if (file == "") continue; int pIndex = file.LastIndexOf("\\"); string pFilePath = file.Substring(0, pIndex); string pFileName = file.Substring(pIndex + 1); pWorkspaceFactory = new CadWorkspaceFactory(); pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0); pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName + ":polyline"); pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.Name = pFileName; pFeatureLayer.FeatureClass = pFeatureClass; mainMapControl.Map.AddLayer(pFeatureLayer); } mainMapControl.ActiveView.Refresh(); mainMapControl.Extent = mainMapControl.FullExtent; } } catch (Exception ex) { MessageBox.Show("分图层加载CAD数据失败!\n" + ex.Message, "警告"); } } private void tsmiAddCADByWhole_Click(object sender, EventArgs e) { try { IWorkspaceFactory pWorkspaceFactory; IFeatureWorkspace pFeatureWorkspace; IFeatureLayer pFeatureLayer; IFeatureDataset pFeatureDataset; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "CAD(*.dwg)|*.dwg"; ofd.Title = "打开CAD数据文件"; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { foreach (string file in ofd.FileNames) { if (file == "") continue; int pIndex = file.LastIndexOf("\\"); string pFilePath = file.Substring(0, pIndex); string pFileName = file.Substring(pIndex + 1); pWorkspaceFactory = new CadWorkspaceFactoryClass(); pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0); pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pFileName); IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset; 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; mainMapControl.Map.AddLayer(pFeatureLayer); } else { pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.Name = pFeatClass.AliasName; pFeatureLayer.FeatureClass = pFeatClass; mainMapControl.Map.AddLayer(pFeatureLayer); } } } mainMapControl.ActiveView.Refresh(); mainMapControl.Extent = mainMapControl.FullExtent; } } catch (Exception ex) { MessageBox.Show("加载整幅CAD图数据失败!\n" + ex.Message, "警告"); } } private void tsmiAddCADByRaster_Click(object sender, EventArgs e) { try { IWorkspaceFactory pCadWorkspaceFactory; IWorkspace pWorkspace; ICadDrawingWorkspace pCadDrawingWorkspace; ICadDrawingDataset pCadDrawingDataset; ICadLayer pCadLayer; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "CAD(*.dwg)|*.dwg"; ofd.Title = "打开CAD数据文件"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { string pFullPath = ofd.FileName; if (pFullPath == "") return; int pIndex = pFullPath.LastIndexOf("\\"); string pFilePath = pFullPath.Substring(0, pIndex); string pFileName = pFullPath.Substring(pIndex + 1); pCadWorkspaceFactory = new CadWorkspaceFactoryClass(); pWorkspace = pCadWorkspaceFactory.OpenFromFile(pFilePath, 0); pCadDrawingWorkspace = (ICadDrawingWorkspace)pWorkspace; pCadDrawingDataset = pCadDrawingWorkspace.OpenCadDrawingDataset(pFileName); pCadLayer = new CadLayerClass(); pCadLayer.CadDrawingDataset = pCadDrawingDataset; mainMapControl.Map.AddLayer(pCadLayer); mainMapControl.ActiveView.Refresh(); } } catch (Exception ex) { MessageBox.Show("作为栅格地图加载CAD数据失败!\n" + ex.Message, "警告"); } } private void tsmiMapDocSave1_Click(object sender, EventArgs e) { try { if (mainMapControl.Map.LayerCount < 1) { MessageBox.Show("地图文档为空或出现异常,不能保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string sMxdFileName = mainMapControl.DocumentFilename; IMapDocument pMapDocument = new MapDocumentClass(); if (sMxdFileName != null && mainMapControl.CheckMxFile(sMxdFileName)) { if (pMapDocument.get_IsReadOnly(sMxdFileName)) { MessageBox.Show("地图文档是只读的,不能保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); pMapDocument.Close(); return; } } else { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "请选择保存路径"; sfd.OverwritePrompt = true; sfd.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { sMxdFileName = sfd.FileName; } else { return; } } pMapDocument.New(sMxdFileName); pMapDocument.ReplaceContents(mainMapControl.Map as IMxdContents); pMapDocument.Save(pMapDocument.UsesRelativePaths, true); pMapDocument.Close(); MessageBox.Show("地图文档保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("地图文档保存失败.\n" + ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void tsmiMapDocSave2_Click(object sender, EventArgs e) { if (mainMapControl.Map.LayerCount < 1) { MessageBox.Show("地图文档为空或出现异常,不能保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ICommand pCommand = new ControlsSaveAsDocCommandClass(); pCommand.OnCreate(mainMapControl.Object); pCommand.OnClick(); MessageBox.Show("地图文档保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void tsmiMapDocSaveAs_Click(object sender, EventArgs e) { try { if (mainMapControl.Map.LayerCount < 1) { MessageBox.Show("地图文档为空或出现异常,不能保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "另存为"; sfd.OverwritePrompt = true; sfd.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { string sFilePath = sfd.FileName; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.New(sFilePath); pMapDocument.ReplaceContents(mainMapControl.Map as IMxdContents); pMapDocument.Save(true, true); pMapDocument.Close(); MessageBox.Show("地图文档另存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("地图文档另存失败.\n" + ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void tsmiAddXY2PointShp_Click(object sender, EventArgs e) { try { LoadTxtXY2PointShpForm frmLoadTxtXY2PointShp = new LoadTxtXY2PointShpForm(); frmLoadTxtXY2PointShp.CurMapControl = mainMapControl; frmLoadTxtXY2PointShp.CurTOCControl = axTOCControl1; //frmLoadTxtXY2PointShp.Show(); frmLoadTxtXY2PointShp.ShowDialog(); } catch (Exception ex) { MessageBox.Show("加载TXT/CSV的XY点数据失败!\n" + ex.Message, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } } private void tsmiZoomIn_Click(object sender, EventArgs e) { mainMapControl.CurrentTool = null; pMouseOperate = "ZoomIn"; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerZoomIn; } private void tsmiZoomOut_Click(object sender, EventArgs e) { mainMapControl.CurrentTool = null; pMouseOperate = "ZoomOut"; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerZoomOut; } private void tsmiZoomInStep_Click(object sender, EventArgs e) { IEnvelope pEnvelope = mainMapControl.Extent; pEnvelope.Expand(0.5, 0.5, true); mainMapControl.Extent = pEnvelope; mainMapControl.ActiveView.Refresh(); } private void tsmiZoomOutStep_Click(object sender, EventArgs e) { //不指定中心点 //IEnvelopepEnvelope=mainMapControl.Extent; //pEnvelope.Expand(2, 2, true); //mainMapControl.Extent=pEnvelope; //mainMapControl.ActiveView.Refresh(); //指定中心点 IActiveView pActiveView = mainMapControl.ActiveView; IPoint centerPoint = new PointClass(); centerPoint.PutCoords((pActiveView.Extent.XMin + pActiveView.Extent.XMax) / 2, (pActiveView.Extent.YMax + pActiveView.Extent.YMin) / 2); IEnvelope envlope = pActiveView.Extent; envlope.Expand(1.5, 1.5, true); pActiveView.Extent.CenterAt(centerPoint); pActiveView.Extent = envlope; pActiveView.Refresh(); } private void tsmiPan_Click(object sender, EventArgs e) { mainMapControl.CurrentTool = null; pMouseOperate = "Pan"; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerPan; } private void tsmiFrontView_Click(object sender, EventArgs e) { pExtentStack = mainMapControl.ActiveView.ExtentStack; if (pExtentStack.CanUndo()) { pExtentStack.Undo(); tsmiForwardView.Enabled = true; if (!pExtentStack.CanUndo()) { tsmiFrontView.Enabled = false; } } mainMapControl.ActiveView.Refresh(); } private void tsmiForwardView_Click(object sender, EventArgs e) { pExtentStack=mainMapControl.ActiveView.ExtentStack; if (pExtentStack.CanRedo()) { pExtentStack.Redo(); tsmiFrontView.Enabled = true; if (!pExtentStack.CanRedo()) { tsmiForwardView.Enabled = false; } } mainMapControl.ActiveView.Refresh(); } private void tsmiFullExtent_Click(object sender, EventArgs e) { mainMapControl.Extent = mainMapControl.FullExtent; } private void tsmiMapMeasure_Click(object sender, EventArgs e) { ClearMeasureObject(); tsslMeasureResult.Text = "地图量测"; } private void tsmiLengthMeasure_Click(object sender, EventArgs e) { mainMapControl.CurrentTool = null; pMouseOperateBackup = "MeasureLength"; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair; tsslMeasureResult.Text = "距离量测"; } private void tsmiAreaMeasure_Click(object sender, EventArgs e) { mainMapControl.CurrentTool = null; pMouseOperateBackup = "MeasureArea"; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair; tsslMeasureResult.Text = "面积量测"; } private void mainMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { // tsslXY.Text =string.Format("{0}, {1} {2}", e.mapX.ToString("#######.####"), // e.mapY.ToString("#######.####"),mainMapControl.MapUnits.ToString().Substring(4)); sMapUnits = GetMapUnit(mainMapControl.Map.MapUnits); tsslXY.Text = String.Format("当前坐标:X={0:#.###}Y={1:#.###}{2}", e.mapX, e.mapY, sMapUnits); pMovePt = (mainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); switch (pMouseOperateBackup) { case "MeasureLength": //距离量测 if (pNewLineFeedback != null) { pNewLineFeedback.MoveTo(pMovePt); } double deltaX = 0; //两点之间X差值 double deltaY = 0; //两点之间Y差值 if ((pPointPt != null) && (pNewLineFeedback != null)) { deltaX = pMovePt.X - pPointPt.X; deltaY = pMovePt.Y - pPointPt.Y; dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)), 3); dTotalLength = dTotalLength + dSegmentLength; tsslMeasureResult.Text = String.Format("距离量测:当前线段{0:.####}{1};总长{2:.####}{1}", dSegmentLength, sMapUnits, dTotalLength); dTotalLength = dTotalLength - dSegmentLength; //鼠标移动到新点重新开始计算 } break; case "MeasureArea": //面积量测 if (pNewPolygonFeedback != null) { pNewPolygonFeedback.MoveTo(pMovePt); } IPointCollection pPointCol = new Polygon(); IPolygon pPolygon = new PolygonClass(); IGeometry pGeo = null; ITopologicalOperator pTopo = null; for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++) { pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing); } pPointCol.AddPoint(pMovePt, ref missing, ref missing); if (pPointCol.PointCount < 3) return; pPolygon = pPointCol as IPolygon; if ((pPolygon != null)) { pPolygon.Close(); pGeo = pPolygon as IGeometry; pTopo = pGeo as ITopologicalOperator; pTopo.Simplify(); pGeo.Project(mainMapControl.Map.SpatialReference); IArea pArea = pGeo as IArea; tsslMeasureResult.Text = String.Format("面积量测:总面积{0:.####}平方{1};总长度{2:.####}{1}", pArea.Area, sMapUnits, pPolygon.Length); pPolygon = null; } break; default: break; } } private void mainMapControl_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e) { switch (pMouseOperateBackup) { case "MeasureLength": //距离量测 if (pNewLineFeedback != null) { pNewLineFeedback.Stop(); pNewLineFeedback = null; //清空所画的线对象 (mainMapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null); } dTotalLength = 0; dSegmentLength = 0; break; case "MeasureArea": //面积量测 if (pNewPolygonFeedback != null) { pNewPolygonFeedback.Stop(); pNewPolygonFeedback = null; //清空所画的线对象 (mainMapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null); } pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //清空点集中所有点 break; default: break; } } } }以上是具体代码
10-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值