线密度和点密度计算

与之前的欧式距离计算相似,这里算得是线密度和点密度,凡是桌面版ArcToolBox里的工具都可以用Geoprocessor这样的方式实现,真后悔没早点用9.2,在9.1里要进行这些运算麻烦多了。

 

Public Function Density(ByVal SourceFeatureClass As IFeatureClass, ByVal ExtentFeatureClass As IFeatureClass, ByVal DensityRaster_SavePath As String, ByVal DensityRaster_SaveName As String, ByVal Radius As Double, ByVal CellSize As Integer, ByVal FieldName As String) As IRaster

        '得到矢量数据的范围
        Dim pEnv As IEnvelope
        pEnv = RasterHelper.GetFeatureClassEnvelop(ExtentFeatureClass)

        '通过FeatureClass得到矢量数据的路径
        Dim SourceDataPathName As String
        SourceDataPathName = GetPathFromFeatureClass(SourceFeatureClass)

        '设置运算的环境变量
        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
        If SourceFeatureClass.ShapeType = esriGeometryType.esriGeometryPolyline Then
            '线密度

            Dim LDensity As LineDensity
            LDensity = New LineDensity

            '设置线密度运算器的属性
            With LDensity
                .cell_size = CellSize
                .in_polyline_features = SourceDataPathName
                .out_raster = DensityRaster_SavePath & DensityRaster_SaveName & ".img"
                .population_field = FieldName
                .search_radius = Radius
            End With

            '进行线密度计算,得到结果
            result = GeoPro.Execute(LDensity, Nothing)

        ElseIf SourceFeatureClass.ShapeType = esriGeometryType.esriGeometryPoint Then
            '点密度

            Dim PDensity As PointDensity
            PDensity = New PointDensity

            '设置点密度运算器的属性
            With PDensity
                .cell_size = CellSize
                .in_point_features = SourceDataPathName
                .neighborhood = Radius
                .out_raster = DensityRaster_SavePath & DensityRaster_SaveName & ".img"
                .population_field = FieldName
            End With

            '进行点密度计算,得到结果
            result = GeoPro.Execute(PDensity, Nothing)

        Else
            result = Nothing
            MessageBox.Show("文件出错")
        End If

        '得到输出结果数据的路径
        Dim RasterFullpath As String
        RasterFullpath = DensityRaster_SavePath & DensityRaster_SaveName & ".img"

        '通过结果数据路径得到RasterDataset
        Dim pRasterDataset As IRasterDataset
        pRasterDataset = GetRasterDatasetFromSourceData(RasterFullpath)

        '通过RasterDataset得到Raster
        Dim pRaster As IRaster
        pRaster = GetRasterFromRasterDataset(pRasterDataset)

        Return pRaster

    End Function

你可能感兴趣的:(计算)