In [1]:
import holoviews as hv
import geoviews as gv
import param, paramnb, parambokeh
import pandas as pd
import dask.dataframe as dd
import datashader as ds
from colorcet import cm
from bokeh.models import WMTSTileSource
from holoviews.operation.datashader import datashade
from holoviews.operation import decimate
from holoviews.streams import RangeXY, PlotSize
In [2]:
hv.extension('bokeh')
In [3]:
%%time
df = dd.read_parquet('../data/crimes-2017.snappy.parq/').persist()
print(len(df))
In [4]:
df.head()
Out[4]:
In [5]:
# drop records with NaN coordinates
df = df.dropna(how='any', subset=['Latitude', 'Longitude'])
df.head()
Out[5]:
In [6]:
# plot coordinates
points = hv.Points(df, kdims=['Longitude', 'Latitude'], vdims=['PrimaryType'], label='Map')
decimate(points) # limit to 1K points max
Out[6]:
In [7]:
# create map tiles
tiles = gv.WMTS(WMTSTileSource(url='https://server.arcgisonline.com/ArcGIS/rest/services/'
'World_Imagery/MapServer/tile/{Z}/{Y}/{X}.jpg'))
In [8]:
options = dict(width=400,height=400,xaxis=None,yaxis=None,bgcolor='black',show_grid=False)
In [ ]:
#TODO
gv_dataset = gv.Dataset(df, kdims=['Longitude', 'Latitude'], vdims=['PrimaryType'])
tiles * datashade(gv_dataset,
x_sampling=10, y_sampling=10,
cmap=cm['fire'],
element_type=gv.Image, aggregator=ds.count_cat('PrimaryType')).opts(plot=options)
In [ ]:
crime_points = datashade(points,
x_sampling=1, y_sampling=1,
cmap=cm['fire'], element_type=gv.Image).opts(plot=options)
crime_points
In [ ]: