《地理信息系统设计与开发》实验指导书(黑体,小3号)课程编号:地理信息系统设计与开发课程英文名称:DesignandDevelopmentofGeographicInformationSystem学时数:36学分数:3适用层次和专业:地理信息系统及测绘工程本科实验一安装MO和VB1.实验目的学习安装MO学习安装VB6熟悉VB6开发环境2.实验内容安装VB6.0安装MO2.3或更高版本在VB窗体中添加MO组件为MO组件添加数据china.shp实验二视图缩放和全图操作1.实验目的掌握MO控件的一般使用方式2.实验内容添加地图控件,通过设置地图控件的属性添加数据在窗体上增加一个按钮,双击这个按钮,在代码窗口中输入以下代码PrivateSubCommand1_Click()SetMap1.Extent=Map1.FullExtentEndSub双击地图控件为他的事件MouseDown增加以下代码PrivateSubMap1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)IfButton=vbLeftButtonThenSetMap1.Extent=Map1.TrackRectangleEndIfEndSub进一步操作PopUpMenu(右键菜单)使用菜单编辑器生成一个右键菜单Popup1,为Popup1建立以下几个子菜单项“显示全图”“放大”“缩小”编写代码实现“显示全图”的功能;PrivateSubpop1Full_Click()Map1.Extent=Map1.FullExtentEndSub修改Mouse事件中的代码,显示右键菜单PrivateSubMap1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)IfButton=vbLeftButtonThenSetMap1.Extent=Map1.TrackRectangleElse:Button=vbRightButtonPopupMenupop1EndIfEndSub进一步操作:工具栏ToolBar在窗体上放置ImageList控件设置ImageList1的属性,增加图片ZoomIn.bmp;ZoomOut.bmp;Pan.bmp;Globe.bmp(这些文件在光盘目录BitMaps下)在窗体上放置ToolBar控件设置ToolBar1的属性,将ToolBar1的图像列表设置为ImageList1;增加按钮ZoomIn,ZoomOut,Pan,设置样式为2-tbrButtonGroup,并设置相应的显示图片;增加第4个按钮设置样式为4-tbrPlaceholder;增加第5个按钮btnFullExtent设置图片为Globe.bmp注意:VB控件库MicrosoftWindowsCommonControls6.0中包含ToolBar和ImageList控件实验三动态加载图层1.实验目的掌握CommandDialog组件添加图层的方法练习VB中添加按钮的一般方法2.实验内容导入CommandDialog组件,这一组件在对象库MicrosoftCommonDialogControl6.0中。添加Map控件,ConmonDialog控件,并将其名称改为cDlg1,添加一个按钮.程序代码:PrivateSubCommand1_Click()DimshpLayerAsNewMapObjects2.MapLayerDimDCAsNewMapObjects2.DataConnectionDimgdsAsMapObjects2.GeoDatasetDimFNameAsStringcDlg1.Filter=ESRIShape文件(*.shp)|*.shpcDlg1.CancelError=TrueOnErrorGoToeTrapcDlg1.ShowOpenIfLen(cDlg1.FileName)=0ThenExitSubDC.Database=CurDirIfNotDC.ConnectThenExitSubFName=Left(cDlg1.FileTitle,Len(cDlg1.FileTitle)-4)Setgds=DC.FindGeoDataset(FName)IfgdsIsNothingThenExitSubSetshpLayer.GeoDataset=gdsMap1.Layers.AddshpLayerExitSubeTrap:IfErr.NumbercdlCancelThenMsgBoxErr.Description,vbCriticalEndIfEndSub实验四调整图层顺序1.实验目的掌握在MO当中如何调整图层顺序2.实验内容‘置顶当前图层PrivateSublstLayers_DblClick()DimlyrAsMapObjects2.MapLayerIflstLayers.ListIndex-1ThenMap1.Layers.MoveToToplstLayers.ListIndexMap1.RefreshlstLayers.ClearForEachlyrInMap1.LayerslstLayers.AddItemlyr.NameNextlyrEndIfEndSub‘上移图层PrivateSubCommand2_Click()DimiAsIntegerDimlyrAsMapObjects2.MapLayerIflstLayers.ListIndex-1AndlstLayers.ListIndex0Theni=lstLayers.ListIndex-1Map1.Layers.MoveTolstLayers.ListIndex,iMap1.RefreshlstLayers.ClearForEachlyrInMap1.LayerslstLayers.AddItemlyr.NameNextlyrlstLayers.Selected(i)=TrueEndIfEndSub‘下移图层PrivateSubCommand4_Click()DimiAsIntegerDimlyrAsMapObjects2.MapLayerIflstLayers.ListIndex-1AndlstLayers.ListIndexlstLayers.ListCount-1Theni=lstLayers.ListIndex+1Map1.Layers.MoveTolstLayers.ListIndex,iMap1.RefreshlstLayers.ClearForEachlyrInMap1.LayerslstLayers.AddItemlyr.NameNextlyrlstLayers.Selected(i)=TrueEndIfEndSub实验五取消图层调入和动态跟踪层1.实验目的掌握取消图层调入掌握动态跟踪层的使用2.实验内容‘取消图层调入,运行时设置Map.CancelAction=moCancelMap添加一个command1按钮。增加事件Command1_Click()。添加在运行时添加图层的代码添加事件Map1_DrawingCanceled()PrivateSubMap1_DrawingCanceled()MsgBoxthelayer(orlayers)hasbeencanceled!EndSub‘TrackingLayer动态跟踪DimptAsNewMapObjects2.Point'convertthepointtomapcoordinatesSetpt=Map1.ToMapPoint(X,Y)'addaneweventMap1.TrackingLayer.AddEventpt,symIndex实验六缓冲区1.实验目的掌握使用缓冲区功能2.实验内容PrivateSubForm_Load()Map1.TrackingLayer.SymbolCount=2WithMap1.TrackingLayer.Symbol(0).SymbolType=moPointSymbol.Style=moCircleMarker.Color=moRed.Size=3EndWithWithMap1.TrackingLayer.Symbol(1).SymbolType=moFillSymbol.Style=moGrayFill.Color=moRed.OutlineColor=moRedEndWithEndSubPrivateSubMap1_AfterTrackingLayerDraw(ByValhDCAsstdole.OLE_HANDLE)Dimsym1AsNewMapObjects2.Symbolsym1.SymbolType=moFillSymbolsym1.Style=moTransparentFillsym1.OutlineColor=moBlackMap1.DrawShapeMap1.FullExtent,sym1EndSub查看各顶点的M属性地图数据:ynroadsm.shpDimlineAsNewMapObjects2.lineDimrecsAsNewMapObjects2.RecordsetDimrecCountAsIntegerDimiAsIntegerList1.ClearSetrecs=Map1.Layers(0).RecordsrecCount=recs.CountFori=0TorecCount-1List1.AddItem线段:&i+1Setline=recs(Shape).ValueoutputMeasureslineNextiPrivateSuboutputMeasures(aLineAsMapObjects2.line)DimitemCountAsIntegerDimpartLineAsMapObjects2.PointsDimiAsIntegerForEachpartLineInaLine.PartsFori=0TopartLine.Count-1Step1'NoofverticesintotalitemCount=itemCount+1WithpartLine.Item(i)List1.AddItemItem:&i&,&itemCount&Chr(9)&X:&Format(.X,##.00)&Chr(9)&Y:&Format(.Y,#.00)&Chr(9)&M:&Format(.Measure,##.00)EndWithNextiNextpartLineEndSub实验七控件坐标和地图坐标1.实验目的掌握控件坐标和地图坐标转化的一般方法学习地图距离获取的一般方法2.实验内容1.控件坐标与地图坐标添加数据Chinaprj.shpPrivateSubMap1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)Form1.RefreshForm1.CurrentX=0Form1.CurrentY=200Print当前鼠标坐标X:&X&vbTab&vbTab&Y:&YPrintDimptAsMapObjects2.PointSetpt=Map1.ToMapPoint(X,Y)Print当前地图坐标X:&pt.X&vbTab&Y:&pt.YPrintPrintMap1.Height&vbTab&vbTab&Map1.WidthEndSub2.控件距离与地图距离PrivateSubMap1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)DimmyplAsNewMapObjects2.LineSetmypl=Map1.TrackLineMap1.TrackingLayer.AddEventmypl,0Print地图距离为:&mypl.LengthPrint控件距离为:&Map1.