robosat icon indicating copy to clipboard operation
robosat copied to clipboard

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

Open iboates opened this issue 4 years ago • 1 comments

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.

iboates avatar Mar 27 '21 14:03 iboates

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 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.

daniel-j-h avatar Mar 27 '21 19:03 daniel-j-h