Skip to main content

Well-known-text and shapely object visualiation library

Project description

WKTPlot

Wrapper around the Bokeh library for plotting well-known-text strings and shapely geometries!

Badges

PyPi Python Versions

codecov

Codacy Badge

Installation


pip install wktplot

Description

The well-known-text standard is very common for working with and representing geospatial data, however it is painful to visualize them programatically. The Shapely library extends the functionality of the well-known-text standard with a rich assortment of geometry objects and operations, but it doesn't make it any easier to visualize.

WKTPlot is a library provides an easy-to-use API for visualizing well-known-text strings and shapely objects programatically. This library wraps around the Bokeh library, which is a powerful plotting library for generating interactive visualizations. Bokeh also provides a rich assortment of stylizing options which are all usable through WKTPlot's add_shape method.

Basic Usage

from shapely.geometry import Polygon

from wktplot import WKTPlot



# Create plot object

plot = WKTPlot(title="My first plot!", save_dir="/path/to/directory")



# Define shapes either through well-known-text (WKT) string, or shapely object

shape_1 = "POINT (30 10)"

shape_2 = Polygon([[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]])



# Add shapes to the plot

plot.add_shape(shape_1, fill_color="green", line_width=3)

plot.add_shape(shape_2, fill_color="cyan", fill_alpha=0.7)



# Save the plot to disk [/path/to/directory/my_first_plot.html]

plot.save()

Supported datatypes

WKTPlot supports majority of shapely objects including:

  • Point

  • MultiPoint

  • LineString

  • MultiLineString

  • LinearRing

  • Polygon

  • MultiPolygon

  • GeometryCollection

Advanced Usage

Example for plotting from shapefile. Shapefile is of California's county boundaries from here.

import shapefile  # pyshp module



from random import randrange

from shapely.geometry import Polygon

from wktplot import WKTPlot



def get_rand_color():

    return f"#{randrange(0, 0xffffff):0>6x}"



plot = WKTPlot(title="California Counties", save_dir="~/scratch")

with shapefile.Reader("~/scratch/CA_Counties_TIGER2016.shp") as shp:

    for shape in shp.shapes():

        p = Polygon(shape.points)

        plot.add_shape(p, fill_color=get_rand_color())

plot.save()

Which will result in this output:

CaliforniaCounties

Dependency Limitations

  • Shapely version 1.8 is not yet compatible with Python 3.9 on M1 MacOS Big Sur: issue

  • Shapely version 1.8 is not yet compatible with Python 3.9 on Windows: issue

Future Plans

  • Add native support for visualizing GeoDataframes and shapefiles.

  • Make web view more interactive.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

wktplot-2.1.0-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wktplot-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: wktplot-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for wktplot-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b767ee886e5e172fb8437c8808ed33d7cf6155e52ffba6c5ee4dbb1077d7b989
MD5 dab3bd23e6f196bbe20b9d5648e650c6
BLAKE2b-256 716e88d101fe9bd300f09f743d1057f689c969fdcc170969175867d517e4fa54

See more details on using hashes here.

Supported by

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