mattijn / topojson

Encode spatial data as topology in Python! 🌍 https://mattijn.github.io/topojson
BSD 3-Clause "New" or "Revised" License
183 stars 27 forks source link
geojson python simplification spatial-data topojson topojson-format topology

topojson

PyPI version License github actions Conda version shapely, numpy 2.0 compliant

Encode spatial data as topology in Python!

Topojson is a library that is capable of creating a topojson encoded format of merely any spatial object in Python.

With topojson it is possible to reduce the size of your spatial data. Mostly by orders of magnitude. It is able to do so through:

See Topojson Documentation Site for all info how to use this package.

Usage

The package can be used in multiple different ways, with the main purpose to create a TopoJSON topology.

See the Python Topojson Documentation Site for all info or this Notebook with some examples, such as the following:

click to open notebook

Click on the image to go the Notebook Viewer with code-snippets how these images are created or visit the Topojson Documentation Site.

Installation

Installation can be done through PyPI by the following command:

python -m pip install topojson

And through conda using the following command:

conda install topojson -c conda-forge

This package topojson has the following hard dependencies:

Further, optional soft dependencies are:

Other resources

For a better understanding how the different included simplification algorithms work

You can have a look to this blog post on Line simplification algorithms. There you can find out that the epsilon value for vw is area-based and that the epsilon value for rdp is distance-based.

Also, if your source projection is in meters, than it is very likely that your epsilon value should be magnitudes larger than the examples on this page where the source projection is in degrees.

There is a section on simplification in the book-in-progress on 'Geocomputation with Python' that describes toposimplification as follow:

The main advanatage of .toposimplify is that it is topologically “aware”: it simplifies the combined borders of the polygons (rather than each polygon on its own), thus ensuring that the overlap is maintained.

Get in touch

For now, just use the Github issues. That can be:

Finally, see the Python Topojson Documentation Site for all info how to use this package.