空间查询实验报告文档格式.docx
《空间查询实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《空间查询实验报告文档格式.docx(15页珍藏版)》请在冰豆网上搜索。
实验室
GIS实验室
一.实验预习
1.实验目的
通过绘制图形实现对shapfile文件的查询
2.实验原理、实验流程或装置示意图(试验浓缩版步骤或者流程图)
借助VB工具和MO模块实现画点、线、面、多边形,shapfile文件的查询。
3.实验设备及材料
计算机,VB6.0软件,MO组件。
(1)实验方法步骤及注意事项
一:
利用VB工具制作界面(添加按钮,图像显示框,图像目录框架);
首先在部件里面加载:
ESRIMapObjects2.2;
ESRIMapObjectsLegendControl;
;
MicrosoftCommonDialogControls6.0;
MicrosoftWindowsCommonControls6.0。
等
窗体1界面;
窗体二界面:
二:
在代码窗口编写代码
窗体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
Map1.DrawShapepLine,pSym
IfNotpRectangleIsNothingThen
pSym.SymbolType=moFillSymbol
pSym.Style=moTransparentFill
pSym.OutlineColor=moBlue
Map1.DrawShapepRectangle,pSym
IfNotpPolygonIsNothingThen
Map1.DrawShapepPolygon,pSym
IfNotpSelIsNothingThen
pSymSel.Color=moYellow
Map1.DrawShapepSel,pSymSel
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"
SetpLine=Map1.TrackLine
SetpShape=pLine
Rectangles"
SetpRectangle=Map1.TrackRectangle
SetpShape=pRectangle
Polygons"
SetpPolygon=Map1.TrackPolygon
SetpShape=pPolygon
sel"
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
Else
Map1.Refresh
SubExecuteSearch()
SetpSel=Nothing
SetpSel=Map1.Layers(frmAdSpatialSel.cboLayer.ListIndex).SearchShape(pShape,frmAdSpatialSel.cboMethod.ListIndex,"
'
用表显示选中图形
SubDisplaySelFeature()
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
Fori=0TotDesc.FieldCount-1
frmAdSpatialSel.MSFlexGrid1.TextMatrix(0,i+1)=tDesc.FieldName(i)
frmAdSpatialSel.MSFlexGrid1.ColAlignment(i)=flexAlignLeftCenter
frmAdSpatialSel.MSFlexGrid1.ColWidth(i)=1200
frmAdSpatialSel.MSFlexGrid1.ColAlignment(0)=flexAlignCenterCenter
frmAdSpatialSel.MSFlexGrid1.ColWidth(0)=680
Form=1Torecscount
Forn=0TotDesc.FieldCount-1
frmAdSpatialSel.MSFlexGrid1.TextMatrix(m,n+1)=pSel.Fields(tDesc.FieldName(n)).Value
Nextn
Nextm
frmAdSpatialSel.MSFlexGrid1.Refresh
窗体2代码如下:
PrivateSubcmdCenter_Click()
OnErrorResumeNext
DimRectAsRectangle,Rect2AsRectangle
DimshapeXAsDouble,shapeYAsDouble
DimdeltaxAsDouble,deltayAsDouble
DimtheShapeAsObject,pinPointAsMapObjects2.Point
DimrecNoAsInteger
recNo=MSFlexGrid1.Row-1
记录指针移动到属性数据表选择中的记录上
Fori