holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
592 stars 76 forks source link

Differences between gv.Dataset and hv.Dataset #314

Open poplarShift opened 5 years ago

poplarShift commented 5 years ago

Why does this code work with hv.Dataset but not gv.Dataset?

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')

gv.Polygons(world, vdims='pop_est')
hv.Dataset(world, kdims=['Longitude', 'Latitude', 'continent'], vdims='pop_est').to(gv.Polygons)
jbednar commented 5 years ago

hv and gv differ in their assumptions about coordinate systems. Specifically, hv doesn't declare any coordinate information at all, which is fine if your data is already in the coordinate system you will use to display it, but otherwise problematic. gv assumes that your data is in lat, lon unless otherwise specified, and will convert the coordinate system as needed. So maybe you need to declare an explicit non-lat,lon coordinate system for gv?

poplarShift commented 5 years ago

Well, that is a bit confusing given that the dataframe above has a geometry column, not explicit lon/lat coordinates, but still using hv.Dataset achieves exactly what I want, while the "native" geoviews version doesn't even accept the input.

jbednar commented 5 years ago

The shapes in the geometry column will be in some coordinate system, which should presumably be specified. I don't know whether that's the issue here, but just pointing that out...

poplarShift commented 5 years ago

Thanks, specifying the crs= kwarg didn't help, but then again the error being thrown is a KeyError about Longitude missing.

denson commented 5 years ago

It appears that the polygons are not being properly converted to individual points by either Holoviews are Geoviews. I can create datasets in either but when I do .to.table() there is missing data which increases each time I sort the table by clicking.

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')

print(gv.__version__)
print(hv.__version__)
print(gpd.__version__)

1.6.2 1.12.3 0.4.1

ds_world = hv.Dataset(world, kdims=['Longitude', 'Latitude', 'continent'], vdims='pop_est')
ds_world.to.table()

BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('Latitude', 10859), ('Longitude', 10859), ('continent', 10750), ('pop_est', 10750)

gv_dataset = gv.Dataset(world, vdims='pop_est')

gv_dataset.table()

BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('Latitude', 10859), ('Longitude', 10859), ('pop_est', 10750)

No clicks:

no_clicks

First click:

first_click

Second click:

two_clicks

Three clicks:

three_clicks

Bunch of clicks:

bunch_of_clicks