Multipolygons cause "UnboundLocalError: local variable 'x' referenced before assignment" in rs cover
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.
Thank you! ☺️
On March 27, 2021 2:40:59 PM UTC, Isaac Boates @.***> wrote:
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
MultiPolygontype, 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
Polygonand notMultiPolygontype before writing them to your cover CSV.