earthdaily.earthdatastore.cube_utils package

Subpackages

Submodules

Module contents

class earthdaily.earthdatastore.cube_utils.GeometryManager(geometry)[source]

Bases: object

A class to manage and convert various types of geometries into different formats.

Parameters:

geometry (various types) – Input geometry, can be GeoDataFrame, GeoSeries, WKT string, or GeoJSON.

geometry

The input geometry provided by the user.

Type:

various types

_obj

The geometry converted into a GeoDataFrame.

Type:

GeoDataFrame

input_type

Type of input geometry inferred during processing.

Type:

str

__call__():

Returns the stored GeoDataFrame.

to_intersects(crs='EPSG:4326'):

Converts geometry to GeoJSON intersects format with a specified CRS.

to_wkt(crs='EPSG:4326'):

Converts geometry to WKT format with a specified CRS.

to_json(crs='EPSG:4326'):

Converts geometry to GeoJSON format with a specified CRS.

to_geopandas():

Returns the GeoDataFrame of the input geometry.

to_bbox(crs='EPSG:4326'):

Returns the bounding box of the geometry with a specified CRS.

buffer_in_meter(distance, crs_meters='EPSG:3857', \*\*kwargs):

Applies a buffer in meters to the geometry and returns it with the original CRS.

buffer_in_meter(distance: int, crs_meters: str = 'EPSG:3857', **kwargs)[source]

Applies a buffer in meters to the geometry and returns it with the original CRS.

Parameters:
  • distance (int) – The buffer distance in meters.

  • crs_meters (str, optional) – The CRS to use for calculating the buffer (default is EPSG:3857).

  • **kwargs (dict, optional) – Additional keyword arguments to pass to the buffer method.

Returns:

The buffered geometry in the original CRS.

Return type:

GeoSeries

to_bbox(crs='EPSG:4326')[source]

Returns the bounding box of the geometry.

Parameters:

crs (str, optional) – The CRS to convert to (default is EPSG:4326).

Returns:

The bounding box as an array [minx, miny, maxx, maxy].

Return type:

numpy.ndarray

to_geopandas()[source]

Converts the input geometry to a GeoDataFrame.

Returns:

The input geometry as a GeoDataFrame.

Return type:

GeoDataFrame

to_intersects(crs='EPSG:4326')[source]

Converts the geometry to GeoJSON intersects format.

Parameters:

crs (str, optional) – The coordinate reference system (CRS) to convert to (default is EPSG:4326).

Returns:

The geometry in GeoJSON intersects format.

Return type:

dict

to_json(crs='EPSG:4326')[source]

Converts the geometry to GeoJSON format.

Parameters:

crs (str, optional) – The CRS to convert to (default is EPSG:4326).

Returns:

The geometry in GeoJSON format.

Return type:

dict

to_wkt(crs='EPSG:4326')[source]

Converts the geometry to WKT format.

Parameters:

crs (str, optional) – The CRS to convert to (default is EPSG:4326).

Returns:

The geometry in WKT format. If there is only one geometry, a single WKT string is returned; otherwise, a list of WKT strings.

Return type:

str or list of str

earthdaily.earthdatastore.cube_utils.zonal_stats(dataset: Dataset, geoms, method: str = 'numpy', smart_load: bool = False, memory: int = None, reducers: list = ['mean'], all_touched=True, label=None, buffer_meters: int | float | None = None, **kwargs)[source]

Xr Zonal stats using np.nan functions.

Parameters:
  • dataset (xr.Dataset) – DESCRIPTION.

  • geoms (TYPE) – DESCRIPTION.

  • method (str) – “xvec” or “numpy”. The default is “numpy”.

  • smart_load (bool) – Will load in memory the maximum of time and loop on it for “numpy” method. The default is False.

  • memory (int, optional) – Only for the “numpy” method, by default it will take the maximum memory available. But in some cases it can be too much or too little. The default is None.

  • reducers (list, optional) – Any np.nan function (“mean” is “np.nanmean”). The default is [‘mean’].

Yields:

zs (TYPE) – DESCRIPTION.