This Python script aggregates geolocated point data into approximately 1 km² hexagonal zones using the H3 geospatial indexing system. It is useful for spatial clustering, density analysis, and visualizing concentrations of point-based geodata.
- Reads geospatial point data from an Excel file
- Cleans and validates latitude/longitude input
- Assigns each coordinate to an H3 cell (resolution 8 ≈ 1 km²)
- Counts how many points fall within each hex cell
- Computes the centroid of each H3 cell
- Saves the result to a new Excel file
To run the script, install the following Python packages:
pip install pandas h3 openpyxl- Clone or download this repository.
- Run the script in a terminal or IDE:
python h3_density_mapper.py-
You will be prompted to:
- Enter the path to your input Excel file
- Provide the desired output path for the results
Your Excel file should include the following columns:
latitudelongitude
These can be in any order. Column names are case-insensitive, and leading/trailing spaces will be trimmed.
The output Excel file will contain:
h3_cell: the H3 hexagon ID (resolution 8)count: the number of points in that hexagoncentroid_lat: latitude of the hexagon centercentroid_lng: longitude of the hexagon center
You can change the H3 resolution (currently set to 8) in the script to adjust the size of the aggregation cells.
📘 Refer to the H3 Resolution Guide for more details on hexagon sizes.
This project is released under the MIT License.