实例介绍
【实例简介】
ArcGis Engine 示例
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | 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小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论