空间数据查询gis开发与设计.docx
《空间数据查询gis开发与设计.docx》由会员分享,可在线阅读,更多相关《空间数据查询gis开发与设计.docx(19页珍藏版)》请在冰点文库上搜索。
空间数据查询gis开发与设计
本科学生综合性、设计性
实验报告
姓名学号_
专业_测绘工程班级__
实验课程名称_GIS软件设计与开发__
指导教师及职称______
开课学期2013至2014学年第二学期
上课时间2014年5月12日
云南师范大学旅游与地理科学学院地理信息系统系
一、实验设计
实验名称:
数据的加载与空间数据查询
实验时间:
2014/5/12
小组合作:
是()否(√)
小组成员:
无
1、实验内容(含实验原理介绍):
(1)、软件的界面设计;
(2)、对于数据加载的设计与工程编辑;
(3)、对数据进行空间查询的相关分析;
(4)、用MO组件对GIS进行开发。
2、实验目的:
(1)、学习VB软件,并开始使用软件进行数据加载;
(2)、对于地图处理软件的界面合理编辑;
(3)、学习数据加载的设计与工程编辑,达到实用效果;
(4)、通过编辑查询工具条,进行相应的空间查询。
3、设计实验相关情况介绍(包含使用软件以及实验设备等):
(1)、实验设计思想:
本实验是使用MO方法,对于地图处理软件做开发设计,提高学生的软件设计思维与开发能力。
通过简单的MO方法,将数据加载到地图上,并编辑出相应的查询工具。
(2)、使用软件与实验设备:
软件:
MicrosoftVisualBasic6.0中文版
实验设备:
学院实验室windowXP系统的计算机及相关软件。
4、实验过程、方法步骤:
操作步骤:
(1)、打开MicrosoftVisualBasic6.0中文版软件,运行程序:
工程1。
(2)、打开已经拥有初步软件界面,相关控件,以及可以进行放大、平移、缩小等功能的VB程序:
工程1.vbp。
如下:
其中,需要添加相关的部件:
窗体1进行如下图设计:
(3)、在地图区域,点击鼠标右键,选择“特性”,加载数据,如下图:
(4)、加载后的数据进行运行,结果为:
(5)、设置窗体2:
(每条注释下面的代码为相关注释表示的代码)根据相关控件的功能,设计窗体2,最终的结果如下:
(6)、在窗体中添加一个模块,并在其中添加相应的代码:
具体代码为:
OptionExplicit‘将窗体置于最上面的windowsAPI函数
PublicDeclareFunctionSetWindowPosLib"user32"(ByValhwndAsLong,ByValhWndInsertAfterAsLong,ByValXAsLong,ByValYAsLong,ByValcxAsLong,ByValcyAsLong,ByValwFlagsAsLong)AsLong
PublicConstSWP_NOSIZE=&H1
PublicConstSWP_NOMOVE=&H2
PublicConstHWND_TOPMOST=-1
PublicConstHWND_NOTOPMOST=-2
(7)、在窗口1中编写如下代码:
OptionExplicit
DimpShapeAsObject
DimptAsMapObjects2.Point
DimpLineAsMapObjects2.Line
DimpRectangleAsMapObjects2.Rectangle
DimpPolygonAsMapObjects2.Polygon
DimrecsAsMapObjects2.Recordset
PrivateSubCommand1_Click()
frmAdSpatialSel.Show
EndSub
PrivateSubMap1_AfterTrackingLayerDraw(ByValhDCAsstdole.OLE_HANDLE)
DimpSymSelAsNewMapObjects2.Symbol
DimpSymAsNewMapObjects2.Symbol
IfNotptIsNothingThen
pSym.Color=moBlue
Map1.DrawShapept,pSym
EndIf
IfNotpLineIsNothingThen
pSym.Color=moBlue
Map1.DrawShapepLine,pSym
EndIf
IfNotpRectangleIsNothingThen
pSym.SymbolType=moFillSymbol
pSym.Style=moTransparentFill
pSym.Color=moBlue
pSym.OutlineColor=moBlue
Map1.DrawShapepRectangle,pSym
EndIf
IfNotpPolygonIsNothingThen
pSym.OutlineColor=moBlue
pSym.SymbolType=moFillSymbol
pSym.Style=moTransparentFill
Map1.DrawShapepPolygon,pSym
EndIf
IfNotpSelIsNothingThen
pSymSel.Color=moYellow
Map1.DrawShapepSel,pSymSel
EndIf
EndSub
PrivateSubMap1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IffrmAdSpatialSel.Toolbar1.Buttons("Points").Value=1Then
Setpt=Map1.ToMapPoint(X,Y)
SetpShape=pt
ExecuteSearch
DisplaySelFeature
ElseIffrmAdSpatialSel.Toolbar1.Buttons("Lines").Value=1Then
SetpLine=Map1.TrackLine
SetpShape=pLine
ExecuteSearch
DisplaySelFeature
ElseIffrmAdSpatialSel.Toolbar1.Buttons("Rectangles").Value=1Then
SetpRectangle=Map1.TrackRectangle
SetpShape=pRectangle
ExecuteSearch
DisplaySelFeature
ElseIffrmAdSpatialSel.Toolbar1.Buttons("Polygons").Value=1Then
SetpPolygon=Map1.TrackPolygon
SetpShape=pPolygon
ExecuteSearch
DisplaySelFeature
ElseIffrmAdSpatialSel.Toolbar1.Buttons("sel").Value=1Then
DimtheTolAsSingle
theTol=0.01
DimptsAsMapObjects2.Point
Setpts=Map1.ToMapPoint(X,Y)
Setrecs=Map1.Layers(frmAdSpatialSel.cboLayer.ListIndex).SearchByDistance(pts,theTol,"")
Ifrecs.EOF=FalseThen
SetpShape=recs("Shape").Value
ExecuteSearch
DisplaySelFeature
Else
EndIf
EndIf
Map1.Refresh
EndSub
SubExecuteSearch()
SetpSel=Nothing
SetpSel=Map1.Layers(frmAdSpatialSel.cboLayer.ListIndex).SearchShape(pShape,frmAdSpatialSel.cboMethod.ListIndex,"")
EndSub
'用表显示选中图形
SubDisplaySelFeature()
IfNotpSelIsNothingThen
DimtDescAsMapObjects2.TableDesc
DimiAsInteger
SettDesc=pSel.TableDesc
DimrecscountAsInteger
'**********************************************************
'以下代码用来填充msgflexgrid
DimmAsInteger
DimnAsInteger
pSel.MoveFirst
DoWhileNotpSel.EOF
pSel.MoveNext
recscount=recscount+1
Loop
'MsgBoxrecsCount
frmAdSpatialSel.MSFlexGrid1.Cols=tDesc.FieldCount+1
frmAdSpatialSel.MSFlexGrid1.Rows=recscount+1
frmAdSpatialSel.MSFlexGrid1.AllowUserResizing=flexResizeColumns
frmAdSpatialSel.MSFlexGrid1.Clear
frmAdSpatialSel.MSFlexGrid1.CellAlignment=flexAlignLeftCenter
Fori=1TotDesc.FieldCount
frmAdSpatialSel.MSFlexGrid1.ColWidth(i)=tDesc.FieldLength(i-1)*72
Nexti
'tofilledthefieldsnameintogrid
frmAdSpatialSel.MSFlexGrid1.TextMatrix(0,0)="特征ID"
Fori=1Torecscount
frmAdSpatialSel.MSFlexGrid1.TextMatrix(i,0)=i
frmAdSpatialSel.MSFlexGrid1.CellAlignment=flexAlignLeftCenter
Nexti
Fori=0TotDesc.FieldCount-1
frmAdSpatialSel.MSFlexGrid1.TextMatrix(0,i+1)=tDesc.FieldName(i)
frmAdSpatialSel.MSFlexGrid1.ColAlignment(i)=flexAlignLeftCenter
frmAdSpatialSel.MSFlexGrid1.ColWidth(i)=1200
Nexti
frmAdSpatialSel.MSFlexGrid1.ColAlignment(0)=flexAlignCenterCenter
frmAdSpatialSel.MSFlexGrid1.ColWidth(0)=680
pSel.MoveFirst
Form=1Torecscount
Forn=0TotDesc.FieldCount-1
frmAdSpatialSel.MSFlexGrid1.TextMatrix(m,n+1)=pSel.Fields(tDesc.FieldName(n)).Value
Nextn
pSel.MoveNext
Nextm
pSel.MoveFirst
frmAdSpatialSel.MSFlexGrid1.Refresh
EndIf
EndSub
(8)、在窗口1中编写如下代码:
PrivateSubcmdCenter_Click()
'OnErrorResumeNext
DimRectAsRectangle,Rect2AsRectangle
DimshapeXAsDouble,shapeYAsDouble
DimdeltaxAsDouble,deltayAsDouble
DimtheShapeAsObject,pinPointAsMapObjects2.Point
DimrecNoAsInteger
recNo=MSFlexGrid1.Row-1
pSel.MoveFirst
'记录指针移动到属性数据表选择中的记录上
Fori=0TorecNo-1
pSel.MoveNext
Nexti
SettheShape=pSel("shape").Value
IfpSel("shape").Type=moPointThen
SetRect2=Form1.Map1.Extent
shapeX=pSel("shape").Value.X
shapeY=pSel("shape").Value.Y
deltax=shapeX-Rect2.Center.X
deltay=shapeY-Rect2.Center.Y
Rect2.Offsetdeltax,deltay
Rect2.ScaleRectangle0.1
Form1.Map1.Extent=Rect2
Else
SetRect=pSel("shape").Value.Extent
Rect.ScaleRectangle1.1
Form1.Map1.Extent=Rect
EndIf
SetRect2=Nothing
SettheShape=Nothing
EndSub
PrivateSubcmdFlash_Click()
CallMovePoint
Callflash_shape
EndSub
'***************************************************************
'闪烁
PrivateSubflash_shape()
'OnErrorResumeNext
Form1.Map1.FlashShapepSel("shape").Value,3
EndSub
'移动
PrivateSubMovePoint()
'OnErrorResumeNext
DimrecNoAsInteger
DimiAsInteger
recNo=MSFlexGrid1.Row-1
pSel.MoveFirst
'记录指针移动到属性数据表选择中的记录上
Fori=0TorecNo-1
pSel.MoveNext
Nexti
EndSub
'***************************************************************
PrivateSubForm_Load()
SetWindowPosMe.hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVEOrSWP_NOSIZE
DimlayerAsMapObjects2.MapLayer
Setlayer=NewMapObjects2.MapLayer
cboLayer.Clear
ForEachlayerInForm1.Map1.Layers
Iflayer.LayerType=0Then
cboLayer.AddItemlayer.Name
i=i+1
EndIf
Nextlayer
cboLayer.ListIndex=0
'初始化空间搜索方法
cboMethod.AddItem"重叠"
cboMethod.AddItem"有一个公共点"
cboMethod.AddItem"边缘相交"
cboMethod.AddItem"有一条公共边"
cboMethod.AddItem"有公共点或边缘相交"
cboMethod.AddItem"有交集"
cboMethod.AddItem"内交"
cboMethod.AddItem"内交,但边缘不相交"
cboMethod.AddItem"特征包含形"
cboMethod.AddItem"形包含特征"
cboMethod.AddItem"特征完全包含形"
cboMethod.AddItem"形完全包含特征"
cboMethod.AddItem"特征包含形的第一个点"
cboMethod.AddItem"形包含特征的中心"
cboMethod.AddItem"特征和形相同"
cboMethod.ListIndex=5
EndSub
PrivateSubMSFlexGrid1_Click()
cmdCenter_Click
EndSub
PrivateSubToolbar1_ButtonClick(ByValButtonAsComctlLib.Button)
'清除选中的图形
IfButton.Key="Clean"Then
MSFlexGrid1.Clear
IfNotptIsNothingThenSetpt=Nothing
IfNotpLineIsNothingThenSetpLine=Nothing
IfNotpRectangleIsNothingThenSetpRectangle=Nothing
IfNotpPolygonIsNothingThenSetpPolygon=Nothing
IfNotpSelIsNothingThenSetpSel=Nothing
MSFlexGrid1.Cols=0
MSFlexGrid1.Rows=0
Form1.Map1.TrackingLayer.RefreshTrue
EndIf
EndSub
(9)、返回工程界面,点击运行按钮
,运行程序:
点击按钮“空间查询”,得界面:
5、实验结果:
(1)、画线查询:
属性表:
(2)、画多边形查询:
属性表:
(3)、画矩形查询:
属性表:
注:
查询功能中,“清除”功能未实现,故未做出结果图。
6、实验小结(出现过的问题或错误、原因分析):
(1)、在界面设计时一定要进行合理的分配,最好做到界面美观,软件使用方便快捷;
(2)、相关代码的顺序容易写错,需要紧密按照程序运行的逻辑顺序编写;
(3)、由于本次实验的代码比较多,且并不是很利于理解,在编写时一定要注意是否写错,格式是否正确。
(4)、在做实验过程中一定要学会注释代码,否则最后的结果往往很混乱的。
(5)、查询功能中,“清除”功能未实现。
指导老师对实验设计方案的意见:
指导老师签名:
年月日