Display a path of Linestrings in GeoViews

673 Views Asked by At

I am trying to visualize some LINESTRINGS in a Jupyter Notebook using the Path Object in Goeviews. The Path should be colorcoded by the amount of traffic (see example below). I read the related post Displaying Paths with Geoviews and the given example worked for me.

However, the coloring does not seem to work for Linestrings. Am I missing something? Any help is much appreciated!

import requests
import geopandas as gpd
import json

import holoviews as hv
import geoviews as gv
hv.extension('bokeh')

url = 'http://stadtplan.bonn.de/geojson?Thema=19584'
r = requests.get(url)
data = r.json()
gdf_traffic = gpd.GeoDataFrame.from_features(data['features'])
gdf_traffic.head(1)



#'geschwindigkeit' = 'traffic' in German
%%opts Path [width=500 height=500 color_index="geschwindigkeit"] (cmap='inferno')

gv.Path(gdf_traffic, vdims=["geschwindigkeit"])
2

There are 2 best solutions below

0
On

Having a similar issue, I ended up using hvplot :

gdf_traffic.set_geometry("geometry").hvplot(
    by = "geschwindigkeit",
    tiles = "CartoLight",
    legend_position = "top_left"
)

map result

You’ll need to import hvplot.pandas before the geodataframe is created.

I’m not sure why entries are missing in the legend, didn’t look into it yet. Not sure how to change the colormap either, there seems to be related bug reports on HoloViz’s github.

1
On

If someone still wants to know how to colour the LineStrings, this works for me:

gv.Path(gdf_traffic, vdims=["geschwindigkeit"]).opts(color="yellow",line_width=2)