AE开发之地图加载.doc_第1页
AE开发之地图加载.doc_第2页
AE开发之地图加载.doc_第3页
AE开发之地图加载.doc_第4页
AE开发之地图加载.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

using System;using System.Collections.Generic;using System.Linq;using System.Text;using ESRI.ArcGIS.AnalysisTools;using ESRI.ArcGIS.Analyst3D;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.DisplayUI;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.GlobeCore;using ESRI.ArcGIS.Output;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.DataSourcesRaster;using ESRI.ArcGIS.DataSourcesRasterUI;using System.Windows.Forms;using System.Drawing;using ESRI.ArcGIS.DataSourcesFile;namespace AEExercise public class GeoMapLoad public static IMapDocument pMapDocument;/定义地图文档接口变量 public static int count=0; public static IRgbColor pColor;/设置颜色 public static string text=空;/标注内容 public static void CreateMeasuredGrid(AxPageLayoutControl axPageLayoutControl1) /设置格网点 ISnapGrid pSnapGrid; IPageLayout pPageLayout = axPageLayoutControl1.PageLayout; pSnapGrid = pPageLayout.SnapGrid;/获取PageLayout的SnapGrid对象 pSnapGrid.VerticalSpacing = 2;/设置垂直间距 pSnapGrid.HorizontalSpacing = 1; pSnapGrid.IsVisible = true;/设置为可见 axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); public static void operatePageLayout(AxPageLayoutControl axPageLayoutControl1, string opt, IEnvelope pEnv,int strBarType=0) switch (opt) case AddScale: if (count 0) return; IScaleBar pScaleBar; IMapFrame pMapFrame; IMapSurroundFrame pMapSurroundFrame; IMapSurround pMapSurround; IElementProperties pElementPro; /产生一个UID对象,使用它产生不同的MapSurround对象 UID pUID = new UIDClass(); pUID.Value = esriCarto.scalebar; IPageLayout pPageLayout; pPageLayout = axPageLayoutControl1.PageLayout; IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pPageLayout as IGraphicsContainer; IActiveView pActiveView; pActiveView = pGraphicsContainer as IActiveView; IMap pMap; pMap = pActiveView.FocusMap; /获得于地图相关的MapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; /产生MapsurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null); /依据传入参数不同使用不同类型的比例尺 MessageBox.Show(strBarType.ToString(); switch (strBarType) case 0: /西安交互比例尺 pScaleBar = new AlternatingScaleBarClass(); break; case 1: /双线交互比例尺 pScaleBar = new DoubleAlternatingScaleBarClass(); break; case 2: /中空式比例尺 pScaleBar = new HollowScaleBarClass(); break; case 3: /线式比例尺 pScaleBar = new ScaleLineClass(); break; case 4: /分割式比例尺 pScaleBar = new SingleDivisionScaleBarClass(); break; case 5: /阶梯式比例尺 pScaleBar = new SteppedScaleLineClass(); break; default: pScaleBar = new ScaleLineClass(); break; pScaleBar.Division = 4; pScaleBar.Divisions = 4; pScaleBar.LabelGap = 4; pScaleBar.LabelPosition = esriVertPosEnum.esriAbove; pScaleBar.Map = pMap; pScaleBar.Name = 比例尺; pScaleBar.Subdivisions = 2; pScaleBar.UnitLabel = 千米; pScaleBar.UnitLabelGap = 4; pScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAbove; pScaleBar.Units = esriUnits.esriKilometers; pMapSurround = pScaleBar; pMapSurroundFrame.MapSurround = pMapSurround; pElementPro = pMapSurroundFrame as IElementProperties; pElementPro.Name = my scalebar; /将MapSurrooundFrame对象添加到控件中 axPageLayoutControl1.AddElement(pMapSurroundFrame as IElement, pEnv, Type.Missing, Type.Missing, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; public void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType) /定义打开文件对话框 OpenFileDialog OpenFileDlg = new OpenFileDialog(); /定义保存文件对话框 SaveFileDialog SaveFileDlg = new SaveFileDialog(); OpenFileDlg.Filter = 地图文档文件(*.mxd)|*.mxd; SaveFileDlg.Filter = 地图文档文件(*.mxd)|*.mxd; string strDocFileN = string.Empty; pMapDocument = new MapDocumentClass(); /判断操作文档地图的类型 switch (strOperateType) case NewDoc: SaveFileDlg.Title = 输入需要新建地图文档的名称; SaveFileDlg.ShowDialog(); strDocFileN = SaveFileDlg.FileName; if (strDocFileN = string.Empty) return; pMapDocument.New(strDocFileN); pMapDocument.Open(strDocFileN, ); axMapControl1.Map = pMapDocument.get_Map(0); break; case OpenDoc: OpenFileDlg.Title = 选择需要加载的地图文档文件; OpenFileDlg.ShowDialog(); strDocFileN = OpenFileDlg.FileName; if (strDocFileN = string.Empty) return; /将数据加载入pMapDocument并与map控件联动起来 pMapDocument.Open(strDocFileN, ); for (int i = 0; i pMapDocument.MapCount; i+) /遍历可能的Map对象 axMapControl1.Map = pMapDocument.get_Map(i); /axMapControl2.Map = pMapDocument.get_Map(i); /刷新地图 axMapControl1.Refresh(); break; case SaveDoc: /判断文档是否为只读文档 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) = true) MessageBox.Show(此地图文档为只读文档!, 信息提示); return; /用相对路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show(保存成功!, 信息提示); break; case SaveDocAs: SaveFileDlg.Title = 地图文档另存; SaveFileDlg.ShowDialog(); strDocFileN = SaveFileDlg.FileName; if (strDocFileN = string.Empty) return; if (strDocFileN = pMapDocument.DocumentFilename) /将修改后的地图文档保存在原文件中 /用相对路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show(保存成功!, 信息提示); break; else /将修改后的地图文档保存为新文件 pMapDocument.SaveAs(strDocFileN, true, true); MessageBox.Show(保存成功!, 信息提示); break; default: break; public void SetColor() pColor = getRGBColor(); public void MapOperate(AxMapControl axMapControl1, IMapControlEvents2_OnMouseDownEvent e, string strOperat) if (pColor = null) pColor = new RgbColorClass(); pColor.Blue = 5; pColor.Red = 213; pColor.Green = 9; switch (strOperat) case strLKoper: axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; axMapControl1.Extent = axMapControl1.TrackRectangle(); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); break; case strMapPan: axMapControl1.Pan(); break; /绘制线 case strDrawLine: /绘制线 IMap pMap; IActiveView pActiveView; pMap = axMapControl1.Map; pActiveView = pMap as IActiveView; IPolyline pPolyline; pPolyline = axMapControl1.TrackLine() as IPolyline; /产生一个SimpleLineSymbol符号 ISimpleLineSymbol pSimpleLineSym; pSimpleLineSym = new SimpleLineSymbolClass(); pSimpleLineSym.Style = esriSimpleLineStyle.esriSLSSolid;/需要用户动态选择 /设置符号颜色 pSimpleLineSym.Color = pColor;/需要用户动态选择 pSimpleLineSym.Width = 1; /产生一个PolylineElement对象 ILineElement pLineEle; pLineEle = new LineElementClass(); IElement pEle; pEle = pLineEle as IElement; pEle.Geometry = pPolyline; try /将元素添加到Map对象之中 IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pMap as IGraphicsContainer; pGraphicsContainer.AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); catch(ExecutionEngineException e3) MessageBox.Show(两点距离太近); return; break; /绘制面 case strDrawPolygon: /绘制面 IMap pMap; IActiveView pActiveView; pMap = axMapControl1.Map; pActiveView = pMap as IActiveView; IPolygon pPolygion; pPolygion = axMapControl1.TrackPolygon() as IPolygon; /产生一个SimpleFillSymbol符号 ISimpleFillSymbol pSimpleFillSym; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Style = esriSimpleFillStyle.esriSFSDiagonalCross;/需要用户动态选择 pSimpleFillSym.Color = pColor;/需要用户动态选择 /产生一个PolygonElement对象 IFillShapeElement pPolygonEle; pPolygonEle = new PolygonElementClass(); pPolygonEle.Symbol = pSimpleFillSym; IElement pEle; pEle = pPolygonEle as IElement; pEle.Geometry = pPolygion; /将元素添加到Map对象之中 IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pMap as IGraphicsContainer; pGraphicsContainer.AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; /地图标注 case strMapLable: /地图标注 IMap pMap; IActiveView pActiveView; pMap = axMapControl1.Map; pActiveView = pMap as IActiveView; ITextElement pTextEle; IElement pEles; /建立文字符号对象,并设置相应的属性 pTextEle = new TextElementClass(); pTextEle.Text = text; pEles = pTextEle as IElement; /设置文字字符的几何形体属性 IPoint pPoint; pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); pEles.Geometry = pPoint; /添加到Map对象中,并刷新显示 IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pMap as IGraphicsContainer; pGraphicsContainer.AddElement(pEles, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; case strSelect: /要素选择 /得到一个 包络线Envelope对象 IEnvelope pEnv; pEnv = axMapControl1.TrackRectangle(); /新建选择集环境对象 ISelectionEnvironment pSelectionEnv; pSelectionEnv = new SelectionEnvironmentClass(); /改变选择集的默认颜色 pSelectionEnv.DefaultColor = pColor; /选择要素,并将其放入选择集 axMapControl1.Map.SelectByShape(pEnv, pSelectionEnv, false); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); /需要遍历所选要素 break; case LKselect: IMap pMap; IActiveView pActiveView; pMap = axMapControl1.Map; pActiveView = pMap as IActiveView; IEnvelope pEnv; pEnv = axMapControl1.TrackRectangle(); ISelectionEnvironment pSelct; pSelct = new SelectionEnvironmentClass(); pSelct.DefaultColor = pColor; pMap.SelectByShape(pEnv, pSelct, false); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); break; case PointSelect: IMap pMap; IActiveView pActiveView; pMap = axMapControl1.Map; pActiveView = pMap as IActiveView; IPoint pPt; pPt = new PointClass(); pPt.PutCoords(e.mapX, e.mapY); IEnumElement pEnumEle; /选择元素,其中1为容差 IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pMap as IGraphicsContainer; pEnumEle = pGraphicsContainer.LocateElements(pPt, 10);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论