turf icon indicating copy to clipboard operation
turf copied to clipboard

function for oriented, not-axis-aligned envelope (minimum rotated rectangle)

Open quassy opened this issue 5 months ago • 6 comments

It would be great if Turf not only supported calculating the axis-aligned envelope (bounding box geometry) but also a not-axis-aligned envelope, for example like shapely and PostGIS do.

Image

This can naively be implemented by rotating the convex hull of a geometry, getting the axis-aligned envelope of the rotated, stopping when the envelope has a minimum area, and then rotating the axis-aligned envelope by the angle when that area was reached. But I'm sure there is a more efficient algorithm.

quassy avatar Jun 10 '25 11:06 quassy

Thanks for suggesting this @quassy. Are you interested in submitting a PR implementing this functionality?

smallsaucepan avatar Jun 10 '25 13:06 smallsaucepan

Not too familiar with TS but I will try. After some research I found this https://www.npmjs.com/package/geojson-minimum-bounding-rectangle which is actually using Turf, do you think it can serve as a base for a Turf module turf-oriented-envelope (exports orientedEnvelope)?

For attribution I need to mention @matthiasfeist in the module license file, correct?

quassy avatar Jun 10 '25 16:06 quassy

There are also other options:

  1. We could also use my module directly in Turf
  2. I'd be happy to move my source code into TurfJS and deprecate my npm module then instead.

Up to the maintainers :)

matthiasfeist avatar Jun 11 '25 05:06 matthiasfeist

Thanks for jumping in the TS deep end to put together a PR @quassy. And for those couple of usage options @matthiasfeist. Very cool to see some new functionality coming to Turf 🤩

@matthiasfeist if you're willing to incorporate your code into Turf that would be amazing.

Option 2 would probably be cleaner, mostly so we're not creating any sort of circular import. Though I wouldn't expect you to deprecate your npm presence as well. Only if you really want to.

smallsaucepan avatar Jun 11 '25 11:06 smallsaucepan

I'd be happy to incorporate my code into turfjs. But that would mean we would scrap @quassy's PR? Is that OK for you, @quassy ?

matthiasfeist avatar Jun 15 '25 08:06 matthiasfeist

I'd be happy to incorporate my code into turfjs. But that would mean we would scrap @quassy's PR?

Isn't that what my PR is already doing? I basically took your code, added a test and deduplicated it into one function with an optional parameter. Happy to work further on the PR if there is anything you think is missing or could be improved :)

quassy avatar Jun 16 '25 13:06 quassy