《空间查询实验报告材料.doc》由会员分享,可在线阅读,更多相关《空间查询实验报告材料.doc(11页珍藏版)》请在课桌文档上搜索。
1、实验报告实验序号实验名称空间查询实验时间实验室GIS实验室一实验预习1实验目的通过绘制图形实现对shapfile文件的查询2实验原理、实验流程或装置示意图试验浓缩版步骤或者流程图 借助VB工具和MO模块实现画点、线、面、多边形,shapfile文件的查询。3实验设备与材料 计算机,VB6.0软件, MO组件。(1) 实验方法步骤与须知事项一:利用VB工具制作界面添加按钮,图像显示框,图像目录框架;首先在部件里面加载:ESRI MapObjects2.2;ESRI MapObjects LegendControl;;Microsoft mon Dialog Controls 6.0;Micros
2、oft Windows mon Controls6.0。等窗体1界面;窗体二界面:二:在代码窗口编写代码窗体1代码如下:Option ExplicitDim pShape As ObjectPrivate Sub mand1_Click()End SubPrivate Sub Map1_AfterTrackingLayerDraw(ByVal hDC As stdole.OLE_HANDLE) If Not pt Is Nothing Then pSym.Color = moBlue Map1.DrawShape pt, pSym End If If Not pLine Is Nothing
3、Then pSym.Color = moBlue Map1.DrawShape pLine, pSym End If If Not pRectangle Is Nothing Then pSym.SymbolType = moFillSymbol pSym.Style = moTransparentFill pSym.Color = moBlue pSym.OutlineColor = moBlue Map1.DrawShape pRectangle, pSym End If If Not pPolygon Is Nothing Then pSym.OutlineColor = moBlue
4、pSym.SymbolType = moFillSymbol pSym.Style = moTransparentFill Map1.DrawShape pPolygon, pSym End If If Not pSel Is Nothing Then pSymSel.Color = moYellow Map1.DrawShape pSel, pSymSel End IfEnd SubPrivate Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If frmAdSpatialS
5、el.Toolbar1.Buttons(Points).Value = 1 Then Set pt = Map1.ToMapPoint(X, Y) Set pShape = pt ExecuteSearch DisplaySelFeature ElseIf frmAdSpatialSel.Toolbar1.Buttons(Lines).Value = 1 Then Set pShape = pLine ExecuteSearch DisplaySelFeature ElseIf frmAdSpatialSel.Toolbar1.Buttons(Rectangles).Value = 1 The
6、n Set pShape = pRectangle ExecuteSearch DisplaySelFeature ElseIf frmAdSpatialSel.Toolbar1.Buttons(Polygons).Value = 1 Then Set pShape = pPolygon ExecuteSearch DisplaySelFeature ElseIf frmAdSpatialSel.Toolbar1.Buttons(sel).Value = 1 Then Dim theTol As Single Set pts = Map1.ToMapPoint(X, Y) Set recs =
7、 Map1.Layers(frmAdSpatialSel.cboLayer.ListIndex).SearchByDistance(pts, theTol, ) If recs.EOF = False Then Set pShape = recs(Shape).Value ExecuteSearch DisplaySelFeature Else End If End IfEnd SubSub ExecuteSearch() Set pSel = Nothing Set pSel = Map1.Layers(frmAdSpatialSel.cboLayer.ListIndex).SearchSh
8、ape(pShape, frmAdSpatialSel.cboMethod.ListIndex, )End Sub用表显示选中图形 Sub DisplaySelFeature() If Not pSel Is Nothing Then Dim i As Integer Dim recscount As Integer * 以下代码用来填充msgflexgrid Dim m As Integer Dim n As Integer recscount = recscount + 1 Loop MsgBox recsCount frmAdSpatialSel.MSFlexGrid1.Cols = t
9、Desc.FieldCount + 1 frmAdSpatialSel.MSFlexGrid1.Rows = recscount + 1 frmAdSpatialSel.MSFlexGrid1.AllowUserResizing = flexResizeColumns frmAdSpatialSel.MSFlexGrid1.CellAlignment = flexAlignLeftCenter frmAdSpatialSel.MSFlexGrid1.ColWidth(i) = tDesc.FieldLength(i - 1) * 72 Next i to filled the fields n
10、ame into grid frmAdSpatialSel.MSFlexGrid1.TextMatrix(0, 0) = 特征 ID For i = 1 To recscount frmAdSpatialSel.MSFlexGrid1.TextMatrix(i, 0) = i frmAdSpatialSel.MSFlexGrid1.CellAlignment = flexAlignLeftCenter Next i For i = 0 To tDesc.FieldCount - 1 frmAdSpatialSel.MSFlexGrid1.TextMatrix(0, i + 1) = tDesc
11、.FieldName(i) frmAdSpatialSel.MSFlexGrid1.ColAlignment(i) = flexAlignLeftCenter frmAdSpatialSel.MSFlexGrid1.ColWidth(i) = 1200 Next i frmAdSpatialSel.MSFlexGrid1.ColAlignment(0) = flexAlignCenterCenter frmAdSpatialSel.MSFlexGrid1.ColWidth(0) = 680 For m = 1 To recscount For n = 0 To tDesc.FieldCount
12、 - 1 frmAdSpatialSel.MSFlexGrid1.TextMatrix(m, n + 1) = pSel.Fields(tDesc.FieldName(n).Value Next n Next m End IfEnd Sub窗体2代码如下:Private Sub cmdCenter_Click() On Error Resume Next Dim Rect As Rectangle, Rect2 As Rectangle Dim shapeX As Double, shapeY As Double Dim deltax As Double, deltay As Double D
13、im reo As Integer reo = MSFlexGrid1.Row - 1 记录指针移动到属性数据表选择中的记录上 For i = 0 To reo - 1 Next i Set theShape = pSel(shape).Value If pSel(shape).Type = moPoint Then Rect2.Offset deltax, deltay Form1.Map1.Extent = Rect2 Else Form1.Map1.Extent = Rect End If Set Rect2 = Nothing Set theShape = NothingEnd Sub
14、Private Sub cmdFlash_Click() Call MovePoint Call flash_shapeEnd Sub*闪烁Private Sub flash_shape() On Error Resume Next Form1.Map1.FlashShape pSel(shape).Value, 3End Sub移动Private Sub MovePoint() On Error Resume Next Dim reo As Integer Dim i As Integer reo = MSFlexGrid1.Row - 1 记录指针移动到属性数据表选择中的记录上 For i
15、 = 0 To reo - 1 Next iEnd Sub*Private Sub Form_Load() SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE If layer.LayerType = 0 Then i = i + 1 End If Next layer cboLayer.ListIndex = 0 初始化空间搜索方法 cboMethod.AddItem 重叠 cboMethod.AddItem 有一个公共点 cboMethod.AddItem 边缘相交 cboMethod.AddIt
16、em 有一条公共边 cboMethod.AddItem 有公共点或边缘相交 cboMethod.AddItem 有交集 cboMethod.AddItem 内交 cboMethod.AddItem 内交,但边缘不相交 cboMethod.AddItem 特征包含形 cboMethod.AddItem 形包含特征 cboMethod.AddItem 特征完全包含形 cboMethod.AddItem 形完全包含特征 cboMethod.AddItem 特征包含形的第一个点 cboMethod.AddItem 形包含特征的中心 cboMethod.AddItem 特征和形一样 cboMethod.
17、ListIndex = 5End SubPrivate Sub MSFlexGrid1_Click() cmdCenter_ClickEnd SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As ctlLib.Button) 去除选中的图形 If Button.Key = Clean Then If Not pt Is Nothing Then Set pt = Nothing If Not pLine Is Nothing Then Set pLine = Nothing If Not pRectangle Is Nothing Then S
18、et pRectangle = Nothing If Not pPolygon Is Nothing Then Set pPolygon = Nothing If Not pSel Is Nothing Then Set pSel = Nothing MSFlexGrid1.Cols = 0 MSFlexGrid1.Rows = 0 Form1.Map1.TrackingLayer.Refresh True End IfEnd Sub模块代码如下:Option Explicit窗体总位于最上边Public Declare Function SetWindowPos Lib user32 (By
19、Val hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPublic Const SWP_NOSIZE = &H1Public Const SWP_NOMOVE = &H2Public Const HWND_TOPMOST = -1Public Const HWND_NOTOPMOST = -2Public i As Integer第三步:调试代码,直至得到实验要求的结果:1、 点查询2、 线查询3、 矩形查询:4、 多边形查询:a) 实验内容1、对实验现象、实验结果的分析与其结论 实验达到预期效果。教师评语与评分:签名: 年 月 日