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) or geopackage (.gpkg) (experimental) tiles are currently not imported from geopackage files

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 keys are “label”, tooltip”, “fill”, “stroke”, “stroke_width” and “radius”

Example

Screenshot (Link to open SVG for interactive features):

../_images/example26.png

Source Code (Link to Github):


import os.path
import sys
import argparse
import random
import io

from visigoth.diagram import Diagram
from visigoth.map_layers.geoimport import Geoimport
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.containers.map import Map
from visigoth.utils.mapping import Projections
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()

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

    projection=Projections.ESPG_3857
    bounds = None
    m1 = Map(1024,bounds,projection)

    d.add(Text("GeoPackage Example",font_height=50,text_attributes={"stroke":"purple"}))
    d.add(Space(20,20))

    path = "/tmp/rivers.gpkg"

    if not os.path.exists(path):
        url = "https://raw.githubusercontent.com/opengeospatial/ets-gpkg12/master/src/test/resources/gpkg/rivers.gpkg"
        with open(path,"wb") as f:
            f.write(HttpCache.fetch(url))

    m1.addLayer(Geoimport(path,line_style=lambda p:{"stroke":rng.choice(["red","green","blue"])}))
    d.add(m1)
    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()