mapbox / mapbox/robosat

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

Open
#217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.1k
Forks
385
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with burntiles.py and the _feature_extrema function used by rs cover, then determine whether the limitation belongs in robosat or its supermercado dependency. Reproduce the UnboundLocalError with a MultiPolygon cover GeoJSON and verify that rs cover handles it without the error while preserving the existing Polygon behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.