Available with Spatial Analyst license.

## Summary

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

## Usage

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.

Only the part of a line within the neighborhood is considered for the Majority, Mean, Median, Minority, and Length statistics. For the others, it does not matter whether a part or the whole line is used.

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

The statistic types Majority, Mean, Median, and Minority 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.

The values on the output raster will always be integer in the case of Variety. They will always be floating point for Mean and Length. For the other statistics, the output data type is the same as the input item value type.

For statistic types Majority, Maximum, Median, Minimum, Minority, and Range, the output data type of the raster will be the same as the input field type. For statistics types Mean and Length, the output raster will always be floating point. For Variety, the output raster will always be integer.

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

## Syntax

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

Parameter | Explanation | Data Type |

in_polyline_features | The input polyline features for which to calculate the statistics in a neighbourhood around each output cell. | Feature Layer |

field | The field that the specified statistic will be calculated for. It can be any numeric field of the input 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-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 for more detail. | 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) | Specifies the statistic type to be calculated. Statistics are calculated on the value of the specified field for all lines within 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)
- MAJORITY —Determines the value having the greatest length of line in the neighborhood.
- MAXIMUM —Determines 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.
- LENGTH —The 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.
When the specified field is integer, the available statistic choices are Mean, Majority, Maximum, Median, Minimum, Minority, Range, and Variety. When the field is floating point, the only allowed statistics are Mean, Maximum, Minimum, and Range. | String |

#### Return Value

Name | Explanation | Data Type |

out_raster | The output line statistics raster. | Raster |

## Code sample

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")
```

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")
```

## Environments

## Licensing information

- Basic: Requires Spatial Analyst
- Standard: Requires Spatial Analyst
- Advanced: Requires Spatial Analyst