turfjs - turf.intersect reverses winding order of polygon - Stack Overflow

admin2025-04-28  8

In the below example, I am using turf.intersect to compute the intersection between Saudi Arabia and its own bounding box. So the returned polygon by turf.intersect should be Saudi Arabia.

However, I see that the winding order of the returned polygon is reversed. What's the reason for this? If I don't want the winding order reversed, do I have to reverse the polygon's coordinates manually (in the example, I have a line commented out that calls turf.rewind to do this)?

In the below example, I am using turf.intersect to compute the intersection between Saudi Arabia and its own bounding box. So the returned polygon by turf.intersect should be Saudi Arabia.

However, I see that the winding order of the returned polygon is reversed. What's the reason for this? If I don't want the winding order reversed, do I have to reverse the polygon's coordinates manually (in the example, I have a line commented out that calls turf.rewind to do this)?

https://observablehq.com/d/7b6b204c8afebddc

Share Improve this question edited Jan 13 at 19:28 Eric asked Jan 9 at 19:01 EricEric 1,6234 gold badges13 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The input saudiArabia geojson is invalid because it's wound the wrong way. According to the spec polygons must follow the right hand rule.

The winding is likely being fixed (reversed from where you're standing) at some layer within Turf to make sure the output is valid geojson.

If you don't want your result wound according to the spec, it might be of help to note Turf has a rewind() function that includes a reverse option.

转载请注明原文地址:http://www.anycun.com/QandA/1745778660a91169.html