I'm working with OSM data and many of my objects are simple 4-polygons (parallelograms), which can be expressed by 4 unique corner points. But the full OSM data has the shape represented by more than 4 points, with multiple points per line segment (see image). This means that the shapes are expressed with redundant points, 16+1 in the case of this polygon:
For an arbitrary polygon, how can I find either
1 the minimum bounding (rotated) rectangle?
2 or the best fitting rectangle?
Example GeoJSON:
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"osm_id":"1269601","type":"multipolygon","leisure":"pitch","sport":"soccer"},"geometry":{"type":"Polygon","coordinates":[[[6.6131123,46.5124914],[6.6129421,46.5125385],[6.6127998,46.5125783],[6.6126291,46.512626],[6.6125308,46.5124593],[6.6127016,46.5124121],[6.6128452,46.5123724],[6.6130153,46.5123244],[6.6131123,46.5124914]]]}}]}
http://bl.ocks.org/d/465e77bb03acfd7085b2f9a1d2dd08d5
What I've tried:
ogr2ogr's
simplify
flag and the simplify() function in Shapely, which doesn't force my polygons to be 4 sided, and is also smoothening things I don't want (like corners). It's my understanding thatsimplify
won't work if the points aren't near enough to each other.Bounding Box, which gives me the smallest non-rotated rectangle that fits my polygon.