hvplot(geo=True) argument maps XY coordinates to incorrect latitude coordinates

221 Views Asked by At

I have a raster of the Northern beaches, Australia, in the UTM CRS projection for this region (56S). Now when I'm plotting this data using the hvplot.xarray extension as da.hvplot(x="x", y="y", geo=True), the argument geo=True triggers y coordinates [meters] to be converted to coordinates [lon, lat], but the latitudes are mapped as northern hemisphere coordinates. They become lat = 90 + (-y), whereas it should simply be lat = -y. Which function is triggered by geo=True that infers the coordinates from XY to lon/lat?

Plotting with matplotlib works fine, see: https://i.stack.imgur.com/zRC68.png

Aim

Overal objective is to overlay the vector data (shoreline) on top of the raster (ndwi).

Some software version

python==3.10.8

hvplot.__version__  # '0.8.2'
holoviews.__version__  # 1.15.3

Complete, minimal, self-contained example code that reproduces the issue

import cartopy.crs as ccrs
import geopandas as gpd
import geoviews as gv
import geoviews.tile_sources as gts
import holoviews as hv
import hvplot.xarray
import xarray as xr

ndwi = xr.open_dataset(
    "https://s3.eu-central-1.amazonaws.com/floris.calkoen.open.data/narrabeen_ndwi_2023-01-24T00%3A02%3A21.tif",
    engine="rasterio",
)
shoreline = gpd.read_file(
    "https://s3.eu-central-1.amazonaws.com/floris.calkoen.open.data/narrabeen_shoreline_2023-01-24T00%3A02%3A21.geojson"
)

ndwi.rio.crs == shoreline.crs  ## true

utm_zone = shoreline.crs.utm_zone
southern_hemisphere = True if utm_zone[-1] == "S" else False
utm_code = int(utm_zone[:-1])
utm_crs = ccrs.UTM(
    utm_code, southern_hemisphere
)  # why cartopy.crs.UTM() doesn't handle utm zone strings?

shoreline_plot = gv.Path([shoreline], crs=utm_crs)
ndwi_plot = ndwi["band_data"].squeeze().hvplot(x="x", y="y", geo=True, crs=utm_crs)

shoreline_plot * gts.EsriImagery  # this seems correct 

ndwi_plot # see how the XY coordinates are converted from XY UTM zone 56S to latitudes in the northern hemisphere (90 + (-y)) 

shoreline_plot * ndwi_plot  # therefore the overlay doesn't work

# to plot with matplotblib
fig, ax = plt.subplots()
ndwi["band_data"].squeeze().plot(ax=ax)
shoreline.plot(ax=ax, color='black', linewidth=5, label="shoreline")
plt.legend()
plt.show()

0

There are 0 best solutions below