Skip to content

sarlo.geo

Common geospatial data processing operations for working with radar data

center_polygon(polygon_text)

Converts polygon text to center coordinates

Parameters:

Name Type Description Default
polygon_text str

MULTIPOLYGON (((-121.857719 38.099609, -119.010895 38.493401, -119.345619 40.112171, -122.261093 39.719498, -121.857719 38.099609)))

required

Returns:

Type Description
[x, y]

center point of polygon

Source code in sarlo/geo.py
def center_polygon(polygon_text: str):
    """Converts polygon text to center coordinates

    Args:
        polygon_text: MULTIPOLYGON (((-121.857719 38.099609, -119.010895 38.493401, -119.345619 40.112171, -122.261093 39.719498, -121.857719 38.099609)))

    Return:
        [x, y]: center point of polygon
    """
    Poly = shapely.wkt.loads(polygon_text)
    my_feature = geojson.Feature(geometry=Poly.centroid)
    center = list(geojson.utils.coords(my_feature))
    for x, y in center:
        x = x
        y = y
    return [x, y]

write_polygon_geojson(lonMin, lonMax, latMin, latMax)

Write polygon from lat lon boundaries

Parameters:

Name Type Description Default
lonMin int

x or longitude minimum

required
lonMax int

x or longitude maximum

required
latMin int

y or latitude minimum

required
latMax int

y or latitude maximum

required

Returns:

Type Description

None. writes geojson to directory

Source code in sarlo/geo.py
def write_polygon_geojson(lonMin: int, lonMax: int, latMin: int, latMax: int):
    """Write polygon from lat lon boundaries

    Args:
        lonMin: x or longitude minimum
        lonMax: x or longitude maximum
        latMin: y or latitude minimum
        latMax: y or latitude maximum

    Return:
        None. writes geojson to directory
    """
    geom_in_geojson = geojson.Polygon(
        [
            [
                [lonMin, latMax],
                [lonMin, latMin],
                [lonMax, latMin],
                [lonMax, latMax],
                [lonMin, latMax],
            ]
        ]
    )
    tmp_file = tempfile.mkstemp(suffix=".geojson")
    with open(tmp_file[1], "w") as outfile:
        geojson.dump(geom_in_geojson, outfile)
    return tmp_file[1]
Back to top