Line Statistics (Spatial Analyst)
Summary
Calculates a statistic on the attributes of lines in a circular neighborhood around each output cell.
Usage
-
Only the part of a line within the neighborhood is considered for the Majority, Mean, Median and Minority 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, the Variety statistic assigns 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. 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. For the other statistics, the output data type is the same as the input item value type.
-
When the field is integer, the available overlay 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.
-
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 type Mean, the output raster will always be floating point. For Variety, the output raster will always be integer.
Syntax
Parameter | Explanation | Data Type |
in_polyline_features |
The input polyline features for which to calculate the Line Statistics. | Feature Layer |
field |
Field can be any numeric field of the input line features. It can be the Shape field if the input features contains 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.
| 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 # Author: ESRI # 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")