How to set starting zoom level in EsriImagery with datashader and bokeh?

402 Views Asked by At

I want to project a map with its starting position like this

what i want

The current output that I get is like this

what I get

import holoviews as hv
from geoviews.tile_sources import EsriImagery
from holoviews.operation.datashader import datashade, dynspread
import datashader as ds
import colorcet as cc

hv.extension('bokeh', 'matplotlib')

c = df.loc[(df['dropoff_latitude'] >= 40.5) &
           (df['dropoff_latitude'] <= 41) &
           (df['dropoff_longitude'] >= -74.1) &
           (df['dropoff_longitude'] <= -73.7)]

map_tiles  = EsriImagery().opts(alpha=0.5, width=900, height=480, bgcolor='black')
points = hv.Points(ds.utils.lnglat_to_meters(c['dropoff_longitude'], c['dropoff_latitude']))
taxi_trips = datashade(points, dynamic = True, x_sampling=0.1, y_sampling=0.1, cmap=cc.fire, height=1000, width=1000)

map_tiles * taxi_trips

I tried to set a zoom_level or xrange, yrange in EsriImagery opts, but there are no such parameters. The method itself also has no documentation. And I couldn't find the documentation regrading this online too. (I could be looking at the wrong place.)

1

There are 1 best solutions below

0
On

There are two ways to do this:

Option 1 -- dircet input

Set your wanted values using the parameter x_range and y_range in datashade(...).

taxi_trips = datashade(points, x_range=(-8250000,-8200000))

Option 2 -- indirect input

If you don't know the needed values and you want to play around a bit, you can use this workaround.

The existing figure object has a Range1d object, and this has a start and end point. This can be printed and set by a user.

This code starts with the last line of your example.

from bokeh.plotting import show

fig = hv.render(map_tiles * taxi_trips)
fig.x_range.start = -8250000
fig.x_range.end = -8200000
# fig.x_range.reset_start = -8250000
# fig.x_range.reset_end = -8200000
# the same for the y-axis
show(fig)

Here you have to get the bokeh (underlying package) figure and set your values. This values looks a bit odd and you maybe have to play a bit with it.

Output for both options

Here is the changed output.

changed zoom

I hope this works for you. Good luke.