Skip to main content
Solved

How to create Bounding Box with 5-8 vertex?


wind

Hello,

I need to create a bounding box with 5-8 vertex for my polygones. The BoundingBoxReplacer has 4 vertex only. I tried the HullReplacer, but it creates too many vertex - 10-20. But need only 5-8 vertes around my polygone.

Do you have an idea?

Thank you anyway.

Regards

image

Best answer by geomancer

There certainly seems to be a way for polygons like the one in your image, consisting of a number of long segments and a number of (often grouped) short segments. Remove the short segments, calculate the intersection points of the remaining segments and their neighbours. The intersection points span a convex polygon that completely contains the original polygon, and has fewer vertices.

Hull_cornerUnfortunately this algorithm does not work for all convex polygons. When removing all short segments, there may be too few segments remaining, or a pair of remaining segments may intersect on the wrong side, or the removal of all short segments may lead to an intersection point very distant from the original polygon.

Hull_Distant_Intersection_PointIn cases like this you will get better results by keeping some short segments.

Hull_Use_Some_Short_SegmentsThe attached workspace does all this. For simplicity I have chosen to determine which short segments to keep by simply looking at the number of consecutive short segments, and the maximum number of short segments to skip. There may be better ways, but this was simple to implement.

The workspace contains some sample convex polygons to simplify.

Click the custom transformer ConvexPolygonSimplifier, set the parameters (Minimum Length = 14, Maximum Number of Short Segments to Skip = 4), then run the workspace. Also look what happens when you set parameter Maximum Number of Short Segments to Skip to 0.

 

Please don't expect this custom transformer to be faultless. But I hope it will give you some inspiration, when you look into its inner workings. Good luck!

View original
Did this help you find an answer to your question?

7 replies

drc43
Contributor
Forum|alt.badge.img+11
  • Contributor
  • December 7, 2021

Hi @wind​ ,

I would try using a Generalizer transformer after the HullReplacer to reduce the number of vertexes. You may have to play around with the tolerance value to get the results you want. I would suggest starting with something between 10-20 and go from there.


redgeographics
Celebrity
Forum|alt.badge.img+50
drc43 wrote:

Hi @wind​ ,

I would try using a Generalizer transformer after the HullReplacer to reduce the number of vertexes. You may have to play around with the tolerance value to get the results you want. I would suggest starting with something between 10-20 and go from there.

Do keep in mind that this way there is a chance of parts of the original polygon falling outside of the generalized hull.


wind
  • Author
  • December 10, 2021

Exact, always too many vertex but some of parts of the original polygon falling outside of the generalized hull. I realy need a bounding box with all vertex of the original polygone inside.

Thank you very much anyway!


geomancer
Evangelist
Forum|alt.badge.img+50
  • Evangelist
  • Best Answer
  • December 15, 2021

There certainly seems to be a way for polygons like the one in your image, consisting of a number of long segments and a number of (often grouped) short segments. Remove the short segments, calculate the intersection points of the remaining segments and their neighbours. The intersection points span a convex polygon that completely contains the original polygon, and has fewer vertices.

Hull_cornerUnfortunately this algorithm does not work for all convex polygons. When removing all short segments, there may be too few segments remaining, or a pair of remaining segments may intersect on the wrong side, or the removal of all short segments may lead to an intersection point very distant from the original polygon.

Hull_Distant_Intersection_PointIn cases like this you will get better results by keeping some short segments.

Hull_Use_Some_Short_SegmentsThe attached workspace does all this. For simplicity I have chosen to determine which short segments to keep by simply looking at the number of consecutive short segments, and the maximum number of short segments to skip. There may be better ways, but this was simple to implement.

The workspace contains some sample convex polygons to simplify.

Click the custom transformer ConvexPolygonSimplifier, set the parameters (Minimum Length = 14, Maximum Number of Short Segments to Skip = 4), then run the workspace. Also look what happens when you set parameter Maximum Number of Short Segments to Skip to 0.

 

Please don't expect this custom transformer to be faultless. But I hope it will give you some inspiration, when you look into its inner workings. Good luck!


wind
  • Author
  • March 17, 2022

@geomancer​  thank you very much, it works. You are fantastic!


geomancer
Evangelist
Forum|alt.badge.img+50
  • Evangelist
  • March 17, 2022

Hi @wind​ , thanks for your feedback, I'm glad to hear I could help you.


topotoma
Contributor
Forum|alt.badge.img+3
  • Contributor
  • March 19, 2023
geomancer wrote:

There certainly seems to be a way for polygons like the one in your image, consisting of a number of long segments and a number of (often grouped) short segments. Remove the short segments, calculate the intersection points of the remaining segments and their neighbours. The intersection points span a convex polygon that completely contains the original polygon, and has fewer vertices.

Hull_cornerUnfortunately this algorithm does not work for all convex polygons. When removing all short segments, there may be too few segments remaining, or a pair of remaining segments may intersect on the wrong side, or the removal of all short segments may lead to an intersection point very distant from the original polygon.

Hull_Distant_Intersection_PointIn cases like this you will get better results by keeping some short segments.

Hull_Use_Some_Short_SegmentsThe attached workspace does all this. For simplicity I have chosen to determine which short segments to keep by simply looking at the number of consecutive short segments, and the maximum number of short segments to skip. There may be better ways, but this was simple to implement.

The workspace contains some sample convex polygons to simplify.

Click the custom transformer ConvexPolygonSimplifier, set the parameters (Minimum Length = 14, Maximum Number of Short Segments to Skip = 4), then run the workspace. Also look what happens when you set parameter Maximum Number of Short Segments to Skip to 0.

 

Please don't expect this custom transformer to be faultless. But I hope it will give you some inspiration, when you look into its inner workings. Good luck!

Thank you, very nice !


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings