Available with Spatial Analyst license.
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.
Illustration
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).
For ArcGIS 10.2.1 and later, the default search radius (bandwidth) is calculated based on the spatial configuration and number of input points. This approach corrects for spatial outliers—input points that are very far away from the rest—so they will not make the search radius unreasonably large.
Very large or very small values in the Population field can give results that may seem unintuitive. If the mean of the population field is much bigger than 1 (for example, as with city populations), the default search radius might be very small, resulting in small rings around the input points. If the mean of the population field is much smaller than 1, the calculated bandwidth might seem unreasonably large. In these cases, you may want to enter your own search radius.
The density calculations are dependent on accurate distance and area calculations. It is recommended that in most cases the GEODESIC method should be used. The PLANAR method may be appropriate if the analysis is to be performed on a local area with a projection that accurately maintains the correct distance and area. See Learn more about geographic and projected coordinate systems for determining appropriate projections.
See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.
Syntax
KernelDensity (in_features, population_field, {cell_size}, {search_radius}, {area_unit_scale_factor}, {out_cell_values}, {method})
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 behaviors 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 search radius (bandwidth) is computed specifically to the input dataset using a spatial variant of Silverman's Rule of Thumb that is robust to spatial outliers (that is, points that are far away from the rest of the points). See the usage tips above for a description of the algorithm. | 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 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. If no output spatial reference is specified, the output spatial reference will be the same as the input feature class. The default output density units is determined by the linear units of the output spatial reference as follows. If the output linear units are meters, the output area density units will be set to SQUARE_KILOMETERS, outputting square kilometers for point features or kilometers per square kilometers for polyline features. If the output linear units are feet, the output area density units will be set to SQUARE_MILES. If the output units is anything other than feet or meters, the output area density units will be set to SQUARE_MAP_UNITS. That is, the output density units will be the square of the linear units of the output spatial reference. For example, if the output linear units is centimeters, the output area density units will be SQUARE_MAP_UNITS, which would result in square centimeters. If the output linear units is kilometers, the output area density units will be SQUARE_MAP_UNITS, which would result in square kilometers. The available options and their corresponding output density units are the following:
| String |
out_cell_values (Optional) | Determines what the values in the output raster represent.
| String |
method (Optional) | Determines whether to use a shortest path on a spheroid (geodesic) or a flat earth (planar) method. It is strongly suggested to use the geodesic method with data stored in a coordinate system that is not appropriate for distance measurements (for example, Web Mercator or any geographic coordinate system) and any analysis that spans a large geographic area.
| String |
Return Value
Name | Explanation | Data Type |
out_raster | The output kernel density raster. It is always a floating point raster. | Raster |
Code sample
KernelDensity example 1 (Python window)
This example calculates a smoothed density raster from a point shapefile.
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")
KernelDensity example 2 (stand-alone script)
This example calculates a smoothed density raster from a point shapefile.
# 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")
Environments
Licensing information
- ArcGIS Desktop Basic: Requires Spatial Analyst
- ArcGIS Desktop Standard: Requires Spatial Analyst
- ArcGIS Desktop Advanced: Requires Spatial Analyst