xyzspaces.utils module

This is a collection of utilities for using XYZ Hub.

Actually, they are almost unspecific to any XYZ Hub functionality, apart from feature_to_bbox(), but convenient to use.

xyzspaces.utils.join_string_lists(**kwargs)[source]

Convert named lists of strings to one dict with comma-separated strings.

Parameters

kwargs – Lists of strings

Returns

Converted dict.

Return type

dict

Example:

>>> join_string_lists(foo=["a", "b", "c"], bar=["a", "b"], foobar=None)
{"foo": "a,b,c", "bar": "a,b"}
xyzspaces.utils.feature_to_bbox(feature)[source]

Extract bounding box from GeoJSON feature rectangle.

Parameters

feature (dict) – A dict representing a GeoJSON feature.

Returns

A list of four floats representing West, South, East and North margins of the resulting bounding box.

Return type

List[float]

xyzspaces.utils.get_xyz_token()[source]

Read and return the value of the environment variable XYZ_TOKEN.

Returns

The string value of the environment variable or an empty string if no such variable could be found.

Return type

str

xyzspaces.utils.grouper(size, iterable, fillvalue=None)[source]

Create groups of size each from given iterable.

Parameters
  • size – An int representing size of each group.

  • iterable – An iterable.

  • fillvalue – Value to put for the last group.

Returns

A generator.

xyzspaces.utils.wkt_to_geojson(wkt_data)[source]

Converts wkt to geojson

Parameters

wkt_data (str) – wkt data to be converted

Returns

Geojson

Return type

dict

xyzspaces.utils.grid(bbox, cell_width, cell_height, units)[source]

This function generates the grids for the given bounding box

Parameters
  • bbox – bounding box coordinates

  • cell_width – Cell width in specified in units

  • cell_height – Cell height in specified in units

  • units – Units for given sizes

Returns

FeatureCollection of grid boxes genarated for the giving bounding box

xyzspaces.utils.divide_bbox(feature, cell_width=None, units='m')[source]

Divides the given feature into grid boxes as per given cell width

Parameters
  • feature (dict) – Feature to be divide in grid

  • cell_width (Optional[float]) – Width of each grid boxs

  • units (Optional[str]) – Units for the width of grid boxs

Returns

List of features in which the input feature is divided

xyzspaces.utils.flatten_geometry(data)[source]

Flatten the geometries in the given GeoPandas dataframe. Flatten geometry is formed by extracting individual geometries from GeometryCollection, MultiPoint, MultiLineString, MultiPolygon.

Parameters

data (gpd.GeoDataFrame) – GeoPandas dataframe to be flatten

Returns

Flat GeoPandas dataframe

Return type

gpd.GeoDataFrame