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

Converting LineString to Polygon? #177

Closed zoink closed 4 years ago

zoink commented 4 years ago

I'm trying to doing rs cover to generate tiles from a list of roads, where the .geojson file contains LineStrings (not Polygons).

As a result I've been running into the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/robosat/tools/__main__.py", line 58, in <module>
    args.func(args)
  File "/usr/src/app/robosat/tools/cover.py", line 32, in main
    tiles.extend(map(tuple, burntiles.burn([feature], args.zoom).tolist()))
  File "/opt/venv/lib/python3.6/site-packages/supermercado/burntiles.py", line 55, in burn
    bounds = find_extrema(polys)
  File "/opt/venv/lib/python3.6/site-packages/supermercado/burntiles.py", line 23, in find_extrema
    xMax = totalArr[:, 0].max() - epsilon
IndexError: too many indices for array

Is there some simple tool I can use to convert LineString to Polygon with some defined width? Thanks so much!

daniel-j-h commented 4 years ago

Hey,

check out how rs extract handles roads here:

https://github.com/mapbox/robosat/blob/1d0cf506cde4600ab7063c238f7f9e25d65ba611/robosat/osm/road.py

we define some heuristics for road width such as road class, number of lanes, and so on. Based on this we come up with a road width and buffer the linestring by that amount of meters:

https://github.com/mapbox/robosat/blob/1d0cf506cde4600ab7063c238f7f9e25d65ba611/robosat/osm/road.py#L140-L142

You could either just use rs extract with the road handler or use the code in that handler as inspiration to buffer your linestring geometries.

Hope that helps.