Skip to main content

Python wrapper for visualiation of shapely geometries.

Project description

WKTPlot

Plot well-known-text strings and shapely geometries with Bokeh!

Badges

CircleCI Codacy Badge Codacy Badge

Installation

pip install wktplot

Usage

from wktplot.wkt_plot import WKTPlot

shape = "POLYGON((-124.4009 41.9983,-123.6237 42.0024, ...))"
plot = WKTPlot(title="California", save_dir="/path/to/directory")
plot.add_shape(shape, color="green", line_width=3)
plot.save()

WKTPlot supports majority of shapely objects including:

  • Point
  • MultiPoint
  • LineString
  • MultiLineString
  • LinearRing
  • Polygon
  • MultiPolygon
  • GeometryCollection

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

from random import randrange
from shapely.geometry import Polygon
from wktplot.wkt_plot import WKTPlot

import shapefile  # pyshp module

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/CA_Counties/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

Additional Info

WKTPlot supports Bokeh's stylization parameters for customizing the look of added elemented. See this guide for more info: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html

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 Distribution

wktplot-1.0.1.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

wktplot-1.0.1-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

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