Geoplot

class visigoth.map_layers.geoplot.Geoplot(multipoints=[], multilines=[], multipolys=[], font_height=12, text_attributes={}, label_fill='#FFFFFF80')

Create a geo plot containing specified multi-points or multi-lines or multi-polygons

Keyword Arguments
  • multipoints (list) – points list of Multipoint

  • multilines (list) – lines list of Multiline

  • multipolys (list) – polygons to plot list of Multipoylgon

  • font_height (int) – font size in pixels for labels

  • text_attributes (dict) – a dict containing SVG name/value attributes to apply to labels

  • label_fill (str) – fill colour for displaying labels

Example

Screenshot (Link to open SVG for interactive features):

../_images/example27.png

Source Code (Link to Github):


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

from visigoth.diagram import Diagram
from visigoth.containers.map import Map
from visigoth.map_layers.geoplot import Geoplot
from visigoth.map_layers.wms import WMS
from visigoth.containers.popup import Popup
from visigoth.containers.box import Box
from visigoth.common.button import Button
from visigoth.common.text import Text
from visigoth.common.space import Space
from visigoth.map_layers.geoplot import Multipoint,Multiline,Multipolygon
from visigoth.utils.mapping import Geocoder,Projections

from visigoth.svg import circle

if __name__ == "__main__":

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

    rng = random.Random()
    d = Diagram(fill="white")
    
    gc = Geocoder()
    bb = gc.fetchBoundingBox("Berlin")

    lon_min = bb[0][0]
    lon_max = bb[1][0]
    lat_min = bb[0][1]
    lat_max = bb[1][1]

    lon_range = lon_max-lon_min
    lat_range = lat_max-lat_min

    multipoints=[]
    for i in range(20):
        popup = Popup(Text("Popup! %d"%(i)),"popup")
        label = "point_%d"%i
        col = rng.choice(["red","purple","orange","green"])
        lon = lon_min+rng.random()*lon_range
        lat = lat_min+rng.random()*lat_range
        multipoints.append(Multipoint([(lon,lat)],label=label,popup=popup,properties={"type":"point"},fill=col))

    multilines=[]
    popup = Popup(Text("Popup! %d"%(i)),"popup")
    label = "line_%d"%i
    multiline = []
    multiline.append((lon_min+lon_range*0.1,lat_min+lat_range*0.2))
    multiline.append((lon_min+lon_range*0.3,lat_min+lat_range*0.3))
    multiline.append((lon_min+lon_range*0.5,lat_min+lat_range*0.6))
    multiline.append((lon_min+lon_range*0.8,lat_min+lat_range*0.9))
    multilines.append(Multiline([multiline],label=label,popup=popup,properties={"type":"line"},fill="white",width=10,stroke="red",stroke_width=3))

    multipolys=[]

    lps = []
        
    lps.append((lon_min+lon_range*0.6,lat_min+lat_range*0.5))
    lps.append((lon_min+lon_range*0.9,lat_min+lat_range*0.5))
    lps.append((lon_min+lon_range*0.9,lat_min+lat_range*0.8))
    lps.append((lon_min+lon_range*0.6,lat_min+lat_range*0.8))

    hole = []

    hole.append((lon_min+lon_range*0.7,lat_min+lat_range*0.6))
    hole.append((lon_min+lon_range*0.8,lat_min+lat_range*0.6))
    hole.append((lon_min+lon_range*0.8,lat_min+lat_range*0.7))
    hole.append((lon_min+lon_range*0.7,lat_min+lat_range*0.7))
       
    popup = Popup(Text("Popup! %d"%(i)),"popup")
    label = "poly_%d"%i
    multipolys.append(Multipolygon([[lps,hole]],label=label,popup=popup,properties={"type":"poly"},stroke="red",fill="#0000FF30"))

    m = Map(512,boundaries=bb,projection=Projections.ESPG_3857,zoom_to=2)
    m.addLayer(WMS())
    gp = Geoplot(multipoints=multipoints,multilines=multilines,multipolys=multipolys)
    m.addLayer(gp)

    gj = Box(m)
    d.add(gj)
    svg = d.draw()

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