Skip to content

bgc_data_processing.utils.convert_polygons

Functions to convert a shaeply Polygon to list of nodes.

polygon_to_list(polygon)

Convert polygon from shapely to list of coordinates.

Parameters:

Name Type Description Default
polygon Polygon

Polygon to convert.

required

Returns:

Type Description
Tuple[list, list]

List of longitude values, list of latitude values.

Source code in src/bgc_data_processing/utils/convert_polygons.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def polygon_to_list(polygon: "Polygon") -> tuple[list, list]:
    """Convert polygon from shapely to list of coordinates.

    Parameters
    ----------
    polygon : Polygon
        Polygon to convert.

    Returns
    -------
    Tuple[list, list]
        List of longitude values, list of latitude values.
    """
    x_raw, y_raw = polygon.exterior.coords.xy
    x = list(x_raw)
    y = list(y_raw)
    return x, y