Holoviews combined with geoviews.tile_sources causes axis scale error

852 views Asked by At

I'm trying to combine a geoviews.tile_sources layer with a datashade layer. Both layers individually result in the correct axis (see image), but when combined (using *) the scale becomes distorted.

import numpy as np
import pandas as pd
import holoviews as hv
from geoviews.tile_sources import EsriImagery
from holoviews.operation.datashader import datashade

hv.extension('bokeh')

lats = np.random.uniform(51.111, 51.222, 10000)
longs = np.random.uniform(1.31, 1.33, 10000)

df = pd.DataFrame({"latitude": lats, "longitude": longs})

points = hv.Points(df, ['longitude', 'latitude'])
shader = datashade(points)

EsriImagery * shader

Incorrect axis

However, both of the individual plots are correct:

shader + EsriImagery

enter image description here

2

There are 2 answers

0
philippjfr On BEST ANSWER

HoloViews elements do no know anything about the coordinate system of your data, while tile sources are defined in a Mercator coordinate system. Therefore when you overlay hv.Points on top of a tile source it assumes your coordinates are already in Mercator coordinates. In order to overlay data situated in different coordinates systems you should therefore use the GeoViews elements, e.g. in your case gv.Points, as described in this user guide. This will ensure that your points are interpreted correctly as lat/lon pairs and can be automatically projected into the same coordinate system as the tile source.

0
James A. Bednar On

You're trying to combine a HoloViews object in PlateCarree coordinates with a GeoViews object in Web Mercator coordinates, which differ by a factor of a few million. You can fix it by changing hv.Points() to gv.Points(), which will be a GeoViews object in PlateCaree coordinates that GeoViews will project into the same coordinate system as the tile layer when it's displayed. You can also consider using gv.project_points() to do the projection a single time at the start, rather than the default of re-projecting it each time it's displayed.