turf.lineIntersect not detecting intersection at anti-meridian #2881
Replies: 2 comments 1 reply
-
Hi @tsairinius. There are a few things going on here so I'll touch on each one, and we can dive deeper on any in particular you want to. Forgive my diagramming skills.
Sort of. The geojson spec indicates features shouldn't cross the antimeridian. I think of the antimeridian as an impassible fence. To get from just to the left [179.9, 0] to just to the right [-179.9, 0] you need to head west and go the long way around. That's why some tools will render the polygon like this: v2.0.0 adds an extra point, but it's still not right: That shape should be two completely separate polygons, neither of which cross the antimeridian:
It does still occur in 2.0.0 to some degree. In the diagrams below the vertical dashed green and blue lines are the two meridian lines. You can see in the two different versions of Fiji that they refer to different sides of the map, and overlap with different points. If we cut the map along the antimeridian and flatten it out we get the below: fiji-1.1.4 fiji-2.0.0 If you look at the two points that match with a 180 meridian and 2.0.0 (the diagram immediately above) they're practically the same, both matches for the northern coatline only.
Thinking back to the flat map metaphor, that's what that line looks like: Those coordinates take you from the top right of the map, alllll the way over to the middle left, and then back to the bottom right. The "antimeridian" ends up being a zigzag. What I can't figure outyet is why the zigzag line crossing the extended polygon doesn't match up with the intersection points (marked by the two pins). Will have to get back to you on that part. To resolve, I believe if the polygons were defined correctly most of these problems would go away. Hope that's of some help! Sing out if you've got any follow up questions. |
Beta Was this translation helpful? Give feedback.
-
@smallsaucepan Thanks so much for the explanation! This definitely clears things up. Splitting that polygon into two separate ones on each side of the anti-meridian is an interesting alternative. But I wonder how D3 manages to draw Fiji without having it stretch across the map. As far as detecting Fiji's intersection with the anti-meridian goes, I tried a different approach (added it to the Observable) that I think should work for my purposes. I defined a thin polygon on each side of the anti-meridian. Each one stretches along the length of the anti-meridian. Then I determine whether the country intersects with both polygons, which would indicate that it crosses the anti-meridian. I'd like to be able to detect whether any country cross the anti-meridian, not just Fiji. I think this approach should work in most cases, and Russia and Fiji are the only countries I know of that cross the anti-meridian. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to detect intersections between Fiji and the anti-meridian using
turf.lineIntersect
. In my application I'm using the110m.json
file fromworld-atlas
v1.1.4 and turf v7.2.0.You can see from this example that the anti-meridian definitely passes through Fiji:
https://observablehq.com/d/3783b622de803945
If I represent the anti-meridian using
turf.lineString([[180, 90], [180, 0], [180, -90]])
,turf.lineIntersect
does not find any intersections with Fiji (notice thatantimeridianIntersect
'sfeatures
array is empty). However, if I change it toturf.lineString([[-180, 90], [-180, 0], [-180, -90]])
with x-values being-180
,turf.lineIntersect
successfully picks up on the intersections.Taking a closer look at Fiji's coordinates, its max x-value is 179.4 and its min x-value is -180. Does turf think that Fiji wraps around the globe from -180 to 179.4?
Other points:
turf.lineString([[180, 90], [-180, 0], [180, -90]])
with just the middle point's x-value at -180 does lead to intersections being detected. However, those intersections are not located within Fiji. I'm guessing turf is thinking that the line wraps all around the globe in order to go from 180 to -180. But I'm not sure why it detects intersections somewhere outside of Fiji.world-atlas
. It looks like Fiji's topology is slightly different in these versions. Still, I'm not sure why using -180 versus 180 as an x-value for defining the anti-meridian would changeturf.lineIntersect
's ability to detect intersections.Beta Was this translation helpful? Give feedback.
All reactions