Kernel Density (Spatial Analyst)

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. A barrier can be used to alter the influence of a feature while calculating Kernel Density.

Learn more about how Kernel Density works

Illustration

Kernel Density illustration
OutRas = KernelDensity(InPts, None, 30)

Usage

  • Larger values of the Search radius (search_radius in Python) 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 when 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 (population_field in Python) parameter can produce results that may seem non-intuitive. If the mean of the population field is much larger than 1 (for example, as with city populations), the default search radius may 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 search radius may seem unreasonably large. In these cases, you can 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, in which 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.

  • The default search radius 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).

  • For data formats that support Null values, such as file geodatabase feature classes, a Null value will be ignored when used as input.

  • The Output cell values (out_cell_values in Python) parameter specifies what the output raster values represent. If Densities is chosen, the values represent the kernel density value per unit area for each cell. If Expected counts is chosen, the values represent the kernel density per cell area. The equation that calculates the counts from the density values is Count = Density × Area.

  • The Planar option (PLANAR in Python) in the Method (method in Python) parameter is appropriate if the analysis is to be performed at a local scale with a projection that accurately maintains the correct distance and area. The Geodesic (GEODESIC in Python) option is appropriate if the analysis is to be performed at a regional or large scale (for example, using Web Mercator or any geographic coordinate system). This method takes into account the curvature of the spheroid and correctly handles data near the poles and the international dateline.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

LabelExplanationData Type
Input point or polyline features

The input features (point or line) for which to calculate the density.

Feature Layer
Population field

The 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 can be integer or floating point.

The options and default behaviors for the field are listed below.

  • Use None if no item or special value will be used and each feature will be counted once.

  • You can use the Shape field if input features contain Z.

  • Otherwise, the default field is POPULATION. The following conditions may also apply:

    • If there is no POPULATION field, but there is a POPULATIONxxxx field, it will be used by default. The xxxx can be any valid characters, for example, POPULATION6, POPULATION1974, and POPULATIONROADTYPE.
    • If there is no POPULATION field or POPULATIONxxxx field, but there is a POP field, it will be used by default.
    • If there is no POPULATION field, POPULATIONxxxx field, or POP field, but there is a POPxxxx field, it will be used by default.
    • If there is no POPULATION field, POPULATIONxxxx field, POP field, or POPxxxx field, NONE will be used by default.
Field
Output 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 section 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 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 is computed specifically for the input dataset using a spatial variant of Silverman's Rule of Thumb (Silverman, 1986) that is robust enough for spatial outliers (points that are far away from the rest of the points). See the usage tips for a description of the algorithm.

Double
Area units
(Optional)

The 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 want 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 are 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 are centimeters, the output area density units will be Square map units, which will result in square centimeters. If the output linear units are kilometers, the output area density units will be Square map units, which will result in square kilometers.

The available options and their corresponding output density units are the following:

  • Square map unitsFor the square of the linear units of the output spatial reference.
  • Square milesFor miles (U.S.).
  • Square kilometersFor kilometers.
  • AcresFor acres (U.S.).
  • HectaresFor hectares.
  • Square yardsFor yards (U.S.).
  • Square feetFor feet (U.S.).
  • Square inchesFor inches (U.S.).
  • Square metersFor meters.
  • Square centimetersFor centimeters.
  • Square millimetersFor millimeters.
String
Output cell values
(Optional)

Specifies what the values in the output raster represent.

Since the cell value is linked to the specified cell size, the resulting raster cannot be resampled to a different cell size.

  • DensitiesThe output values represent the calculated density value per unit area for each cell. This is the default.
  • Expected countsThe output values represent the calculated density value per cell area.
String
Method
(Optional)

Specifies whether the flat earth (planar) or the shortest path on a spheroid (geodesic) method will be used.

The geodesic method only supports points as input features.

  • PlanarThe planar distance between features will be used. This is the default.
  • GeodesicThe geodesic distance between features will be used.
String
Input barrier features
(Optional)

The dataset that defines the barriers.

The barriers can be a feature layer of polyline or polygon features.

Feature Layer

Return Value

LabelExplanationData Type
Output raster

The output kernel density raster.

It is always a floating point raster.

Raster

KernelDensity(in_features, population_field, {cell_size}, {search_radius}, {area_unit_scale_factor}, {out_cell_values}, {method}, {in_barriers})
NameExplanationData Type
in_features

The input features (point or line) for which to calculate the density.

Feature Layer
population_field

The 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 can be integer or floating point.

The options and default behaviors for the field are listed below.

  • Use None if no item or special value will be used and each feature will be counted once.

  • You can use the Shape field if input features contain Z.

  • Otherwise, the default field is POPULATION. The following conditions may also apply:

    • If there is no POPULATION field, but there is a POPULATIONxxxx field, it will be used by default. The xxxx can be any valid characters, for example, POPULATION6, POPULATION1974, and POPULATIONROADTYPE.
    • If there is no POPULATION field or POPULATIONxxxx field, but there is a POP field, it will be used by default.
    • If there is no POPULATION field, POPULATIONxxxx field, or POP field, but there is a POPxxxx field, it will be used by default.
    • If there is no POPULATION field, POPULATIONxxxx field, POP field, or POPxxxx field, NONE will be used by default.
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 section 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 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 is computed specifically for the input dataset using a spatial variant of Silverman's Rule of Thumb (Silverman, 1986) that is robust enough for spatial outliers (points that are far away from the rest of the points). See the usage tips for a description of the algorithm.

Double
area_unit_scale_factor
(Optional)

The 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 want 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 are 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 are centimeters, the output area density units will be Square map units, which will result in square centimeters. If the output linear units are kilometers, the output area density units will be Square map units, which will result in square kilometers.

The available options and their corresponding output density units are the following:

  • SQUARE_MAP_UNITSFor the square of the linear units of the output spatial reference.
  • SQUARE_MILESFor miles (U.S.).
  • SQUARE_KILOMETERSFor kilometers.
  • ACRESFor acres (U.S.).
  • HECTARESFor hectares.
  • SQUARE_YARDSFor yards (U.S.).
  • SQUARE_FEETFor feet (U.S.).
  • SQUARE_INCHESFor inches (U.S.).
  • SQUARE_METERSFor meters.
  • SQUARE_CENTIMETERSFor centimeters.
  • SQUARE_MILLIMETERSFor millimeters.
String
out_cell_values
(Optional)

Specifies what the values in the output raster represent.

  • DENSITIESThe output values represent the calculated density value per unit area for each cell. This is the default.
  • EXPECTED_COUNTSThe output values represent the calculated density value per cell area.

Since the cell value is linked to the specified cell size, the resulting raster cannot be resampled to a different cell size.

String
method
(Optional)

Specifies whether the flat earth (planar) or the shortest path on a spheroid (geodesic) method will be used.

  • PLANARThe planar distance between features will be used. This is the default.
  • GEODESICThe geodesic distance between features will be used.

The geodesic method only supports points as input features.

String
in_barriers
(Optional)

The dataset that defines the barriers.

The barriers can be a feature layer of polyline or polygon features.

Feature Layer

Return Value

NameExplanationData 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.

from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outKDens = KernelDensity("rec_sites.shp", " ", 45, 1200, "SQUARE_KILOMETERS",
                         " ", "GEODESIC")
outKDens.save("C:/sapyexamples/output/KD_out.tif")
KernelDensity example 2 (stand-alone script)

This example calculates a smoothed density raster from a point shapefile.

# Name: KernelDensity_Ex_02.py
# Description: Calculates the ozone concentration pattern divided by
#              Sierra Nevada Mountain in California
#              based on the point samples using a kernel function to
#              fit a smoothly tapered surface.
# 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 = "ozone_california.shp"
populationField = "OZONE"
cellSize = 60
searchRadius = 2500
inBarriers = "SierraNevada.shp"

# Execute KernelDensity
outKernelDensity = KernelDensity(inFeatures, populationField, cellSize, searchRadius,
                                 "SQUARE_KILOMETERS", "DENSITIES", "PLANAR", inBarriers)

# Save the output 
outKernelDensity.save("C:/sapyexamples/output/KD_ozone_california.tif")

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics