Line Statistics (Spatial Analyst)

Available with Spatial Analyst license.

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

  • There are several statistic types to choose from. The selection of available statistics depends on the type of the specified field.

  • For integer fields, the valid choices for Statistics type are: majority, maximum, mean, median, minimum, minority, range, variety, and length. For float fields, the valid statistics are: maximum, mean, minimum, range, and length. Majority, minority, and variety are not available.

  • If the field type is integer, the output raster will be integer for the following statistics: majority, maximum, median, minimum, minority, range, and variety. The output will be float for the mean and length statistics.

    If the field type is float, the output raster will be float for all available statistic types.

  • Only the part of a line that falls within the neighborhood is considered for the majority, mean, median, minority, and length statistics. For the maximum, minimum, range, and variety statistics, a part or the whole line can be used

  • The majority, mean, median, and minority statistics types are weighted according to the length of the lines. For example, if a line is twice as long as another, its value is considered to occur twice as often.

  • If there are no lines in the neighborhood of a raster cell, the variety and length statistics assign a value of zero. For the other statistics, NoData is assigned.

  • The Output cell size 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, 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 value.

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

Parameters

LabelExplanationData Type
Input polyline features

The input lines to use in the neighborhood operation.

For each output cell, a statistic will be calculated for all of the portions of the input polyline features that fall within a circular neighborhood around that cell.

The size the circular neighbourhood is defined by the search radius.

Feature Layer
Field

The field for which the specified statistic will be calculated. It can be any numeric field of the input line features.

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

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

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 that will be used to calculate the statistic within, in map units.

The default radius is five times the output cell size.

Double
Statistics type
(Optional)

Specifies the statistic type to be calculated.

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

The default statistic type is Mean.

The available choices for the statistic type are determined by the numeric type of the specified field. If the field is integer, the available statistic choices will be majority, maximum, mean, median, minimum, minority, range, variety, and length. If the field is floating point, only the mean, maximum, minimum, range, and length statistics will be available.

  • MeanThe average field value in each neighborhood, weighted by the length, will be calculated.The form of the calculation is:
    • Mean = (sum of (length * field_value)) / (sum_of_length)
    Only the part of the line that falls within the neighborhood is used.
  • MajorityThe value having the greatest length of line in the neighborhood will be identified.
  • MaximumThe largest value in the neighborhood will be identified.
  • MedianThe median value, weighted by the length, will be calculated.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.
  • MinimumThe smallest value in each neighborhood will be identified.
  • MinorityThe value having the least length of line in the neighborhood will be identified.
  • RangeThe range of values (maximum–minimum) will be calculated.
  • VarietyThe number of unique values will be calculated.
  • LengthThe total line length in the neighborhood will be calculated. If the value of the field is not 1, the lengths are multiplied by the item value before adding them together. This option can be used when the field parameter is set to None.
String

Return Value

LabelExplanationData Type
Output raster

The output line statistics raster.

Raster

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

The input lines to use in the neighborhood operation.

For each output cell, a statistic will be calculated for all of the portions of the input polyline features that fall within a circular neighborhood around that cell.

The size the circular neighbourhood is defined by the search radius.

Feature Layer
field

The field for which the specified statistic will be calculated. It can be any numeric field of the input line features.

When statistics_type is set to Length, the field parameter can be set to NONE.

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

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 that will be used to calculate the statistic within, in map units.

The default radius is five times the output cell size.

Double
statistics_type
(Optional)

Specifies the statistic type to be calculated.

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

  • MEANThe average field value in each neighborhood, weighted by the length, will be calculated.The form of the calculation is:
    • Mean = (sum of (length * field_value)) / (sum_of_length)
    Only the part of the line that falls within the neighborhood is used.
  • MAJORITYThe value having the greatest length of line in the neighborhood will be identified.
  • MAXIMUMThe largest value in the neighborhood will be identified.
  • MEDIANThe median value, weighted by the length, will be calculated.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.
  • MINIMUMThe smallest value in each neighborhood will be identified.
  • MINORITYThe value having the least length of line in the neighborhood will be identified.
  • RANGEThe range of values (maximum–minimum) will be calculated.
  • VARIETYThe number of unique values will be calculated.
  • LENGTHThe total line length in the neighborhood will be calculated. If the value of the field is not 1, the lengths are multiplied by the item value before adding them together. This option can be used when the field parameter is set to None.

The default statistic type is MEAN.

The available choices for the statistic type are determined by the numeric type of the specified field. If the field is integer, the available statistic choices will be majority, maximum, mean, median, minimum, minority, range, variety, and length. If the field is floating point, only the mean, maximum, minimum, range, and length statistics will be available.

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

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

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