Skip to main content

Convert matplotlib contour plots to geojson

Project description

geojsoncontour

Build Status PyPI version Coverage Status
A Python 3 module to convert matplotlib contour plots to geojson. Supports both contour and contourf plots.

Designed to show geographical contour plots, created with matplotlib/pyplot, as vector layer on interactive slippy maps like OpenLayers and Leaflet.

Demo project that uses geojsoncontour: climatemaps.romgens.com

geojson contour demo usage

Installation

Install with pip,

$ pip install geojsoncontour

Usage

Use contour_to_geojson to create a geojson with contour lines from a matplotlib.contour plot (not filled). Use contourf_to_geojson to create a geojson with filled contours from a matplotlib.contourf plot.

Contour plot to geojson

import numpy
import matplotlib.pyplot as plt
import geojsoncontour

# Create contour data lon_range, lat_range, Z
<your code here>

# Create a contour plot plot from grid (lat, lon) data
figure = plt.figure()
ax = figure.add_subplot(111)
contour = ax.contour(lon_range, lat_range, Z, cmap=plt.cm.jet)

# Convert matplotlib contour to geojson
geojson = geojsoncontour.contour_to_geojson(
    contour=contour,
    ndigits=3,
    unit='m'
)

For filled contour plots (matplotlib.contourf) use contourf_to_geojson. See example_contour.py and example_contourf.py for simple but complete examples.

Show the geojson on a map

An easy way to show the generated geojson on a map is the online geojson renderer geojson.io or geojson.tools.

Style properties

Stroke color and width are set as geojson properties following https://github.com/mapbox/simplestyle-spec.

Create geojson tiles

Try geojson-vt or tippecanoe if performance is an issue and you need to tile your geojson contours.

Tests

Run all tests,

python -m unittest discover

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geojsoncontour-0.3.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geojsoncontour-0.3.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file geojsoncontour-0.3.2.tar.gz.

File metadata

  • Download URL: geojsoncontour-0.3.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for geojsoncontour-0.3.2.tar.gz
Algorithm Hash digest
SHA256 1e7efb643e46fffb17371ca851ad1617e59ce367870ad688cbbfdcf4cedc73f4
MD5 02ab490064ac954cc1cdf3fd80bb5272
BLAKE2b-256 a36415fd0d400b8140865be65d52d67caadaf2fa711e2add7ea5daee9330c37b

See more details on using hashes here.

File details

Details for the file geojsoncontour-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: geojsoncontour-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for geojsoncontour-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d815b77e703ce94e8c543a2ed5ac955e1a7c7bba3777af642dbf6406153c93f
MD5 7ebcd7282f490cf6b4c195c2b343d676
BLAKE2b-256 fbc08cf5be306d3a7e63f64b338971bc0a1cab2d3fd3dd8573032b1790dbd3b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page