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

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

楼主#
更多 发布于:2007-02-27 09:24
求助ao开发代码(vb或者c#皆可),如何实现通过鼠标点击查询实体的空间属性,获得空间数据库(geodatabase)的内容?
喜欢0 评分0
默认头像
路人甲
路人甲
  • 注册日期2005-09-26
  • 发帖数14
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2007-02-27 11:42

谢谢楼上的几次帮忙,很感谢

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2007-01-25
  • 发帖数11
  • QQ
  • 铜币21枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2007-02-27 11:40

谢谢楼上的几次帮忙,很感谢

举报 回复(0) 喜欢(0)     评分
默认头像
卧底
卧底
  • 注册日期2004-04-18
  • 发帖数235
  • QQ
  • 铜币614枚
  • 威望2点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2007-02-27 11:12

首先点击获得Feature

代码:

 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)
   Dim pRefreshArea As IInvalidArea
   pRefreshArea = New InvalidArea

   Dim pFeatureLayer As IFeatureLayer
   Dim pFeatureClass As IFeatureClass
   Dim pSpatialFilter As ISpatialFilter
   Dim pFilter As IQueryFilter
   Dim pActiveView As IActiveView
   Dim pGeometry As IGeometry
   Dim pPoint As IPoint


   '将所有选择集合加入到pInvalidArea中,刷新时能清除原有的选择集合
   Dim pOrigEnumFeature As IEnumFeature
   Dim pOrigFeature As IFeature
   pOrigEnumFeature = pMap.FeatureSelection
   pOrigFeature = pOrigEnumFeature.Next
   While pOrigFeature IsNot Nothing
     pRefreshArea.Add(pOrigFeature)
     pOrigFeature = pOrigEnumFeature.Next
   End While

   '初始话pLayer层的选择SelectionSet
   Dim pFeatureSelect As IFeatureSelection
   Dim pSelectionSet As ISelectionSet
   pFeatureSelect = pLayer
   pFeatureSelect.Clear()
   pSelectionSet = pFeatureSelect.SelectionSet

   Try
     pMap.ClearSelection() '首先清除以前选择项

     If pLayer Is Nothing Then Exit Sub
     If Not TypeOf pLayer Is IGeoFeatureLayer Then Exit Sub

     ' Get the feature layer and class of the current layer
     pFeatureLayer = pLayer
     pFeatureClass = pFeatureLayer.FeatureClass
     If pFeatureClass Is Nothing Then Exit Sub

     ' Get the mouse down position in map coordinates
     pActiveView = pMap
     pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)
     pGeometry = pPoint

     ' Use a four pixel buffer around the cursor for feature search
     Dim length As Double
     length = ConvertPixelsToMapUnits(pMap, pixSize)
     Dim pTopo As ITopologicalOperator
     pTopo = pGeometry
     Dim pBuffer As IGeometry
     pBuffer = pTopo.Buffer(length)
     pGeometry = pBuffer.Envelope

     ' Set up a Filter specific to this layer
     pSpatialFilter = New SpatialFilter
     pSpatialFilter.Geometry = pGeometry
     Select Case pFeatureClass.ShapeType
       Case esriGeometryPoint
         pSpatialFilter.SpatialRel = esriSpatialRelIntersects
       Case esriGeometryPolyline
         pSpatialFilter.SpatialRel = esriSpatialRelIntersects
       Case esriGeometryPolygon
         pSpatialFilter.SpatialRel = esriSpatialRelIntersects
     End Select
     pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName
     pFilter = pSpatialFilter

     ' Do the search
     Dim pCursor As IFeatureCursor
     pCursor = pFeatureLayer.Search(pFilter, True)

     ' and select the features on the map
     Dim pFeature As IFeature
     pFeature = pCursor.NextFeature
     If pFeature IsNot Nothing Then
       '如果justOne为真只添加一个

      If justOne Then
         pMap.SelectFeature(pLayer, pFeature)
         pRefreshArea.Add(pFeature)
         pSelectionSet.Add(pFeature.OID)
       Else
         While Not pFeature Is Nothing
           pMap.SelectFeature(pLayer, pFeature)
           pRefreshArea.Add(pFeature)
           pSelectionSet.Add(pFeature.OID)
           pFeature = pCursor.NextFeature
         End While
       End If
     End If

     '更新Map中的选择集合,并触发selectionChanged事件
     pMap.ClearSelection()
     pFeatureSelect.SelectionSet = pSelectionSet
     pFeatureSelect.SelectionChanged()

     '刷新屏幕
     pRefreshArea.Display = pActiveView.ScreenDisplay
     pRefreshArea.Invalidate(esriAllScreenCaches)
   Catch ex As Exception
     MsgBox(ex.Message)
   End Try
 End Sub

由于是GDB,可以通过Shape_Length、Shape_Area获得长度、面积等信息。

个人专栏: https://zhuanlan.zhihu.com/c_165676639
举报 回复(0) 喜欢(0)     评分
默认头像

返回顶部