Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with wrapping longitude boundary #225

Closed
aabelean opened this issue Oct 30, 2023 · 3 comments · Fixed by #285
Closed

Dealing with wrapping longitude boundary #225

aabelean opened this issue Oct 30, 2023 · 3 comments · Fixed by #285
Assignees
Labels
bug Something isn't working invalid This doesn't seem right plotting release-2

Comments

@aabelean
Copy link
Contributor

I tested the original (legacy) meshes from GlobalMass and plotted them with plot_map(). Ignoring the fact that the meshes contain a lot of isolated triangles, I found that this map distorts the triangles that span the longitude wrapping boundary (180/-180 meridian) and makes them appear across the map like shown in the pictures below.
image
Zoom in close to Wrangel Island (from each side):
image
image

We need to find a way to either mask these triangles or allow splitting the triangle on each side.

@aabelean aabelean added bug Something isn't working invalid This doesn't seem right plotting labels Oct 30, 2023
@aabelean aabelean added this to the Release v0.1.1 milestone Oct 30, 2023
@gareth-j gareth-j removed this from the Release v0.1.1 milestone Nov 1, 2023
@mnky9800n
Copy link
Contributor

@aabelean can you look at the leaflet documentation and see if there is any meniton of mapping across the longitude divide?

@aabelean
Copy link
Contributor Author

aabelean commented Nov 15, 2023

Yes, @mnky9800n there are multiple mentions of this issue. This was first raised in 2011 with the first release of leaflet. Unfortunately, base leaflet did not implement the fix, but it is available through the Leaflet.Antimeridian plugin. However, there is an open issue in rstudio/leaflet from 2018 to incorporate this as either as base or additional functionality, so we can't really use it in R at the moment.

The current workaround (from said 2011, in absence of support for Leaflet.Antimeridian) is to allow these objects to exceed the 180 degree boundary by adding 360 to the negative values. This cannot be done indiscriminately as we would just transfer the problem to Greenwich meridian. My suggestion is to check LONG coordinates of each polygon: if there is a mismatch in sign with other coordinates, we just add 360 to it.
For plot_mesh it is a bit more complicated. If we work, for instance, in Beringia/Chukotka, we get triangle vertices that are shared by triangles that cross the anti-meridian and also those that don't. We cannot just change the coordinates of those points. Instead, we should add new vertices with coordinates transformed. I will do more rigorous testing with this before pushing anything as I think there is a great risk of breaking something.
It can be an issue for Shiny app mesh_builder too, but I think the map is rendered differently in Shiny apps, so might need a different fix. I will check it as well.

@aabelean aabelean assigned aabelean and unassigned gareth-j Nov 27, 2023
@aabelean
Copy link
Contributor Author

I'll implement this through sf::st_wrap_dateline function. As it only works properly with latitudes in range between -180 and 180, I've developed a conversion function (which currently fails). Note that this only concerns the polygons, but not raster.

@aabelean aabelean mentioned this issue Nov 28, 2023
5 tasks
@gareth-j gareth-j added this to the Release v0.2.0 milestone Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right plotting release-2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants