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.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:
- da
xarray.DataArray
DataArray to convert to element
- crs
Cartopy
CRS
orEPSG
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
- da
- 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_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_source
WMTS
element
orpython:str
URL
The tile source to download the tiles from.
- bbox
python:tuple
A four tuple specifying the (left, bottom, right, top) corners of the domain to download the tiles for.
- zoom_level
python:int
The zoom level at which to download the tiles
- bbox_crs
ccrs.CRs
cartopy CRS defining the coordinate system of the supplied bbox
- tile_source
- 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:
EPSG codes : Defined as string of the form “EPSG: {code}” or an integer
proj.4 string : Defined as string of the form “{proj.4 string}”
cartopy.crs.CRS instance
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:
- proj
pyproj.Proj
the projection to convert
- proj
- Returns:
a
cartopy.crs.Projection
object
- geoviews.util.unpack_geoms(geom_el)[source]#
Unpacks the data in a geometry element if it is already in a geometry format.