Fix shapes that cross the antimeridian. See the documentation for information about the underlying algorithm. Depends on shapely and numpy.
Can fix:
- Shapely
Polygon,MultiPolygon,LineString, andMultiLineStringobjects - GeoJSON Polygons, MultiPolygons, Features and FeatureCollections, as dictionaries
- Anything that has a
__geo_interface__
This repo has been ported to a few other languages:
- Typescript: https://github.com/krisaoe/antimeridian-ts
- Go: https://github.com/go-geospatial/antimeridian
python -m pip install antimeridianThen:
import antimeridian
fixed = antimeridian.fix_geojson(geojson)Note
fix_geojson mutates the input dictionary in-place. If you need to preserve the original GeoJSON, make a copy first:
import copy
fixed = antimeridian.fix_geojson(copy.deepcopy(geojson))We also have some utilities to create bounding boxes and centroids from antimeridian-crossing polygons and multipolygons. See the documentation for a complete API reference.
Use the cli optional dependency to install the antimeridian CLI:
python -m pip install 'antimeridian[cli]'
antimeridian fix input.json > output.jsonGet uv. Then:
git clone https://github.com/gadomski/antimeridian
cd antimeridian
uv syncWe use pytest for tests:
uv run pytestTo build and serve the docs locally:
uv run mkdocs serveSee CONTRIBUTING.md.
