Skip to content

Multipolygons cause "UnboundLocalError: local variable 'x' referenced before assignment" in rs cover #217

Description

@iboates

I am just leaving this here as a note to anyone getting this error when using rs cover. If there are features in the cover GeoJSON that are of MultiPolygon type, they will throw the error in the title due to a limitation in supermercado, a dependency of robosat. Specfically, this function in "burntiles.py":

def _feature_extrema(geometry):
    if geometry["type"] == "Polygon":
        x, y = zip(*[c for part in geometry["coordinates"] for c in part])
    elif geometry["type"] == "LineString":
        x, y = zip(*[c for c in geometry["coordinates"]])
    elif geometry["type"] == "Point":
        x, y = geometry["coordinates"]
        return x, y, x, y

    return min(x), min(y), max(x), max(y)

You can get around it by making sure that your training polygons are forced to be Polygon and not MultiPolygon type before writing them to your cover CSV.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions