Median Center (Spatial Statistics)

Summary

Identifies the location that minimizes overall Euclidean distance to the features in a dataset.

Learn more about how Median Center works

Illustration

Median Center illustration

Usage

  • While the Mean Center tool returns a point at the average X, average Y and, if applicable, average Z coordinate for all feature centroids, the Median Center tool uses an iterative algorithm to find the point that minimizes Euclidean distance to all features in the dataset.

  • Both the Mean Center and Median Center are measures of central tendency. The algorithm for the Median Center tool is less influenced by data outliers.

  • This tool requires projected data to accurately measure distances.

  • This tool honors the 3D nature of your point data and will use x, y and z values in its calculations if z values are available. Since these results are 3D in nature, they will need to be visualized in a Scene. Be sure that you are running the analysis in a Scene or copy the result layer into a Scene for correct visualization of your analysis results.

  • For line and polygon features, feature centroids are used in distance computations. For multipoints, polylines, or polygons with multiple parts, the centroid is computed using the weighted mean center of all feature parts. The weighting for point features is 1, for line features is length, and for polygon features is area.

  • The Case Field is used to group features for separate median center computations. When a case field is specified, the input features are first grouped according to case field values, and then a median center is calculated for each group. The case field can be of integer, date, or string type, and will appear as an attribute in the Output Feature Class. Records with NULL values for the Case Field will be excluded from analysis.

  • The x, y and z values for the median center feature(s) are attributes in the output feature class. The values are stored in the fields XCOORD, YCOORD and ZCOORD.

  • The data median will be computed for all fields specified in the Attribute Field parameter.

  • Map layers can be used to define the Input Feature Class. When using a layer with a selection, only the selected features are included in the analysis.

  • Caution:

    When using shapefiles, keep in mind that they cannot store null values. Tools or other procedures that create shapefiles from nonshapefile inputs may store or interpret null values as zero. In some cases, nulls are stored as very large negative values in shapefiles. This can lead to unexpected results. See Geoprocessing considerations for shapefile output for more information.

Syntax

arcpy.stats.MedianCenter(Input_Feature_Class, Output_Feature_Class, {Weight_Field}, {Case_Field}, Attribute_Field)
ParameterExplanationData Type
Input_Feature_Class

A feature class for which the median center will be calculated.

Feature Layer
Output_Feature_Class

A point feature class that will contain the features representing the median centers of the input feature class.

Feature Class
Weight_Field
(Optional)

The numeric field used to create a weighted median center.

Field
Case_Field
(Optional)

Field used to group features for separate median center calculations. The case field can be of integer, date, or string type.

Field
Attribute_Field
[Attribute_Field,...]

Numeric field(s) for which the data median value will be computed.

Field

Code sample

MedianCenter Example (Python Window)

The following Python Window script demonstrates how to use the MedianCenter tool.

import arcpy
arcpy.env.workspace = r"C:\data"
arcpy.MedianCenter_stats("coffee_shops.shp", "coffee_MEDIANCENTER.shp", "NUM_EMP", "#", "#")
MedianCenter Example (Stand-alone Python script)

The following stand-alone Python script demonstrates how to use the MedianCenter tool.

# Measure geographic distribution characteristics of coffee house locations weighted by the number of employees
 
# Import system modules
import arcpy
 
# Local variables...
workspace = "C:/data"
input_FC = "coffee_shops.shp"
CF_output = "coffee_CENTRALFEATURE.shp"
MEAN_output = "coffee_MEANCENTER.shp"
MED_output = "coffee_MEDIANCENTER.shp"
weight_field = "NUM_EMP"
 
try:
    # Set the workspace to avoid having to type out full path names
    arcpy.env.workspace = workspace
 
    # Process: Central Feature...
    arcpy.CentralFeature_stats(input_FC, CF_output, "Euclidean Distance", weight_field, "#", "#")
 
    # Process: Mean Center...
    arcpy.MeanCenter_stats(input_FC, MEAN_output, weight_field, "#", "#")

    # Process: Median Center...
    arcpy.MedianCenter_stats(input_FC, MED_output, weight_field, "#", "#")
 
except:
    # If an error occurred when running the tool, print out the error message.
    print(arcpy.GetMessages())

Environments

Output Coordinate System

Feature geometry is projected to the Output Coordinate System prior to analysis. All mathematical computations are based on the Output Coordinate System spatial reference.

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics