ANALYSIS TOOL BOX

Geospatial Analysis

ConductClusterAnalysis

Perform density-based spatial clustering on geospatial data.

geospatialmapsgisspatial

Introduction

Where are points on a map actually clumping together, as opposed to just being scattered across a region? ConductClusterAnalysis answers that with DBSCAN (Density-Based Spatial Clustering of Applications with Noise), which groups geographic points by proximity rather than forcing them into a fixed number of round clusters like K-Means would. That makes it well suited to real-world geography: clusters can be any shape, points that don't belong to any dense group are labeled "Noise" instead of being crammed into the nearest one, and distances are computed with the Haversine formula so results stay accurate at the scale of real earth coordinates.

Teaching Note

Geospatial cluster analysis is essential for:

  • Identifying periodic gathering points or high-activity zones in intelligence analysis
  • Mapping disease outbreaks or infection hotspots in epidemiology
  • Analyzing urban traffic patterns and identifying public transit bottlenecks
  • Optimizing logistics and locating optimal supply chain distribution centers
  • Detecting anomalies or "ghost" signals in sensor networks
  • Exploring environmental patterns such as deforestation or wildlife migration
  • Segmenting customer locations for localized marketing strategies

Parameters

ParameterTypeDefaultDescription
dataframerequiredpd.DataFrameThe input dataset containing geographic coordinates.
longitude_columnstr'lon'The name of the column containing longitude values. Defaults to 'lon'.
latitude_columnstr'lat'The name of the column containing latitude values. Defaults to 'lat'.
distance_kmfloat5The maximum distance (epsilon) between two points to be considered neighbors, measured in kilometers. Defaults to 5.
min_samplesint5The minimum number of points required to form a dense region (cluster). Defaults to 5.
map_clustersboolFalseWhether to generate and display an interactive Folium map visualization of the resulting clusters. Defaults to False.

Returns

A pandas DataFrame summarizing each identified cluster: cluster ID, cluster name, midpoint coordinates (mean latitude/longitude), and point count.

Example

python
from analysistoolbox.geospatial_analysis import ConductClusterAnalysis
import pandas as pd
import numpy as np

# Intelligence analysis: identifying high-activity zones from signal data
signal_data = pd.DataFrame({
    'signal_id': range(1, 101),
    'lat': [34.05 + np.random.normal(0, 0.01) for _ in range(100)],
    'lon': [-118.24 + np.random.normal(0, 0.01) for _ in range(100)]
})

cluster_summary = ConductClusterAnalysis(
    signal_data,
    longitude_column='lon',
    latitude_column='lat',
    distance_km=0.5,
    min_samples=10,
    map_clusters=True
)
# Returns summary statistics and displays an interactive map of clusters