-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
67687d8
Automatically convert lonlat to xy
ahuang11 aa7bc1f
revert line change
ahuang11 d3754a9
revert line change
ahuang11 2e320e0
Move within if
ahuang11 d2c6ce4
migrate into gridded
ahuang11 251ddc7
move and add gdf support
ahuang11 410e91b
add check for xarray
ahuang11 e1aebd5
Add tests and docs
ahuang11 732389e
mention tiles
ahuang11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -309,7 +309,8 @@ class HoloViewsConverter: | |
CRS object or class name, a WKT string, or a proj.4 string. | ||
Defaults to PlateCarree. | ||
tiles (default=False): | ||
Whether to overlay the plot on a tile source: | ||
Whether to overlay the plot on a tile source. If coordinate values fall within | ||
lat/lon bounds, auto-projects to EPSG:3857, unless `projection=False`. | ||
- `True`: OpenStreetMap layer | ||
- `xyzservices.TileProvider` instance (requires xyzservices to | ||
be installed) | ||
|
@@ -667,6 +668,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]): | ||
|
@@ -2092,6 +2096,40 @@ def _process_chart_args(self, data, x, y, single_y=False, categories=None): | |
not_found = [dim for dim in dimensions if dim not in self.variables] | ||
_, data = process_derived_datetime_pandas(data, not_found, self.indexes) | ||
|
||
data, x, y = self._process_tiles_without_geo(data, x, y) | ||
return data, x, y | ||
|
||
def _process_tiles_without_geo(self, data, x, y): | ||
""" | ||
Tiles without requiring geoviews/cartopy. | ||
""" | ||
if self.geo or not self.tiles or self.output_projection is False: | ||
return data, x, y | ||
elif not is_geodataframe(data) and (x is None or y is None): | ||
return data, x, y | ||
|
||
if is_geodataframe(data): | ||
if data.crs is not None: | ||
data = data.to_crs(epsg=3857) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
return data, x, y | ||
else: | ||
min_x = np.min(data[x]) | ||
max_x = np.max(data[x]) | ||
min_y = np.min(data[y]) | ||
max_y = np.max(data[y]) | ||
x_within_bounds = -180 <= min_x <= 360 and -180 <= max_x <= 360 | ||
y_within_bounds = -90 <= min_y <= 90 and -90 <= max_y <= 90 | ||
if x_within_bounds and y_within_bounds: | ||
data = data.copy() | ||
lons_180 = (data[x] + 180) % 360 - 180 # ticks are better with -180 to 180 | ||
easting, northing = lon_lat_to_easting_northing(lons_180, data[y]) | ||
new_x = 'x' if 'x' not in data else 'x_' # quick existing var check | ||
new_y = 'y' if 'y' not in data else 'y_' | ||
data[new_x] = easting | ||
data[new_y] = northing | ||
if is_xarray(data): | ||
data = data.swap_dims({x: new_x, y: new_y}) | ||
return data, new_x, new_y | ||
return data, x, y | ||
|
||
def chart(self, element, x, y, data=None): | ||
|
@@ -2622,6 +2660,7 @@ 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) | ||
|
||
data, x, y = self._process_tiles_without_geo(data, x, y) | ||
return data, x, y, z | ||
|
||
def _get_element(self, kind): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on removing this cell and only link directly to Customization geographic section to reduce redundancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep them here for now, I think it's nice to have all the options there within the appropriate context.