地图和图层的管理设计.doc

上传人:仙人指路1688 文档编号:3795293 上传时间:2023-03-22 格式:DOC 页数:61 大小:225.50KB
返回 下载 相关 举报
地图和图层的管理设计.doc_第1页
第1页 / 共61页
地图和图层的管理设计.doc_第2页
第2页 / 共61页
地图和图层的管理设计.doc_第3页
第3页 / 共61页
地图和图层的管理设计.doc_第4页
第4页 / 共61页
地图和图层的管理设计.doc_第5页
第5页 / 共61页
点击查看更多>>
资源描述

《地图和图层的管理设计.doc》由会员分享,可在线阅读,更多相关《地图和图层的管理设计.doc(61页珍藏版)》请在三一办公上搜索。

1、地图文档管理PageLayout地图管理图层管理Render一、 地图文档管理LXMXDDocument Class接口IMapDocment IMapControl3 IPageLayoutControl2功能:新建、打开、保存、另存、设置保存路径(相对还是绝对路径)、新建public bool CreateMapDocument(string mxdPath)方法功能:新建地图文档输入参数:string mxdPath 地图文档的保存路径返回参数:bool 值为True时,表示新建成功;值为False表示建立失败打开public bool OpenMap(string strPath,bo

2、ol bPageLayout)方法功能:在MapControl或PageLayout中打开给定的图文件输入参数:string strMXDPath 打开的地图文档路径及文件名 bool bPageLayout 是否用PageLayout打开地图返回参数: bool 值为True时,表示打开成功;值为False表示打开失败保存public bool SaveMapDocument(string pSMxdFile,string pTMxdFile)方法功能 保存MXD文件输入参数 string pSMxdFile 源MXD文件名string pTMxdFile 目标MXD文件名注意pSMxdFi

3、le与pTMxdFile相等返回参数:bool 值为True时,表示保存成功;值为False表示保存失败另存public bool SaveAsMapDocument(string pSMxdFile,string pTMxdFile)方法功能 保存MXD文件输入参数 string pSMxdFile 源MXD文件名string pTMxdFile 目标MXD文件名注意pSMxdFile与pTMxdFile不相等返回参数:bool 值为True时,表示保存成功;值为False表示保存失败设置保存路径public bool SetDSavePath(string dSavePath)方法功能:设

4、置文档保存路径 注意是相对还是绝对 (还是有点疑问,是否要放在系统配置中)输入参数:string dSavePath 文档保存路径返回参数:bool 值为True表示设置成功;值为False表示设置失败 地图文档打印Private Function MapPrint()On Error GoTo ErrorHandler If PageLayoutCtrl.Printer Is Nothing Then MsgBox 没有打印机, , 提示 Exit Function End If Dim pPrinter As IPrinter Set pPrinter = PageLayoutCtrl.P

5、rinter If pPrinter.Paper.Orientation PageLayoutCtrl.Page.Orientation Then pPrinter.Paper.Orientation = PageLayoutCtrl.Page.Orientation End If Dim dWidth As Double, dHeight As Double pPrinter.QueryPaperSize dWidth, dHeight PageLayoutCtrl.PrintPageLayout 打印 PageLayoutCtrl.MousePointer = esriPointerDef

6、ault Exit FunctionErrorHandler: ErrorOperate Err.Description, Erl, c_sModuleFileName, MapPrintSettingEnd Function地图文档打印设置Private Function MapPrintSetting()On Error GoTo ErrorHandler If Not ShowPrinterSet Then Exit Function 如果取消就退出 If PageLayoutCtrl.Printer Is Nothing Then MsgBox 没有打印机, , 提示 Exit Fun

7、ction End If Dim dWidth As Double, dHeight As Double, iUnits As Integer Dim pPrinter As IPrinter Set pPrinter = PageLayoutCtrl.Printer pPrinter.Paper.FormID = Printer.PaperSize pPrinter.Paper.Orientation = Printer.Orientation dWidth = pPrinter.Paper.PrintableBounds.Envelope.Width dHeight = pPrinter.

8、Paper.PrintableBounds.Envelope.Height With PageLayoutCtrl.Page .FormID = esriPageFormCUSTOM 自定义纸张大小(看到的) iUnits = .Units .Units = pPrinter.Units .Orientation = pPrinter.Paper.Orientation .PutCustomSize dWidth, dHeight .StretchGraphicsWithPage = False .QuerySize dWidth, dHeight End With Dim pFrameEle

9、ment As IFrameElement Dim pElement As IElement Dim pMapFrame As IMapFrame Set pFrameElement = PageLayoutCtrl.ActiveView.GraphicsContainer.FindFrame(PageLayoutCtrl.ActiveView.FocusMap) If Not (pFrameElement Is Nothing) Then Set pMapFrame = pFrameElement Set pElement = pMapFrame Dim pEnvelope As IEnve

10、lope Set pEnvelope = pElement.Geometry.Envelope With pEnvelope .Height = dHeight - .YMin * 2 根据纸张变化重新设定地图框大小 .Width = dWidth - .XMin * 2 End With pElement.Geometry = pEnvelope Dim pGraphicsContainer As IGraphicsContainer Set pGraphicsContainer = PageLayoutCtrl.PageLayout pGraphicsContainer.UpdateEle

11、ment pElement End If PageLayoutCtrl.Page.Units = iUnits PageLayoutCtrl.ActiveView.Refresh Exit FunctionErrorHandler: If Err.Number = 32755 Then Exit Function user pressed cancel ErrorOperate Err.Description, Erl, c_sModuleFileName, MapPrintSettingEnd Function二、 PageLayout模版切合(Maps类)、视图切换Public Funct

12、ion f_PageLayout_CreateEnvelope(PageLayoutControl1 As IPageLayoutControl2, lXmin As Long, lYmin As Long, lXmax As Long, lYmax As Long) As IEnvelope函数功能:创建一个范围编写人 helen编写日期 2004/5/25 Set f_PageLayout_CreateEnvelope = Nothing Get the IPoint interface by creating points is the current page units Dim pP

13、ointMin As IPoint Dim pPointMax As IPoint Set pPointMin = PageLayoutControl1.ToPagePoint(lXmin, lYmin) Set pPointMax = PageLayoutControl1.ToPagePoint(lXmax, lYmax) Get the IEnvelope interface Dim pEnvelope As IEnvelope Set pEnvelope = New Envelope Set the envelope coordinates pEnvelope.PutCoords pPo

14、intMin.X, pPointMin.y, pPointMax.X, pPointMax.y Set f_PageLayout_CreateEnvelope = pEnvelopeEnd FunctionPublic Function ChangeLayout(Optional firstPath As String) As Integer函数功能: 切换地图模版编写人 wufayun编写日期 2006/04/02参数: Optional firstPath As String 初始化打开对话框的路径返回值: = -1 地图模版路径为空;= -3 您加载的地图模版文件有错误;= -2 用户单

15、击的是取消;= -4 未知错误;= 1 成功On Error GoTo ErrorHandlerfirstPath初始路径 CommonDialog1.DialogTitle = 打开地图模版 CommonDialog1.Filter = 地图模版 (*.mxt)|*.mxt CommonDialog1.InitDir = firstPath CommonDialog1.CancelError = True CommonDialog1.ShowOpen Exit if no map document is selected Dim MXTFilePath As String MXTFilePa

16、th = CommonDialog1.FileName If MXTFilePath = Then ChangeLayout = -1 地图模版路径为空 Exit Function End If If Not PageLayoutCtrl.CheckMxFile(MXTFilePath) Then ChangeLayout = -3 您加载的地图模版文件有错误 Exit Function End If PageLayoutCtrl.LoadMxFile MXTFilePath Dim pMaps As IMaps Set pMaps = New Maps Dim pMap As IMap Se

17、t pMap = m_pMapDocument.Map(0) pMaps.Add pMap PageLayoutCtrl.PageLayout.ReplaceMaps pMaps PageLayoutCtrl.ActiveView.Activate PageLayoutCtrl.hwnd m_pMapDocument.ReplaceContents PageLayoutCtrl.PageLayout TOCControl1.SetBuddyControl PageLayoutCtrl ChangeLayout = 1 成功 Exit FunctionErrorHandler: If Err.N

18、umber = cdlCancel Then 判断用户单击的是取消 ChangeLayout = -2 用户单击的是取消 Else ChangeLayout = -4 未知错误 End IfEnd Function三、 地图管理LXMap Class接口 IMap IActiveView功能:地图输出为图片、比例尺设置、显示单位设置、地图空间参考设置新建并添加图层组、添加图层、移去图层、图层顺序调整(功能性的)地图输出为图片public bool ExportMapToFile(string pfileName)方法功能:把地图导出到指定格式的图象文件中(*.jpg;*.pdf;*.bmp;*

19、.tif) 注:使用IExporter的接口,比如用JpegExporter实例化,把地图转换成jpg输入参数:pFileName type String,图象文件全名返回参数:bool参数示例: pFileName=d:aa.bmp(此处应该是反斜线的单线吧)比例尺设置public bool SetMapScale(double pScale)方法功能:地图比例尺设置输入参数:double pScale 比例尺大小返回参数:bool要加获取比例尺么public ISpatialReference GetMapPRJ(integer pZone, integer pZoneType,integ

20、er iPrj )方法功能:设置地图空间参考输入参数:integer pZone 表示带号integer pZoneType 值为1 表示 3度带 值为2 表示 6度带integer iPrj iPrj=1表示北京54 iPrj=2 表示西安80返回参数:ISpatialReferencepublic ISpatialReference GetMapPRJ(IMap pMap)方法功能:获取地图空间参考输入参数:IMap pMap返回参数:ISpatialReferencePublic Function f_Coordinate_GetUnitDescription(pUnits As esr

21、iUnits) As String函数功能:显示单位设置On Error GoTo eH f_Coordinate_GetUnitDescription = 未知 Select Case pUnits Case esriInches: f_Coordinate_GetUnitDescription = 英寸 Case esriPoints: f_Coordinate_GetUnitDescription = 点 Case esriFeet: f_Coordinate_GetUnitDescription = 英尺 Case esriYards: f_Coordinate_GetUnitDesc

22、ription = 码 Case esriMiles: f_Coordinate_GetUnitDescription = 英里 Case esriNauticalMiles: f_Coordinate_GetUnitDescription = 海里 Case esriMillimeters: f_Coordinate_GetUnitDescription = 毫米 Case esriCentimeters: f_Coordinate_GetUnitDescription = 厘米 Case esriMeters: f_Coordinate_GetUnitDescription = 米 Cas

23、e esriKilometers: f_Coordinate_GetUnitDescription = 公里 Case esriDecimalDegrees: f_Coordinate_GetUnitDescription = 度 Case esriDecimeters: f_Coordinate_GetUnitDescription = 度 Case esriUnknownUnits: f_Coordinate_GetUnitDescription = 未知 Case Else: f_Coordinate_GetUnitDescription = 未知 End SelecteH:End Fu

24、nction地图刷新Public Function MapRefresh() As Boolean Dim pActiveView As IActiveView MapRefresh = False If m_Map Is Nothing Then Exit Function Set pActiveView = m_Map pActiveView.Refresh MapRefresh = TrueEnd Function放大地图Public Function MapZoomIn() Dim point1 As IPoint Dim lZoomInKey As Long Dim pEnvelop

25、e As IEnvelope lZoomInKey = GetKeyState(vbKeyAdd) If lZoomInKey And &H8000 Then Set point1 = New point point1.x = MapCtrl.Extent.XMin + MapCtrl.Extent.Width / 2 point1.y = MapCtrl.Extent.YMin + MapCtrl.Extent.Height / 2 Set pEnvelope = MapCtrl.ActiveView.Extent pEnvelope.Height = pEnvelope.Height /

26、1.5 pEnvelope.Width = pEnvelope.Width / 1.5 pEnvelope.CenterAt point1 MapCtrl.ActiveView.Extent = pEnvelope MapCtrl.ActiveView.PartialRefresh esriViewGeography, Nothing, Nothing MapCtrl.ActiveView.Refresh End If Set point1 = Nothing Set pEnvelope = NothingEnd Function放大地图Public Function MapZoomOut()

27、 Dim point1 As IPoint Dim lZoomOutKey As Long Dim pEnvelope As IEnvelope lZoomOutKey = GetKeyState(vbKeySubtract) If lZoomOutKey And &H8000 Then Set point1 = New point point1.x = MapCtrl.Extent.XMin + MapCtrl.Extent.Width / 2 point1.y = MapCtrl.Extent.YMin + MapCtrl.Extent.Height / 2 Set pEnvelope =

28、 MapCtrl.ActiveView.Extent pEnvelope.Height = pEnvelope.Height * 1.5 pEnvelope.Width = pEnvelope.Width * 1.5 pEnvelope.CenterAt point1 MapCtrl.ActiveView.Extent = pEnvelope MapCtrl.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing MapCtrl.ActiveView.Refresh End If Set point1 = Nothing Set

29、 pEnvelope = NothingEnd Function下移地图Public Function MapMoveDown() Dim point1 As IPoint Dim lDownKey As Long Dim pEnvelope As IEnvelope lDownKey = GetKeyState(vbKeyDown) If lDownKey And &H8000 Then Set point1 = New point point1.x = MapCtrl.Extent.XMin + MapCtrl.Extent.Width / 2 point1.y = MapCtrl.Ext

30、ent.YMin + MapCtrl.Extent.Height / 2 - MapCtrl.Extent.Height / 5 MapCtrl.CenterAt point1 MapCtrl.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing End If Set point1 = Nothing Set pEnvelope = NothingEnd Function左移地图Public Function MapMoveLeft() Dim point1 As IPoint Dim lLeftKey As Long Dim

31、 pEnvelope As IEnvelope lLeftKey = GetKeyState(vbKeyLeft) If lLeftKey And &H8000 Then Set point1 = New point point1.x = MapCtrl.Extent.XMin + MapCtrl.Extent.Width / 2 - MapCtrl.Extent.Width / 5 point1.y = MapCtrl.Extent.YMin + MapCtrl.Extent.Height / 2 MapCtrl.CenterAt point1 MapCtrl.ActiveView.Part

32、ialRefresh esriViewGraphics, Nothing, Nothing End If Set point1 = Nothing Set pEnvelope = NothingEnd Function右移地图Public Function MapMoveRight() Dim point1 As IPoint Dim lRightKey As Long Dim pEnvelope As IEnvelope lRightKey = GetKeyState(vbKeyRight) If lRightKey And &H8000 Then Set point1 = New poin

33、t point1.x = MapCtrl.Extent.XMin + MapCtrl.Extent.Width / 2 + MapCtrl.Extent.Width / 5 point1.y = MapCtrl.Extent.YMin + MapCtrl.Extent.Height / 2 MapCtrl.CenterAt point1 MapCtrl.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing End If Set point1 = Nothing Set pEnvelope = NothingEnd Functi

34、on上移地图Public Function MapMoveUp() Dim point1 As IPoint Dim lUpKey As Long Dim pEnvelope As IEnvelope lUpKey = GetKeyState(vbKeyUp) If lUpKey And &H8000 Then Set point1 = New point point1.x = MapCtrl.Extent.XMin + MapCtrl.Extent.Width / 2 point1.y = MapCtrl.Extent.YMin + MapCtrl.Extent.Height / 2 + M

35、apCtrl.Extent.Height / 5 MapCtrl.CenterAt point1 MapCtrl.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing End If Set point1 = Nothing Set pEnvelope = NothingEnd FunctionGetAllFeatureLGetAllRasterLGetFeatureL四、 图层管理LXLayer Class接口 Ilayer IFeatureLayer IRasterLayer功能:获得图层、可见比例尺范围设置、数据源设置、可

36、见性设置、可选性设置、透明度设置、图层可见要素设置、Public Function f_Layer_GetLayerName(pLayer As ILayer, pLayerNameType As Integer) As String f_Layer_GetLayerName = If pLayer Is Nothing Then Exit Function Dim i_LabelName As String 图层的Layer别名 Dim i_DataSetName As String 图层的Dataset名 Dim i_DataSetFullName As String 图层的Dataset

37、全名 Dim i_LayerFullName As String 图层的(Layer别名+Dataset全名) Dim i_WSName As String 图层所在数据库带路径的全名 i_LabelName = pLayer.Name If TypeOf pLayer Is IFeatureLayer Then Dim i_FeatureLayer As IFeatureLayer Set i_FeatureLayer = pLayer If i_FeatureLayer Is Nothing Then Exit Function Dim i_FeatureClass As IFeature

38、Class Set i_FeatureClass = i_FeatureLayer.FeatureClass If i_FeatureClass Is Nothing Then Exit Function Dim i_Dataset As IDataset Set i_Dataset = i_FeatureClass If i_Dataset Is Nothing Then Exit Function Dim i_workspace As IWorkspace Set i_workspace = i_Dataset.Workspace If i_workspace Is Nothing The

39、n Exit Function i_DataSetName = i_Dataset.Name i_DataSetFullName = i_workspace.PathName & - & i_Dataset.Name i_WSName = i_workspace.PathName ElseIf TypeOf pLayer Is IRasterLayer Then Dim i_RasterLayer As IRasterLayer Set i_RasterLayer = pLayer If i_RasterLayer Is Nothing Then Exit Function Dim i_Ras

40、ter As IRaster Set i_Raster = i_RasterLayer.Raster If i_Raster Is Nothing Then Exit Function i_DataSetName = i_RasterLayer.filePath End If i_LayerFullName = i_LabelName & , & i_DataSetFullName If pLayerNameType = 1 Then f_Layer_GetLayerName = i_LabelName If pLayerNameType = 2 Then f_Layer_GetLayerNa

41、me = i_DataSetFullName If pLayerNameType = 3 Then f_Layer_GetLayerName = i_LabelName & , & i_DataSetFullName If pLayerNameType = 4 Then f_Layer_GetLayerName = i_DataSetName If pLayerNameType = 5 Then f_Layer_GetLayerName = i_WSName 显示该图层所在的组名 Dim i_GroupLayer As IGroupLayer Set i_GroupLayer = f_Layer_GetLayerGroup(pApp, pLayer) If Not

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号