徐修云
路人甲
路人甲
  • 注册日期2005-09-26
  • 发帖数14
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2010回复:3

[原创]求助ao的空间查询代码

楼主#
更多 发布于:2007-02-27 09:24
求助ao开发代码(vb或者c#皆可),如何实现通过鼠标点击查询实体的空间属性,获得空间数据库(geodatabase)的内容?
喜欢0 评分0
kisssy
卧底
卧底
  • 注册日期2004-04-18
  • 发帖数235
  • QQ
  • 铜币614枚
  • 威望2点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2007-02-27 11:12
<P>首先点击获得Feature</P>
<P>代码:</P>
<P>  Public Shared Sub SelectMouseDown(ByVal pixSize As Integer, ByVal x As Long, ByVal y As Long, ByVal pLayer As IFeatureLayer, ByVal pMap As IMap, ByVal justOne As Boolean)<BR>    Dim pRefreshArea As IInvalidArea<BR>    pRefreshArea = New InvalidArea</P>
<P>    Dim pFeatureLayer As IFeatureLayer<BR>    Dim pFeatureClass As IFeatureClass<BR>    Dim pSpatialFilter As ISpatialFilter<BR>    Dim pFilter As IQueryFilter<BR>    Dim pActiveView As IActiveView<BR>    Dim pGeometry As IGeometry<BR>    Dim pPoint As IPoint</P>
<P><BR>    '将所有选择集合加入到pInvalidArea中,刷新时能清除原有的选择集合<BR>    Dim pOrigEnumFeature As IEnumFeature<BR>    Dim pOrigFeature As IFeature<BR>    pOrigEnumFeature = pMap.FeatureSelection<BR>    pOrigFeature = pOrigEnumFeature.Next<BR>    While pOrigFeature IsNot Nothing<BR>      pRefreshArea.Add(pOrigFeature)<BR>      pOrigFeature = pOrigEnumFeature.Next<BR>    End While</P>
<P>    '初始话pLayer层的选择SelectionSet<BR>    Dim pFeatureSelect As IFeatureSelection<BR>    Dim pSelectionSet As ISelectionSet<BR>    pFeatureSelect = pLayer<BR>    pFeatureSelect.Clear()<BR>    pSelectionSet = pFeatureSelect.SelectionSet</P>
<P>    Try<BR>      pMap.ClearSelection() '首先清除以前选择项</P>
<P>      If pLayer Is Nothing Then Exit Sub<BR>      If Not TypeOf pLayer Is IGeoFeatureLayer Then Exit Sub</P>
<P>      ' Get the feature layer and class of the current layer<BR>      pFeatureLayer = pLayer<BR>      pFeatureClass = pFeatureLayer.FeatureClass<BR>      If pFeatureClass Is Nothing Then Exit Sub</P>
<P>      ' Get the mouse down position in map coordinates<BR>      pActiveView = pMap<BR>      pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)<BR>      pGeometry = pPoint</P>
<P>      ' Use a four pixel buffer around the cursor for feature search<BR>      Dim length As Double<BR>      length = ConvertPixelsToMapUnits(pMap, pixSize)<BR>      Dim pTopo As ITopologicalOperator<BR>      pTopo = pGeometry<BR>      Dim pBuffer As IGeometry<BR>      pBuffer = pTopo.Buffer(length)<BR>      pGeometry = pBuffer.Envelope</P>
<P>      ' Set up a Filter specific to this layer<BR>      pSpatialFilter = New SpatialFilter<BR>      pSpatialFilter.Geometry = pGeometry<BR>      Select Case pFeatureClass.ShapeType<BR>        Case esriGeometryPoint<BR>          pSpatialFilter.SpatialRel = esriSpatialRelIntersects<BR>        Case esriGeometryPolyline<BR>          pSpatialFilter.SpatialRel = esriSpatialRelIntersects<BR>        Case esriGeometryPolygon<BR>          pSpatialFilter.SpatialRel = esriSpatialRelIntersects<BR>      End Select<BR>      pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName<BR>      pFilter = pSpatialFilter</P>
<P>      ' Do the search<BR>      Dim pCursor As IFeatureCursor<BR>      pCursor = pFeatureLayer.Search(pFilter, True)</P>
<P>      ' and select the features on the map<BR>      Dim pFeature As IFeature<BR>      pFeature = pCursor.NextFeature<BR>      If pFeature IsNot Nothing Then<BR>        '如果justOne为真只添加一个</P>
<P>       If justOne Then<BR>          pMap.SelectFeature(pLayer, pFeature)<BR>          pRefreshArea.Add(pFeature)<BR>          pSelectionSet.Add(pFeature.OID)<BR>        Else<BR>          While Not pFeature Is Nothing<BR>            pMap.SelectFeature(pLayer, pFeature)<BR>            pRefreshArea.Add(pFeature)<BR>            pSelectionSet.Add(pFeature.OID)<BR>            pFeature = pCursor.NextFeature<BR>          End While<BR>        End If<BR>      End If</P>
<P>      '更新Map中的选择集合,并触发selectionChanged事件<BR>      pMap.ClearSelection()<BR>      pFeatureSelect.SelectionSet = pSelectionSet<BR>      pFeatureSelect.SelectionChanged()</P>
<P>      '刷新屏幕<BR>      pRefreshArea.Display = pActiveView.ScreenDisplay<BR>      pRefreshArea.Invalidate(esriAllScreenCaches)<BR>    Catch ex As Exception<BR>      MsgBox(ex.Message)<BR>    End Try<BR>  End Sub<BR></P>
<P>由于是GDB,可以通过Shape_Length、Shape_Area获得长度、面积等信息。</P>
个人专栏: https://zhuanlan.zhihu.com/c_165676639
举报 回复(0) 喜欢(0)     评分
tiansheng
路人甲
路人甲
  • 注册日期2007-01-25
  • 发帖数11
  • QQ
  • 铜币21枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2007-02-27 11:40
<P>谢谢楼上的几次帮忙,很感谢</P>
举报 回复(0) 喜欢(0)     评分
徐修云
路人甲
路人甲
  • 注册日期2005-09-26
  • 发帖数14
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2007-02-27 11:42
<TABLE fixed; WORD-BREAK: break-all" height="85%" width="95%" align=center border=0>

<TR>
<TD 9pt; LINE-HEIGHT: 12pt" vAlign=top width=* height="100%"><IMG src="http://www.gisempire.com/bbs/Skins/Default/topicface/face1.gif"> <B></B><BR>
<P>谢谢楼上的几次帮忙,很感谢</P></TD></TR></TABLE>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部