Geoimport

class visigoth.map_layers.geoimport.Geoimport(path, point_style=<function Geoimport.<lambda>>, line_style=<function Geoimport.<lambda>>, polygon_style=<function Geoimport.<lambda>>)

Import and plot a layer composed of points, lines and polygons described in a source file source file formats supported are geojson (.geojson)

Parameters:

path – path to the file to be imported

Keyword Arguments:
 
  • path (str) – path to file to import
  • point_style (dict|function) – see Notes
  • line_style (dict|function) – see Notes
  • polygon_style (dict|function) – see Notes

Notes

The point_style, line_style and polygon_style values should be dicts or functions operating on a properties dict and returning a style dict The returned dict describes the SVG rendering style for the element (point, line, area) Possible keys are “label”, tooltip”, “fill”, “stroke”, “stroke_width”, “radius”, “popup” and “marker” These keys map to keyword arguments of the geoplot.Multipoint, geoplot.Multiline and geoplot.Multipolygon instances

Example

(Link to open example in new tab):

Source Code (Link to Github):

# -*- coding: utf-8 -*-

import os.path
import random

from visigoth.diagram import Diagram
from visigoth.map_layers import Geoimport
from visigoth.containers import Map

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

path = os.path.join(os.path.split(__file__)[0],"nz_region.geojson")

m1.addLayer(Geoimport(path,polygon_style=lambda p:{"tooltip":p["REGC2016_N"],"fill":rng.choice(["red","orange","yellow"])}))
d.add(m1)

html = d.draw(format="html")

f = open("example.html", "w")
f.write(html)
f.close()