Chloropleth

class visigoth.map_layers.chloropleth.Chloropleth(path, valuePropertyName, labelPropertyName, palette, default_fill_colour='white', stroke='black', stroke_width=2)

Create a Choloropleth plot

Parameters
  • path – a geojson or geopackage file path

  • valuePropertyName (str) – the name of the property to provide the value to visualize

  • labelPropertyName (str) – the name of the property to provide the label

  • palette (list) – a list of (value, colour) pairs or a list of [(min-value, min-colour),(max-value,max-colour)]

Keyword Arguments
  • default_fill_colour (str) – default colour for areas where a value cannot be obtained

  • stroke (str) – stroke color for circumference of circles

  • stroke_width (int) – stroke width for circumference of circles

Notes:

Example

Screenshot (Link to open SVG for interactive features):

../_images/example22.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import random
import json

from visigoth.diagram import Diagram
from visigoth.containers.map import Map
from visigoth.map_layers.chloropleth import Chloropleth
from visigoth.containers.box import Box
from visigoth.common.legend import Legend
from visigoth.common.button import Button
from visigoth.common.text import Text
from visigoth.common.space import Space
from visigoth.utils.mapping import Mapping
from visigoth.utils.colour import ContinuousPalette
from visigoth.utils.httpcache import HttpCache

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    palette = ContinuousPalette()
    palette.addColour("green",0.0).addColour("blue",10.0)

    rng = random.Random()
    d = Diagram(fill="white")

    path = HttpCache.fetch("https://raw.githubusercontent.com/opengeospatial/ets-gpkg12/master/src/test/resources/gpkg/states10.gpkg",suffix=".gpkg",returnPath=True)

    d.add(Text("randomness",font_height=50,text_attributes={"stroke":"purple"}))
    d.add(Space(20,20))
    c = Chloropleth(path,lambda props:rng.random()*10,"name",palette)
    bounds = ((-124.848974, 24.396308),(-66.885444, 49.384358))
    m = Map(1024,bounds,zoom_to=3)
    m.addLayer(c)
    d.add(Box(m))
    d.add(Space(20,20))
    d.add(Legend(palette,width=500,legend_columns=3))
    d.add(Text("Attribution: https://github.com/opengeospatial/ets-gpkg12",url="https://github.com/opengeospatial/ets-gpkg12",font_height=18))
    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()