1

I'm trying to understand how the kdims work for Polygon plots in geoviews. There is a similar question here but it hasn't really been answered - GeoViews: add a slider to chloropleth with Polygon geometries

In http://geo.holoviews.org/user_guide/Geometries.html the line

gv.Polygons(world, vdims='pop_est')

yields a world map with polygons shaded by population, and I think what it's somehow doing is getting lat/long as the kdims but I don't understand how this works. If I try to specify 'geometry' as the kdims I get an error "Expected two kdims to use GeoDataFrame, found 1."

My end goal is to be able specify the kdims so that I can also specify a "year" parameter as the kdims and get a scrollbar on the map.

1 Answer 1

0

I think you are looking for something like (see also here: https://nbviewer.jupyter.org/github/poplarShift/pyviz-recipes/blob/master/notebooks/data_formats.ipynb)

import geoviews as gv
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
import holoviews as hv
hv.extension('bokeh')

hv.Dataset(world, kdims=['Longitude', 'Latitude', 'continent'], vdims='pop_est').to(gv.Polygons)
4
  • Thank you for your comment. When I try your code I still get a Data Error - "Expected two kdims to use GeoDataFrame, found 3". Did the code work for you?
    – piedpiper
    Commented Apr 20, 2019 at 17:39
  • Yes. I'm on: geoviews version: 1.6.2 holoviews version: 1.12.1 geopandas version: 0.4.1 bokeh version: 1.1.0 but I'm not sure if recent updates have impacted this much
    – doppler
    Commented Apr 21, 2019 at 15:30
  • @doppler thanks for your oneliner this seems to drastically simplify the use of GeoViews, however I can't seem to get around the ValueError: All value dimensions on a Contours element must be scalar
    – Tom Hemmes
    Commented Aug 12, 2019 at 14:31
  • That is pretty weird given my code does not even directly call Contours. If that is the error you get when executing the code given in my answer, you may want to check your versions are recent, and consider filing a bug report.
    – doppler
    Commented Aug 16, 2019 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.