Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically convert lonlat to xy when tiles=True #1377

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from holoviews.plotting.util import process_cmap
from holoviews.operation import histogram, apply_when
from holoviews.streams import Buffer, Pipe
from holoviews.util.transform import dim
from holoviews.util.transform import dim, lon_lat_to_easting_northing
from pandas import DatetimeIndex, MultiIndex

from .backend_transforms import _transfer_opts_cur_backend
Expand Down Expand Up @@ -667,6 +667,9 @@ def __init__(
xlim = (x0, x1)
if ylim:
ylim = (y0, y1)
elif projection is False:
# to disable automatic projection of tiles
self.output_projection = projection

# Operations
if resample_when is not None and not any([rasterize, datashade, downsample]):
Expand Down Expand Up @@ -2622,6 +2625,33 @@ def _process_gridded_args(self, data, x, y, z):
not_found = [dim for dim in dimensions if dim not in self.variables]
_, data = process_derived_datetime_pandas(data, not_found, self.indexes)

print(self.tiles, self.output_projection)
if self.tiles and self.output_projection is not False:
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved
# tiles without requiring geoviews/cartopy
# check if between -180 and 360 and lat between -90 and 90
_hover_code = """
const projections = Bokeh.require("core/util/projections");
const {snap_x, snap_y} = special_vars
const coords = projections.wgs84_mercator.invert(snap_x, snap_y)
return "" + (coords[%d]).toFixed(4)
"""
min_x = np.min(data[self.x])
max_x = np.max(data[self.x])
min_y = np.min(data[self.y])
max_y = np.max(data[self.y])
if -180 < min_x < 360 and -180 < max_x < 360 and -90 < min_y < 90 and -90 < max_y < 90:
data = data.copy()
lons, lats = data[x], data[y]
lons = (lons + 180) % 360 - 180 # ticks are better with -180 to 180
easting, northing = lon_lat_to_easting_northing(lons, lats)
x, y = 'x', 'y'
if x in data:
x = x + '_'
if y in data:
y = y + '_'
data[x] = easting
data[y] = northing
data = data.swap_dims({self.x: x, self.y: y})
return data, x, y, z

def _get_element(self, kind):
Expand Down
Loading