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.
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 Output cell size can be defined by a numeric value or obtained from an existing raster dataset. If the cell size hasn’t been explicitly specified as the parameter value, it is derived from the Cell Size environment if it has been specified. If the parameter cell size or the environment cell size have not been specified, but the Snap Raster environment has been set, the cell size of the snap raster is used. If nothing is specified, the cell size is calculated from the shorter of the width or height of the extent divided by 250, where the extent is in the Output Coordinate System specified in the environment.
If the cell size is specified using a numeric value, the tool will use it directly for the output raster.
If the cell size is specified using a raster dataset, the parameter will show the path of the raster dataset instead of the cell size value. The cell size of that raster dataset will be used directly in the analysis, provided the spatial reference of the dataset is the same as the output spatial reference. If the spatial reference of the dataset is different than the output spatial reference, it will be projected based on the selected Cell Size Projection Method.
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.
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).
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 of the output raster that will be created. This parameter can be defined by a numeric value or obtained from an existing raster dataset. If the cell size hasn't been explicitly specified as the parameter value, the environment cell size value will be used if specified; otherwise, additional rules will be used to calculate it from the other inputs. See the usage for more detail. | 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
- Basic: Requires Spatial Analyst
- Standard: Requires Spatial Analyst
- Advanced: Requires Spatial Analyst