Skip to content

How to get epsg or proj crs? #49

@rsignell-usgs

Description

@rsignell-usgs

I'm trying to use rioxarray.open_rasterio to create an xarray dataarray from a COG and then use hvplot to visualize it, which takes a Cartopy crs argument.

This is a bit embarrassing but I can't figure out how to obtain a crs proj or epsg code from rioxarray.open_rasterio.

If I use xarray.open_rasterio I have .crs, which gives me the proj or epsg code, but with rioxarray.open_rasterio I see spatial_ref, which contains wkt.

Example:

# from https://openaerialmap.org/
cog_url = (
    "https://oin-hotosm.s3.amazonaws.com/"
    "5d7dad0becaf880008a9bc88/0/5d7dad0becaf880008a9bc89.tif"
)
import xarray as xr
xr.open_rasterio(cog_url).crs

yields:

'+init=epsg:3857'

But rioxarray:

import rioxarray as rx
rioxarray.open_rasterio(cog_url).spatial_ref

yields:

<xarray.DataArray 'spatial_ref' ()>
array(0)
Coordinates:
    spatial_ref  int64 0
Attributes:
    spatial_ref:  PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WG...
    crs_wkt:      PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WG...

I think I'm definitely missing something here. 😕

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions