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

Handle wkt format #1092

Merged
merged 3 commits into from
Sep 19, 2023
Merged

Handle wkt format #1092

merged 3 commits into from
Sep 19, 2023

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Jun 21, 2023

I noticed this code would not work:

import hvplot.xarray
import rioxarray as rxr

# Downloaded from: https://oin-hotosm.s3.amazonaws.com/5d7dad0becaf880008a9bc88/0/5d7dad0becaf880008a9bc89.tif
cog_url = "/home/shh/Downloads/5d7dad0becaf880008a9bc89.tif"
da = rxr.open_rasterio(cog_url)
plot = da.hvplot.rgb(x="x", y="y", rasterize=True, tiles=True, crs=3857)
plot

And would give the following traceback:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Exception: It does not make sense to provide both "scale_factor" and "latitude_true_scale". 

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
File ~/Repos/holoviz/hvplot/hvplot/converter.py:662, in HoloViewsConverter._process_crs(self, data, crs)
    661 try:
--> 662     return process_crs(_crs)
    663 except ValueError:
    664     # only raise error if crs was specified in kwargs

File ~/Repos/holoviz/hvplot/hvplot/util.py:274, in process_crs(crs)
    272     return crs
--> 274 raise ValueError("Projection must be defined as a EPSG code, proj4 string, cartopy CRS or pyproj.Proj.") from Exception(*errors)

ValueError: Projection must be defined as a EPSG code, proj4 string, cartopy CRS or pyproj.Proj.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Cell In[1], line 8
      5 cog_url = "/home/shh/Downloads/5d7dad0becaf880008a9bc89.tif"
      7 da = rxr.open_rasterio(cog_url)
----> 8 plot = da.hvplot.rgb(x="x", y="y", rasterize=True, tiles=True, crs=3857)
      9 plot

File ~/Repos/holoviz/hvplot/hvplot/plotting/core.py:2016, in hvPlot.rgb(self, x, y, z, bands, **kwds)
   2014 if bands is not None:
   2015     kwds["bands"] = bands
-> 2016 return self(x, y, z=z, kind="rgb", **kwds)

File ~/Repos/holoviz/hvplot/hvplot/plotting/core.py:92, in hvPlotBase.__call__(self, x, y, kind, **kwds)
     89         plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
     90         return pn.panel(plot, **panel_dict)
---> 92 return self._get_converter(x, y, kind, **kwds)(kind, x, y)

File ~/Repos/holoviz/hvplot/hvplot/plotting/core.py:99, in hvPlotBase._get_converter(self, x, y, kind, **kwds)
     97 y = y or params.pop("y", None)
     98 kind = kind or params.pop("kind", None)
---> 99 return HoloViewsConverter(self._data, x, y, kind=kind, **params)

File ~/Repos/holoviz/hvplot/hvplot/converter.py:401, in HoloViewsConverter.__init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, symmetric, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, datashade, rasterize, row, col, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, tools, attr_labels, coastline, tiles, sort_date, check_symmetric_max, transforms, stream, cnorm, features, rescale_discrete_levels, **kwds)
    399 self.dynamic = dynamic
    400 self.geo = any([geo, crs, global_extent, projection, project, coastline, features])
--> 401 self.crs = self._process_crs(data, crs) if self.geo else None
    402 self.project = project
    403 self.coastline = coastline

File ~/Repos/holoviz/hvplot/hvplot/converter.py:666, in HoloViewsConverter._process_crs(self, data, crs)
    663 except ValueError:
    664     # only raise error if crs was specified in kwargs
    665     if crs:
--> 666         raise ValueError(
    667             "'{}' must be either a valid crs or an reference to "
    668             "a `data.attr` containing a valid crs.".format(crs))

ValueError: '3857' must be either a valid crs or an reference to a `data.attr` containing a valid crs.

@@ -117,7 +117,6 @@ def proj_to_cartopy(proj):
a cartopy.crs.Projection object
"""

import cartopy
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flake8 did not like this line.

@ahuang11
Copy link
Collaborator

ahuang11 commented Jul 14, 2023

This is cool! I'd use this; I found import cartopy.crs as ccrs tedious every time I needed a non ccrs.PlateCarree crs.

By the way, does this support projection=3857 too?

It'd also be cool to support crs="Mercator" or projection="Robinson"

@hoxbro
Copy link
Member Author

hoxbro commented Jul 14, 2023

By the way, does this support projection=3857 too?

No. Not right now. I don't know if there is a technical reason for this.

It'd also be cool to support crs="Mercator" or projection="Robinson"

This seems to work already.

image

@maximlt maximlt added this to the 0.9.0 milestone Sep 11, 2023
@hoxbro hoxbro merged commit 96e0a43 into main Sep 19, 2023
7 checks passed
@hoxbro hoxbro deleted the old_wkt_crs branch September 19, 2023 16:41
ahuang11 pushed a commit that referenced this pull request Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants