Skip to main content

Geohexgrid

Tests: pipeline status

A tiny Python 3.10+ library for making geographic flat-top hexagonal grids like QGIS’s create grid function. That’s it. Not designed for making other kinds of grids or discrete global grid systems.

Here a hexagonal grid, or hex grid for short, is a finite subset of a hexagonal tiling. A hexagonal tiling is a covering of the plane with regular hexagons in which exactly three hexagons meet at each vertex. (For more details, see the Wikipedia article on hexagonal tilings.) The circumradius of a hex grid is the circumradius of any one of its hexagons, that is, the radius of a circle circumscribing any one of the hexagons. This library favors the word ‘grid’ over ‘tiling’, because ‘grid’ is used more often in geographic context, the main context of this library.

The two main features of this library are

  • Making a flat-top hexagonal grid of given circumradius that minimally covers a GeoDataFrame of features, where distance units come from the GeoDataFrame’s coordinate reference system (CRS), e.g. no units for no CRS, metres for the New Zealand Transverse Mercator (NZTM) CRS, and decimal degrees for the WGS84 CRS.

  • By default, hex grids made with a common CRS and circumradius share an origin and thus have equal hexagons (and hexagon IDs) where they overlap. In other words, the grids share a single (infinite) hexagonal tiling of the plane, which is useful when reconciling multiple grids across different geographic areas.

The main non-feature of this library is

  • Making any other kind of grid, e.g. ones with pointy-top hexagons, squares, triangles, kisrhombilles, Penrose tiles…

Here’s a typical example.

import geopandas as gpd
import geohexgrid as ghg

# Load New Zealand territorial authorities projected in EPSG 2193 (NZTM)
nz = gpd.read_file(DATA_DIR / "nz_tas.gpkg")

# Cover it minimally with hexagons of circumradius 10 kilometres
grid = ghg.make_grid_from_gdf(nz, R=10_000)

# Plot
base = nz.plot(color="black", figsize=(10, 10), aspect="equal")
grid.plot(ax=base, color="white", edgecolor="red", alpha=0.5)
hexagon grid of 10,000-metre circumradius covering New Zealand

But why hexagons?! Because hexagons are the bestagons. More seriously, no one grid type works best for all geographic applications. MRCagney, this library’s funder, often works with isochrones, which favor simple convex equal area grids with equidistant neighbor cells, that is, hex grids.

Authors

  • Alex Raichev (2022-07), maintainer

Installation

Install from PyPI, e.g. via uv add geohexgrid.

Examples

See the Marimo notebook at notebooks/examples.py.

Notes

  • This project uses semantic versioning for release numbering.

  • Its current development status is Alpha, which means interfaces and behavior may still change in ways that are more disruptive than users of mature libraries should expect.

  • Thanks to MRCagney for periodically funding this project.

  • Red Blog Games has a great write up of hexagonal grids for computer games.

  • Alex wanted to choose a shorter name for this package, such as ‘hexgrid’, ‘geohex’, or ‘hexcover’, but those were already taken or too close to taken on PyPI.

Changes

3.0.3, 2026-07-07

  • Fixed make_grid_from_gdf crashing in intersect mode when the input GeoDataFrame already has a cell_id (or index_right) column; the spatial join now uses only the input’s geometry.

  • Sped up make_grid roughly 7x by vectorizing its polygon construction, with byte-identical output.

  • Pointed the geographic-CRS warning at the caller’s line instead of library internals.

  • Slimmed the sdist and removed a stray pre-commit hooks file.

3.0.2, 2026-06-16

  • Fixed make_grid_from_bounds (and hence make_grid_from_gdf), which could under-cover the input rectangle for many radii and origins; the grid now always covers the rectangle and is minimal.

  • Made mp_apply return a consistently reindexed result and run serially when num_workers == 1.

  • Accepted NumPy integers as valid integer arguments.

  • Restricted the package’s public API to its intended functions (no longer re-exporting third-party modules).

  • Derived __version__ from the installed package metadata.

  • Removed the unused loguru development dependency and fixed two README typos.

3.0.1, 2026-03-12

  • Added stronger validation for grid dimensions, radius, trim mode, and GeoDataFrame inputs.

  • Added a warning when using geographic CRSs, since grid sizes are then interpreted in angular units.

  • Fixed function mp_apply.

  • Fixed packaging metadata in pyproject.toml.

3.0.0, 2025-06-24

  • Breaking change: changed signature of main.make_grid_from_gdf with trim_mode option.

  • Sped up with parallel processing the spatial operations of main.make_grid_from_gdf when using a trim mode.

2.1.2, 2025-06-16

  • Fixed a docstring typo.

  • Changed pre-commit hooks.

  • Replaced Jupyter with Marimo.

  • Updated dependencies.

2.1.1, 2025-03-07

  • Removed unused Loguru import in main.py. This was preventing users from installing Geohexgrid, because Loguru is only a development dependency.

2.1.0, 2024-09-26

  • Bugfixed make_grid_from_bounds in response to Issue 2.

  • Switched from Poetry to UV for project management.

  • Bumped Python version up to 3.10+.

2.0.0, 2023-11-14

  • Refactored for simpler architecture, gapless grids, and a ~15x speed up in the main function grid_from_gdf.

1.1.0, 2023-10-27

  • Added the clip option to the function grid_from_gdf.

  • Updated dependencies.

  • Re-ordered functions.

  • Changed the cell ID separotor to a comma.

1.0.0, 2022-08-15

  • First release.

Metadata

Release files for geohexgrid 3.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geohexgrid 3.0.3
File Size Uploaded
geohexgrid-3.0.3.tar.gz 629.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for geohexgrid 3.0.3
File Interpreter ABI Platform
geohexgrid-3.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 641.0 kB

Release files / geohexgrid-3.0.3.tar.gz

Download URL geohexgrid-3.0.3.tar.gz
Size 629.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f2eceae5f8fa36e5922f9632ffecf33b52961f70decbcd36a0f62d23cf105936
BLAKE2b-256 checksum
How to use checksums
92f63183114f2632c32a025d42a9635de9e69cd8829bbe19d28d9dcd019e3c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / geohexgrid-3.0.3-py3-none-any.whl

Download URL geohexgrid-3.0.3-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4392f43930bf0b9b281ffa0fcd64111af7307f786305bfaf0a7066ac6a25074
BLAKE2b-256 checksum
How to use checksums
4f775b7fe4105abacf7e571eafd5e23d22071ad3203ef9b4eb0842337474b345
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

3.0.3 This release

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page