mapbox / robosat

Semantic segmentation on aerial and satellite imagery. Extracts features such as: buildings, parking lots, roads, water, clouds
MIT License
2.01k stars 382 forks source link

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

Open iboates opened 3 years ago

iboates commented 3 years ago

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 commented 3 years ago

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.