def from_xarray(da, crs=None, apply_transform=False, nan_nodata=False, **kwargs):
if crs:<EOL><INDENT>kwargs['<STR_LIT>'] = crs<EOL><DEDENT>elif hasattr(da, '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>kwargs['<STR_LIT>'] = process_crs(da.crs)<EOL><DEDENT>except:<EOL><INDENT>param.main.warning('<STR_LIT>'<EOL>'<STR_LIT>' % da.crs)<EOL><DEDENT><DEDENT>coords = list(da.coords)<EOL>if coords not in (['<STR_LIT>', '<STR_LIT:y>', '<STR_LIT:x>'], ['<STR_LIT:y>', '<STR_LIT:x>']):<EOL><INDENT>from .element.geo import Dataset, HvDataset<EOL>el = Dataset if '<STR_LIT>' in kwargs else HvDataset<EOL>return el(da, **kwargs)<EOL><DEDENT>if len(coords) == <NUM_LIT:2>:<EOL><INDENT>y, x = coords<EOL>bands = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>y, x = coords[<NUM_LIT:1>:]<EOL>bands = len(da.coords[coords[<NUM_LIT:0>]])<EOL><DEDENT>if apply_transform:<EOL><INDENT>from affine import Affine<EOL>transform = Affine.from_gdal(*da.attrs['<STR_LIT>'][:<NUM_LIT:6>])<EOL>nx, ny = da.sizes[x], da.sizes[y]<EOL>xs, ys = np.meshgrid(np.arange(nx)+<NUM_LIT:0.5>, np.arange(ny)+<NUM_LIT:0.5>) * transform<EOL>data = (xs, ys)<EOL><DEDENT>else:<EOL><INDENT>xres, yres = da.attrs['<STR_LIT>'] if '<STR_LIT>' in da.attrs else (<NUM_LIT:1>, <NUM_LIT:1>)<EOL>xs = da.coords[x][::-<NUM_LIT:1>] if xres < <NUM_LIT:0> else da.coords[x]<EOL>ys = da.coords[y][::-<NUM_LIT:1>] if yres < <NUM_LIT:0> else da.coords[y]<EOL><DEDENT>data = (xs, ys)<EOL>for b in range(bands):<EOL><INDENT>values = da[b].values<EOL>if nan_nodata and da.attrs.get('<STR_LIT>', []):<EOL><INDENT>values = values.astype(float)<EOL>for d in da.attrs['<STR_LIT>']:<EOL><INDENT>values[values==d] = np.NaN<EOL><DEDENT><DEDENT>data += (values,)<EOL><DEDENT>if '<STR_LIT>' not in kwargs:<EOL><INDENT>kwargs['<STR_LIT>'] = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT:image>']<EOL><DEDENT>if xs.ndim > <NUM_LIT:1>:<EOL><INDENT>from .element.geo import QuadMesh, HvQuadMesh<EOL>el = QuadMesh if '<STR_LIT>' in kwargs else HvQuadMesh<EOL>el = el(data, [x, y], **kwargs)<EOL><DEDENT>elif bands < <NUM_LIT:3>:<EOL><INDENT>from .element.geo import Image, HvImage<EOL>el = Image if '<STR_LIT>' in kwargs else HvImage<EOL>el = el(data, [x, y], **kwargs)<EOL><DEDENT>else:<EOL><INDENT>from .element.geo import RGB, HvRGB<EOL>el = RGB if '<STR_LIT>' in kwargs else HvRGB<EOL>vdims = el.vdims[:bands]<EOL>el = el(data, [x, y], vdims, **kwargs)<EOL><DEDENT>if hasattr(el.data, '<STR_LIT>'):<EOL><INDENT>el.data.attrs = da.attrs<EOL><DEDENT>return el<EOL>
Returns an RGB or Image element given an xarray DataArray
loaded using xr.open_rasterio.

If a crs attribute is present on the loaded data it will
attempt to decode it into a cartopy projection otherwise it
will default to a non-geographic HoloViews element.

Parameters
----------
da: xarray.DataArray
  DataArray to convert to element
crs: Cartopy CRS or EPSG string (optional)
  Overrides CRS inferred from the data
apply_transform: boolean
  Whether to apply affine transform if defined on the data
nan_nodata: boolean
  If data contains nodata values convert them to NaNs
**kwargs:
  Keyword arguments passed to the HoloViews/GeoViews element

Returns
-------
element: Image/RGB/QuadMesh element