MAD tool script for ArcGIS pro
Median Absolute Distance (MAD) — Outlier-Robust Spatial Clustering Tool Median Absolute Distance (MAD)** is a Python-based ArcGIS Pro geoprocessing tool developed to provide an outlier-resistant approach to spatial clustering analysis. The tool replaces traditional mean-based distance measures with median-based calculations, reducing the influence of extreme or misplaced spatial observations commonly found in rapidly urbanizing, informal, and post-conflict environments. The tool calculates median spatial centers, Euclidean distances, and Median Absolute Deviation values to generate global and category-specific clustering buffers. It supports automated analysis by spatial case fields, allowing large datasets to be processed across multiple administrative or thematic groups. The project was tested on **Kabul Municipality data containing approximately 600,000 building features distributed across 27,000 administrative blocks**. The documented analysis demonstrates its ability to process large urban datasets in minutes while identifying differences in spatial concentration and dispersion across the city. Outputs include global and per-category median centroids, MAD buffer polygons, clustering attributes, and an analytical report. A coefficient of variation derived from MAD and median distance provides an additional interpretation of spatial concentration. The project is released as lightweight, open-source software under the MIT License with applications including informal-settlement analysis, infrastructure planning, environmental monitoring, health-related spatial analysis, and commercial geography. **Technologies:** Python, NumPy, ArcGIS Pro, ArcPy, Spatial Analysis **Scale:** 600,000 features / 27,000 groups **Status:** Version 1.0 — Production Ready **License:** MIT Open Source **Repository:** https://github.com/Hoorzhian/MAD-tool-arcgispro.github.io

Methods used
- Developed a Python-based ArcGIS Pro geoprocessing workflow using NumPy to calculate component-wise median centers
- Euclidean distances
- and Median Absolute Deviation (MAD). The tool automates category-based spatial analysis and generates centroids
- MAD buffers
- clustering attributes
- and summary reports.
Why it matters
The tool provides a lightweight, open-source and outlier-resistant approach to spatial clustering for large urban datasets. Applied to 600,000 building features across 27,000 Kabul blocks, it enables systematic identification of spatial concentration and dispersion patterns to support evidence-based urban analysis and planning.


