geoviews.util module#

geoviews.util.asarray(v)[source]#

Convert input to array

First it tries with a normal np.asarray(v) if this does not work it tries with np.asarray(v, dtype=object).

The ValueError raised is because of an inhomogeneous shape of the input, which raises an error in numpy v1.24 and above.

geoviews.util.check_crs(crs)[source]#

Checks if the crs represents a valid grid, projection or ESPG string.

(Code copied from fmaussion/salem)

Returns:
A valid crs if possible, otherwise python:None

Examples

>>> p = check_crs('+units=m +init=epsg:26915')
>>> p.srs
'+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs'
>>> p = check_crs('wrong')
>>> p is None
True
geoviews.util.expand_geoms(geoms)[source]#

Expands multi-part geometries in a list of geometries.

geoviews.util.from_xarray(da, crs=None, apply_transform=False, nan_nodata=False, **kwargs)[source]#

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:
daxarray.DataArray

DataArray to convert to element

crsCartopy CRS or EPSG python:str, optional

Overrides CRS inferred from the data

apply_transformbool

Whether to apply affine transform if defined on the data

nan_nodatabool

If data contains nodata values convert them to NaNs

**kwargs

Keyword arguments passed to the HoloViews/GeoViews element

Returns:
element

Image/RGB/QuadMesh element

geoviews.util.geo_mesh(element)[source]#

Get mesh data from a 2D Element ensuring that if the data is on a cylindrical coordinate system and wraps globally that data actually wraps around.

geoviews.util.geom_dict_to_array_dict(geom_dict, coord_names=None)[source]#

Converts a dictionary containing an geometry key to a dictionary of x- and y-coordinate arrays and if present a list-of-lists of hole array.

geoviews.util.geom_length(geom)[source]#

Calculates the length of coordinates in a shapely geometry.

geoviews.util.geom_to_arr(geom)[source]#

LineString, LinearRing and Polygon (exterior only?)

geoviews.util.geom_to_array(geom)[source]#

Convert the coords of a shapely Geometry to a numpy array.

geoviews.util.get_tile_rgb(tile_source, bbox, zoom_level, bbox_crs=None)[source]#

Returns an RGB element given a tile_source, bounding box and zoom level.

Parameters:
tile_sourceWMTS element or python:str URL

The tile source to download the tiles from.

bboxpython:tuple

A four tuple specifying the (left, bottom, right, top) corners of the domain to download the tiles for.

zoom_levelpython:int

The zoom level at which to download the tiles

bbox_crsccrs.CRs

cartopy CRS defining the coordinate system of the supplied bbox

Returns:
RGB element containing the tile data in the specified bbox
geoviews.util.is_multi_geometry(geom)[source]#

Whether the shapely geometry is a Multi or Collection type.

geoviews.util.path_to_geom_dicts(fullpath, skip_invalid=True)[source]#

Converts a Path element into a list of geometry dictionaries, preserving all value dimensions.

geoviews.util.polygons_to_geom_dicts(polygons, skip_invalid=True)[source]#

Converts a Polygons element into a list of geometry dictionaries, preserving all value dimensions.

For array conversion the following conventions are applied:

  • Any nan separated array are converted into a MultiPolygon

  • Any array without nans is converted to a Polygon

  • If there are holes associated with a nan separated array the holes are assigned to the polygons by testing for an intersection

  • If any single array does not have at least three coordinates it is skipped by default

  • If skip_invalid=False and an array has less than three coordinates it will be converted to a LineString

geoviews.util.process_crs(crs)[source]#

Parses cartopy CRS definitions defined in one of a few formats:

  1. EPSG codes : Defined as string of the form “EPSG: {code}” or an integer

  2. proj.4 string : Defined as string of the form “{proj.4 string}”

  3. cartopy.crs.CRS instance

  4. None defaults to crs.PlateCaree

geoviews.util.proj_to_cartopy(proj)[source]#

Converts a pyproj.Proj to a cartopy.crs.Projection

(Code copied from fmaussion/salem)

Parameters:
projpyproj.Proj

the projection to convert

Returns:
a cartopy.crs.Projection object
geoviews.util.to_ccw(geom)[source]#

Reorients polygon to be wound counter-clockwise.

geoviews.util.unpack_geoms(geom_el)[source]#

Unpacks the data in a geometry element if it is already in a geometry format.

geoviews.util.wrap_lons(lons, base, period)[source]#

Wrap longitude values into the range between base and base+period.

geoviews.util.zoom_level(bounds, width, height)[source]#

Compute zoom level given bounds and the plot size.