您好,欢迎来到微智科技网。
搜索
您的当前位置:首页ArcGIS软件自动分幅出图的实现

ArcGIS软件自动分幅出图的实现

来源:微智科技网
第3期 四川林勘设计 No.3 2011年9月 SICHUAN FORESTRY EXPLORATION AND DESIGN Sep.2011 ArcGIS软件自动分幅出图的实现 林勇 ,李逢吉 ,李德文 ,焦晋川 (1.四川省林业调查规划院,四川成都610081; 2.攀枝花市林业调查规划院,四川攀枝花617000) 摘要:以ArcGIS软件为平台,通过编写VBA代码解决了自动分幅出图的问题。经验 证,生成选择图幅号的打印布局按钮的VBA代码运行良好,可以精确、流畅地实现自动分 幅出图,有一定的推广价值。 关键词:GIS;分幅出图;林业制图 On the Automatical Printing of pictures Through ArcGIS Lin young ,Li Feng—ji ,Li De—wen ,Jiao Jin—chuan (1.Sichuan Forestry Survey and Planning Institute,Chengdu Sieuan 610081,China; 2.Panzhihua Forest Inventory nad Plan Institute;Panzhlhua Sieuan 617000;China) Abstract:Based on VBA,the output methods for automatic plane drawings of for- estry had been presented in ArcGIS.By the methods,the plane drawings meeting with demands are output easily by printer or plotter. Keywords:GIS,Plane drawings,Forestry mapping 在根据行政单位出图时,每个图层显示都可 1.2分幅对象 以是、完整的,这种方法对各种GIS软件都是 通过属性数据库建立、空间数据库建立、数据 较易实现的。但在按基本比例尺地形图分幅标准 联接以及成果图设计,完成四川省元坝区森林分 进行分幅绘制时,很多图层往往是分成了几部分 类区划图。 显示在各张图上,如果不能实现自动分幅出图则 2工作步骤 会给绘图工作带来很多麻烦。笔者以ArcGIS软 2.1 自动分幅数据的建立 件为平台,通过编写VBA代码解决了这一问题。 2.1.1分幅控制点数据的生成 1研究材料 为了分幅面数据生成得精确,分幅控制点按 1.1 AreGIS软件简介 基本比例尺(1:1万)地形图分幅标准进行生成。 ArcGIS是美国环境系统研究所(Environmen— 分幅控制点的生成顺序为:先在Execl中录入元 tal System Research Institute,ESRI)开发的新一代 坝区涉及方形区域地形图最左下角和最右上角经 软件,是世界上应用广泛的GIS软件之一,是一个 纬度的值,录入比例尺,由设计好的Excel文件自 全面、完善、可伸缩的GIS软件平台。无论单用 动生成需要的控制点坐标数值(L、B)(见图1), 户,还是多用户;无论是在桌面端,还是服务端、互 然后复制坐标数值生成一个Excel的坐标信息文 联网还是野外操作,都可以通过ArcGIS构建地理 件,最后在ArcMap中的Tools(工具栏)菜单下 信息系统。 打开Add XY Data模块(见图2)生成分幅控制点 ・收稿日期:201I一07—12 l ̄lJ{l林勘设计2oi1年第3期 图4联接数据示意图 与打印两个命令按钮,两个命令按钮含VBA代 码。窗体内容见图5。 图5分幅打印窗体图 2.4代码编写 通过VBA代码的编写,单击生成选择图幅号 的打印布局按钮,可生成选择图幅号的成果图;单 击打印按钮,根据需要,可把元坝区全部范围内的 分幅图自动转成JPG保存或直接打印。生成选 择图幅号的打印布局按钮的VBA代码含有8个 子过程。代码具体内容及步骤如下: Private Sub Command—Click() SetdataframesActivedfocus矢量激活矢量数据 框架 RemoveLayerF去除底图 Addlmage添加底图 movelayerdown把底图移到最底层 seleetoftable选择图幅号的记录 打印指定区域1万比例尺矢量设置打印区 域及比例尺 SetdataframesAetivedfoeus分幅图激活分幅图 数据框架 dd更新分幅色标 End Sub 打印按钮的VBA代码除含有生成选择图幅 号的打印布局按钮的VBA代码含有8个子过程 外,还增加了1个输出图片的子过程,另外还有还 增加了循环功能代码及打印代码,见以下代码: Private Sub CommandPrint_Cliek() Dim i As Long For i=l T0 83 TextTuhao.text=i SetdataframesActivedfoeus矢量激活矢量数据 框架 RemoveLayerF去除底图 Addlmage添加底图 movelayerdown把底图移到最底层 selectoftable选择图幅号的记录 打印指定区域1万比例尺矢量设置打印区 域及比例尺 SetdataframesAetivedfoeus分幅图徼活分幅图 数据框架 dd更新分幅色标 ExportActiveView输出图片 "Application.PrintDocument订印,根据要求, 与输出图片可只选择一样 Next i End Sub 9个子过程代码详见下: (1)激活矢量数据框架代码 Sub SetdataframesActivedfoeus矢量() Dim strName As String 林勇等:ArcGIS软件自动分幅出图的实现 85 strName=”矢量” Dim pMxDoc As IMxDocument tuhao=TextTuhao.text nameimgl=”E:\元坝分类经营\地形图、地 形图配准” nameimg2=”.img。’ nameimg nameimgl+tuhao+nameimg2 Set pMxDoc=ThisDocument Dim pMap As IMap Set pMap=GetMap(strName) If Not pMap Is Nothing Then If pMxDoe.ActiveView Is pMxDoc.PageLayout pRasterLayer.CreateFromFilePath nameimg Dim pMxDoc As IMxDocument Then Set pMxDoc.ActiveView.FocusMap =pMap Else Set pMxDoc.ActiveView=pMap End If Else Debug.Print”map not f0und:”&strName End If End Sub (2)去除底图代码 Sub RemoveLayerF() Dim pMxDocument As IMxDocument Dim pMap As IMap Dim pActiveView As IActiveView Dim pLayer As ILayer Set pMxDocument=Application.Document Set pMap pMxDocument.FocusMap Set pLayer=pMap.Layer(81 If Not pLayer Is Nothing I'hen pMap.DeleteLayer pLayer End If Set pActiveView=pMap pActiveView.Refresh End Sub (3)添加底图代码 Sub Addlmage() Dim pRasterLayer As IRasterLayer Set pRasterLayer=New RasterLayer Dim tuhao As String Dim nameimg As String Dim nameimgl As String Dim nameimg2 As String Set pMxDoc=ThisDocument pMxDoc.FocusMap.AddLayer pRasterLayer pMxDoc.CurrentContentsView.Refresh pRas. terLayer End Sub (4)把底图移到最底层代码 Sub movelayerdown() Dim pMxDocument As IMxDocument Dim pMap As IMap Dim pLayer As ILayer Set pMxDocument=Application.Document Set pMap pMxDocument.FocusMap Set pLayer=pMxDocument.SeleetedLayer Set pLayer=pMap.Layer(LayerCount) pMap.MoveLayer pLayer,pMap.LayerCount —l pMxDocument.ActiveView.Refresh pMxDocument.UpdateContents End Sub (5)选择图幅号的记录代码 Sub selectoftable() Dim pMxDoc As IMxDocument Set pMxDoe=ThisDocument Dim pMap As IMap Dim tuhao As String tuhao=TextTuhao.text Set pMap pMxDoc.FocusMap Dim PFLayer As IFeatureLayer Set PFLayer=pMap.Layer(1) Dim pQFilter As IQueryFilter Set pQFiher=New QueryFilter pQFilter.SubFields=”Name” 86 四川林勘设计2011年第3期 Set pMxDoc=ThisDocument Dim pEnumFeat As IEnumFeature Set pEnumFeat pMxDoe.FocusMap.Featur- pQFilter.WhereClause=”NAME= ’+tu— hao J-” ’ Dim pFSel As IFeatureSelection Set pFSel=PFLayer eSelection Dim pGeom As/Geometry pFSe1.SeleetFeatures pQFilter,esriSelection— ResuhNew,True Dim pActiveView As IActiveView pMxDoc.ActiveView.PartialRefresh esriView— GeoSelection,Nothing,Nothing End Sub (6)设置打印区域及比例尺 Sub打印指定区域1万比例尺矢量() Clip2selectedShapes 0似缓冲区0设置打印 区域 Dim intAns As Integer Dim pItem As ICommandItem Dim pMxDoc As IMxDocument Set pMxDoc=ThisDocument Dim pActiveView As IActiveView Set pActiveView pMxDoc.FocusMap Dim pGC As IGraphicsContainer Set pGC pMxDoc.PageLayout Dim pMapFrame As IMapFrame Set pMapFrame pGC.FindFrame(pMxDoc. FocusMap) pMapFrame.ExtentType=esriExtentDefault With ThisDocument.CommandBars Set pItem=.Find(Query_ZoomToSelected) pltem.Execute End With pMapFrame.ExtentType=esriExtentScale pMapFrame.MapScale=10000 pActiveView.Refresh pMxDoc.ActiveView.Refresh End Sub 以缓冲区0设置打印区域二级子过程代码 Sub Clip2SelectedShapes(dBuffDist As Doub— le Dim pMxDoc As IMxDocument Set pGeom=New Polygon Set pGeom.SpatialReference pMxDoc.Fo— cusMap.SpatialReference Dim pTopoOp As ITopologicalOperator Set pTopoOp=pGeom Dim pFeat As IFeature Set pFeat=pEnumFeat.Next Do Until pFeat Is Nothing Set pGeom=pFeat.ShapeCopy pGeom.Project pMxDoc.FocusMap.SpatialRef- erenCe Set pTopoOp=pTopoOp.Union(Buffer (pGeom,dBuffDist)) Set pFeat pEnumFeat.Next Loop pMxDoe.FocusMap.ClipGeometry pTopoOp pMxDoc.ActiveView.Refresh End Sub 激活矢量数据框架代码 Sub SetdataframesActivedfocus矢量() Dim strName As Stirng strName=”矢量” Dim pMxDoc As IMxDocument Set pMxDoc=ThisDocument Dim pMap As IMap Set pMap=GetMap(strName) IfNot pMap Is Nothing Then If pMxDoc.ActiveView Is pMxDoe.PageLayout Then Set pMxDoc.ActiveView.FocusMap pMap Else Set pMxDoc.ActiveView pMap EndⅡ Else 林勇等:AreGIS软件自动分幅出图的实现 87 Debug.Print”map not f0und:”&strName End If End Sub (7)激活分幅图数据框架代码 Sub SetdataframesActivedfocus分幅图() Dim strName As String strName=”分幅图” Dim pMxDoc As IMxDocument Set pMxDoc=ThisDocument Dim pMap As IMap Set pMap=GetMap(strName) If Not pMap Is Nothing Then If pMxDoc.ActiveView Is pMxDoc.PageLayout Then Set pMxDoc.ActiveView.FocusMap=pMap Else Set pMxDoc.ActiveView=pMap End If Else Debug.Print”map not f0und:”&strName End If End Sub (8)更新分幅色标代码 Sub dd() Dim pWSF As IWorkspaceFaetory Set pWSF=New AeeessWorkspaeeFaetory Dim pWorkspace As IWorkspace Dim tuhao As String tuhao=TextTuhao.text Set pWorkspace=pWSF.OpenFromFile(”E: \元坝分类经营: shp正式\更新图幅表.mdb”, 0) pWorkspace.ExecuteSQL”UPDATE分幅表 SET色标=1 WHERE Name=”十tuhao十” 2¨ pWorkspace.ExecuteSQL”UPDATE分幅表 SET色标=0 WHERE Name<> +tuhao+ ” 2劓 Dim pMxDoc As IMxDocument Set pMxDoc=ThisDocument pMxDoc.ActiveView.Refresh End Sub (9)输出图片代码 Sub ExpoaActiveView() Dim StrFileName As String Dim pMxDoe As IMxDoeument Dim pActiveView As IActiveView Dim pExport As IExpo ̄ Dim pExponJPEG As IExportJPEG Dim pPixelB0undsEnV As IEnvelope Dim exportRECT As tagRECT Dim iOutputResoluti0n As Integer Dim iScreenResolution As Integer Dim hDC As Long Dim tuhao As String tuhao=TextTuhao.text Set pMxDoc=Application.Document Set pActiveView pMxDoc.ActiveView Set pExport=New ExportJPEG StrFileName=”F: jPg\生态区位图”+ tuhao+”.jpg” pExport.ExportFileName=StrFileName iSereenResolution=96 iOutputResolution=400 pExport.Resolution =iOutputRes0lution Set pExportJPEG pExport pExportJPEG.Quality=80 With exportRECT .Left=0 .Top:0 .Right=pAetiveView.ExportFrame.Ri ght (i0utputResolution/iScreenResolution) .bottom=pActiveView.ExportFrame.bottom 术 (iOutputResolution/iScreenResolution) End With Set pPixe1BoundsEnV :New Envelope pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, expor— 88 四川林勘设计2011年第3期 tRECT.bottom 3运行结果 pExport.PixelBounds = pPixelB0undsEnV 运行结果表明,生成选择图幅号的打印布局 hDC=pExport.StartExporting 按钮的VBA代码运行良好,可以精确、流畅地实 pActiveView.Output hDC,pExport.Resolu— 现自动分幅出图。出图成果图图符清晰,图面美 tion,exportRECT,Nothing,Nothing 观,数据精确,能准确地表达区划结果的各项数据 pExport.FinishExporting 指标。该方法有一定的推广价值。 pExport.Cleanup 设计好的成果图表目录及成图见图6。 End SUb 5 0 15 20 M 00 , ∞  E々0 6 l∞ e5 l70 175 …… 口…省r元市元 E 盐林 班 目 图6成果图表目录及成图示意图 4参考文献 24(5):1l~15. 1林岚岚,张冰.地理信息系统在林业制图中的应 3王国荣,赖长鸿,谢云,等.基于ArcGIS在森林分 用[J].林业勘查设计,2006,(3):80~81. 类区划中的制图探索[J].四川1林业科技,2009, 2曾思齐,肖化顺,石军南.地理信息系统支持下的 30(4):78—81. 森林分类区划界定[J].中南林学院学报,2004, 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务