myoda999
myoda999

Reputation: 355

Turf bbox taking in account rotation

I have a set of polygons and I want to draw the smallest possible polygon around them (it has to be a rectangular shape, all inner angles 90 degrees). To achieve this I used the bboxPolygon function from turf.js and it works okay, but it does not take in account rotation of the polygons. For example take a look at the image bellow, the purple line is the bboxPolygon result but there is too much space at the sides, what I ultimately try to achieve is the corners should be near the topmost points of polygon 101 and bottom most of 202. Is there some other method to use to achieve this? I tried envelope but I still get the same results...

enter image description here

Upvotes: 0

Views: 809

Answers (2)

fredrbl
fredrbl

Reputation: 21

You could first rotate the rectangles using turf transformRotate(angle), so they get aligned with north/south. Then do the turf bboxPolygon, and then finally rotate them back again with transformRotate(-angle)

Upvotes: 2

Steve Bennett
Steve Bennett

Reputation: 126517

By definition, a bbox is always aligned north/south/east/west.

In this particular case, a convex hull is probably what you want. Turf supports that with the convex method.

Upvotes: 0

Related Questions