holoviz / geoviews

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

Adding a Zoom Level feature. #208

Closed AaronV77 closed 6 years ago

AaronV77 commented 6 years ago

Hey guys,

I got messing around with the WMTS geoviews class and I see that there is no ability to pass in a zoom level for a given plot. So here is my following code:

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

# Pick a WMTS tile server
url = 'http://c.tile.openstreetmap.org/{Z}/{X}/{Y}.png'

# x_min, y_min, x_max, y_max
tiles = gv.WMTS(url, crs=ccrs.PlateCarree()).options(width=900, height=500)

# Add Austin, GeoViews Point Data Structures
#long/lat
cities = [[-97.74, 30.27]]
points = gv.Points(cities, crs=ccrs.PlateCarree())
points = points.options(tools=['hover'], size=5, color='red')

# Overlay points on tiles
tiles * points

Now this by default will zoom right into the point itself which I think is way to close, and is possibly a bug. If only one point is given I don't think it should be so close to the point by default.

So if a zoom level option was available you could increase the performance of the plot because it is not trying to get all the tiles at a zoom level of 19/24, and it adds more functionality that would be great for bounding boxes, polygons and so on. Thanks.

philippjfr commented 6 years ago

Bokeh does not provide control over the zoom level, however in the next HoloViews release we will automatically apply padding to the axes which should improve things a fair bit.

AaronV77 commented 6 years ago

Alright, so I should post this issue into Bokeh rather than GeoViews, or is this just something that will not be supported?

philippjfr commented 6 years ago

It seems unlikely that this will be supported since, at least to me, it seems incompatible with the way axis ranges are handled. Could you elaborate on the benefit of controlling the zoom level independent of the ranges of the axes? What would happen as you zoom in and out?

philippjfr commented 6 years ago

Here's what this plot will look like by default after the next HoloViews release:

screen shot 2018-07-14 at 3 24 41 pm
AaronV77 commented 6 years ago

The benefit would be that you don't have to specify a extent / bounding box to control how far the plot zooms in / out. So if I have a point in the middle of Austin Tx, and I want to see where it is from a world view then I can just say zoom_level = 0 rather than give the extent / bounding box of the whole world. It just allows the user to not have to know a given bounding box to get a certain view of their points / polygon / etc. Thanks.

philippjfr commented 6 years ago

We could probably emulate that behavior in some way by translating the zoom level to bounds internally.

jbednar commented 6 years ago

Yes, it seems like we could provide a separate utility function to translate a zoom level and a list of Elements into a bounds, and I can see how that would be useful. The list of Elements would be anything that has a location or an extent, and the function would find the total extent of all those things, take the center of that, then choose an appropriate bounds around it for the given zoom level.

But I think the way it works now is much more general, given that "zoom level" is an entirely arbitrary convention, so I'd only want that functionality to be an explicit, separate utility that can be used deliberately if someone wishes. Something like mercator_zoom_bounds()?

Given that such a utility function would be entirely independent from the rest of the HoloViews/GeoViews code, it seems like an excellent first PR for a new contributor. :-)

AaronV77 commented 6 years ago

So after taking some time of thinking about what you guys have said I completely forgot about the URL that comes from the tile source. The URL takes an X, Y, and a Z, and the z is zoom_level witch either Bokeh or something is giving this URL a z number, or the return from the tile server would be return an error.

jbednar commented 6 years ago

Not sure what you mean precisely, but yes, Bokeh is computing the appropriate zoom number in its tile source code.

AaronV77 commented 6 years ago

Sorry Jim, I was more or less thinking aloud, but after talking to Scott I now have a better understand of what you mean and how to go about implementing this utility. I'll start to look more into this. Thanks.