大家来看看,ArcEngine开发,我这两个函数怎么老出错。
功能:在一个要素类中查找与直线pLine相交的要素
Public Function findCrossPointInFeatureClass(ByVal pFeatureLayer As IFeatureLayer, ByVal pLine As ILine) As Integer
Dim pGeo as IGeometry
pGeo=pLine
Dim pFilter As ISpatialFilter
Dim pFeatureSelection As IFeatureSelection
pFeatureSelection = pFeatureLayer
pFilter = New SpatialFilter '过滤算子
With pFilter
.Geometry = pGeo
.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
End With
pFeatureSelection.SelectFeatures(pFilter, esriSelectionResultEnum.esriSelectionResultNew, False) '在这个地方出错
End Function
Public Function findCrossPointInFeatureClass(ByVal pFeatureClass As IFeatureClass, ByVal pLine As ILine) As Integer
Dim pGeo as IGeometry
pGeo=pLine
Dim pFilter As ISpatialFilter
pFilter = New SpatialFilter '过滤算子
With pFilter
.Geometry = pGeo
.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
End With
pFeatureSelection.SelectFeatures(pFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
Dim pFeatureCursor As IFeatureCursor
Dim count As Integer = 0
Dim pFeature As IFeature
pFeatureCursor = pFeatureClass.Search(pFilter, False) '在这个地方出错
End Function
[解决办法]
利用ISpatialFilter接口进行查询时,它的.Geometry必须是高级的Geometry,所以是不能传入ILine的,必须使用IPolyLine,所以你需要把传入的参数类型改为IPolyLine就可以了
[解决办法]
http://up2megis.spaces.live.com/blog/cns!7947820C29ABE0E8!150.entry
这里是我以前写过的一点东西,里面有你需要的部分