Line Statistics (Spatial Analyst)

License Level:BasicStandardAdvanced

Summary

Calculates a statistic on the attributes of lines in a circular neighborhood around each output cell.

Learn more about how Line Statistics works

Usage

Syntax

LineStatistics (in_polyline_features, field, {cell_size}, {search_radius}, {statistics_type})
ParameterExplanationData Type
in_polyline_features

The input polyline features for which to calculate the Line Statistics.

Feature Layer
field

The Field that will be used to calculate the specified statistic on. It can be any numeric field of the input line features.

When the Statistics type is set to Length, the Field can be set to None.

It can be the Shape field if the input features contain z.

Field
cell_size
(Optional)

Cell size for output raster dataset.

This is the value in the environment if specifically set. If not set in the environment, it is the shorter of the width or height of the extent of the input feature dataset, in the output spatial reference, divided by 250.

Analysis Cell Size
search_radius
(Optional)

Search radius to calculate the desired statistic within, in map units.

The default radius is five times the output cell size.

Double
statistics_type
(Optional)

The Statistic type to be calculated.

Statistics are calculated on the value of the specified field for all lines in the neighborhood.

  • MEAN Calculates the average field value in each neighborhood, weighted by the length.The form of the calculation is:
    • Mean = (sum of (length * field_value)) / (sum_of_length)
    Only the part of the length that falls within the neighborhood is used.
  • MAJORITY Determines the value having the greatest length of line in the neighborhood.
  • MAXIMUMDetermines the largest value in the neighborhood.
  • MEDIAN Determines the median value, weighted by the length.Conceptually, all line segments in the neighborhood are sorted by value and placed end-to-end in a straight line. The value of the segment at the midpoint of the straight line is the median.
  • MINIMUM Calculates smallest value in each neighborhood.
  • MINORITY The value having the least length of line in the neighborhood.
  • RANGE The range of values (maximum–minimum).
  • VARIETY The number of unique values.
  • LENGTHThe total line length in the neighborhood. If the value of the field is other than 1, the lengths are multiplied by the item value before adding them together. This option can be used when the Field is set to None.
String

Return Value

NameExplanationData Type
out_raster

The output line statistics raster.

Raster

Code Sample

LineStatistics example 1 (Python window)

This example calculates the average length of line segments within a certain radius of each cell in the input raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
lineStatOut = LineStatistics("streams", "LENGTH", 50, 500, "MEAN")
lineStatOut.save("C:/sapyexamples/output/linestatout")
LineStatistics example 2 (stand-alone script)

This example calculates the average length of line segments within a certain radius of each cell in the input raster.

# Name: LineStatistics_Ex_02.py
# Description: 
# 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
inLines = "streams.shp"
field = "LENGTH"
cellSize = 50
searchRadius = 500

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute LineStatistics
lineStatOut = LineStatistics(inLines, field, cellSize, searchRadius,
                              "MEAN")

# Save the output 
lineStatOut.save("C:/sapyexamples/output/linestatisout")

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Requires Spatial Analyst
ArcGIS for Desktop Standard: Requires Spatial Analyst
ArcGIS for Desktop Advanced: Requires Spatial Analyst
4/10/2014