Multipolygons cause "UnboundLocalError: local variable 'x' referenced before assignment" in rs cover
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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