Kernel Density (Spatial Analyst)
Summary
Calculates a magnitude per unit area from point or polyline features using a kernel function to fit a smoothly tapered surface to each point or polyline.
Usage
-
Larger values of the search radius parameter produce a smoother, more generalized density raster. Smaller values produce a raster that shows more detail.
-
Only the points or portions of a line that fall within the neighborhood are considered in calculating density. If no points or line sections fall within the neighborhood of a particular cell, that cell is assigned NoData.
-
If the area unit scale factor units are small relative to the features (distance between points or length of line sections, depending on feature type), the output values may be small. To obtain larger values, select the area unit scale factor for larger units (for example, square kilometers versus square meters).
Syntax
Parameter | Explanation | Data Type |
in_features |
The input features (point or line) for which to calculate the density. | Feature Layer |
population_field |
Field denoting population values for each feature. The Population field is the count or quantity to be spread across the landscape to create a continuous surface. Values in the population field may be integer or floating point. The options and default behaviours for the field are listed below.
| Field |
cell_size (Optional) | The cell size for the output raster dataset. This is the value in the environment if specifically set. If the environment is not set, then cell size is the shorter of the width or height of the output extent in the output spatial reference, divided by 250. | Analysis Cell Size |
search_radius (Optional) |
The search radius within which to calculate density. Units are based on the linear unit of the projection of the output spatial reference. For example, if the units are in meters, to include all features within a one-mile neighborhood, set the search radius equal to 1609.344 (1 mile = 1609.344 meters). The default is the shortest of the width or height of the output extent in the output spatial reference, divided by 30. | Double |
area_unit_scale_factor (Optional) |
The desired area units of the output density values. A default unit is selected based on the linear unit of the projection of the output spatial reference. You can change this to the appropriate unit if you wish to convert the density output. Values for line density convert the units of both length and area. For example, if your input units are meters the default output area density units will be square kilometers for point features or kilometers per square kilometer for polyline features. The default density units based on the input feature units are:
| String |
Return Value
Name | Explanation | Data Type |
out_raster |
The output kernel density raster. It is always a floating point raster. | Raster |
Code Sample
This example calculates a smoothed density raster from a point shape file.
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outKDens = KernelDensity("rec_sites.shp", "NONE", 45, 1200, "SQUARE_KILOMETERS")
outKDens.save("C:/sapyexamples/output/kdensout")
This example calculates a smoothed density raster from a point shape file.
# Name: KernelDensity_Ex_02.py
# Description: Calculates a magnitude per unit area from point or polyline
# features using a kernel function to fit a smoothly tapered
# surface to each point or polyline.
# Requirements: Spatial Analyst Extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "C:/sapyexamples/data"
# Set local variables
inFeatures = "rec_sites.shp"
populationField = "NONE"
cellSize = 60
searchRadius = 2500
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute KernelDensity
outKernelDensity = KernelDensity(inFeatures, populationField, cellSize,
searchRadius, "SQUARE_KILOMETERS")
# Save the output
outKernelDensity.save("C:/sapyexamples/output/kerneldout")