欧式距离计算,采用SpatialAnalystTools中的EucDistance ,比较方便,其中GetFeatureClassEnvelop,GetPathFromFeatureClass,GetRasterDatasetFromSourceData,GetRasterFromRasterDataset是另外写的函数(这几个函数写的很搞笑,就是些RasterDataset、Raster和FeatureClass、shp之间的关系及转换,其实可以不用这么写的,高手要是见了,估计会狂鄙视我的,呵呵)。
Public Function Eucdistance(ByVal SourceFeatureClass As IFeatureClass, ByVal ExtentFeatureClass As IFeatureClass, ByVal MaxDistance As Integer, ByVal EuclideanRaster_SavePath As String, ByVal EuclideanRaster_SaveName As String, ByVal CellSize As Integer) As IRaster
'得到矢量数据的范围
Dim pEnv As IEnvelope
pEnv = RasterHelper.GetFeatureClassEnvelop(ExtentFeatureClass)
'通过FeatureClass得到矢量数据的路径
Dim SourceDataPathName As String
SourceDataPathName = GetPathFromFeatureClass(SourceFeatureClass)
'设置欧式距离计算器的参数
Dim Eucdist As EucDistance = New EucDistance()
With Eucdist
.cell_size = CellSize
.maximum_distance = MaxDistance
.in_source_data = SourceDataPathName
.out_distance_raster = EuclideanRaster_SavePath & EuclideanRaster_SaveName & ".img"
End With
'设置运算的环境变量
Dim str As String = pEnv.XMin & " " & pEnv.YMax & " " & pEnv.XMax & " " & pEnv.YMin
Dim GeoPro As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
GeoPro.SetEnvironmentValue("extent", str)
'进行欧式距离计算,得到结果
Dim result As IGeoProcessorResult
result = GeoPro.Execute(Eucdist, Nothing)
'得到结果数据的路径
Dim RasterFullpath As String
RasterFullpath = Eucdist.out_distance_raster
'通过结果数据路径得到RasterDataset
Dim pRasterDataset As IRasterDataset
pRasterDataset = GetRasterDatasetFromSourceData(RasterFullpath)
'通过RasterDataset得到Raster
Dim pRaster As IRaster
pRaster = GetRasterFromRasterDataset(pRasterDataset)
Return pRaster
End Function