-
Notifications
You must be signed in to change notification settings - Fork 121
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
upcoming sf will break tmap when adopting s2 #564
Comments
Apparently, library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
W = ne_countries(returnclass = "sf")
W_valid = st_is_valid(W)
which(!W_valid)
#> [1] 7 54 136
plot(W[!W_valid, 1]) W2 = st_make_valid(W)
plot(W2[!W_valid,1]) W2_valid = st_is_valid(W2)
which(!W2_valid)
#> integer(0) Created on 2021-04-21 by the reprex package (v1.0.0) I guess that this is caused by polygons breaking the (-)180 longitude. Maybe it can be fixed by allowing longitudes to be outside the [-180, 180] range? E.g. by adding 360 to the longitudes of Russia that are < 0. Haven't tried it yet. |
Forgot to mention that the issue has been fixed: tmap does the However, since the |
What you consider "natural" is topological validity on R2 (plate carrée), not on S2. Since our Earth is round, I consider S2 the more natural interpretation of ellipsoidal coordinates, despite the 6 decades of GIS tradition ignoring this. Someone has to start. Once valid on S2, there is no easy way back; you'd have to split at the dateline and break open the poles again.
That, and the singularity of poles (Antarctica making an excursion through +/-180,-90) |
s2 1.0.5 (CRAN) and sf (github, branch sf_1_0) now have a st_make_valid that does a proper job for spherical coordinates. Still failing tmap and tmaptools:
|
I think there are still some s2 problems in tmap. The below examples show an issue with library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1
library(tmap)
data("World")
World2 = World
World2$geometry[World$iso_a3 == "USA"] = st_cast(World$geometry[World$iso_a3 == "USA"], "POLYGON")[6]
ortho_crs = st_crs("+proj=ortho +lon_0=11 +lat_0=46")
World_ortho = st_transform(World2, crs = ortho_crs)
World_ortho = st_make_valid(World_ortho)
World_ortho = st_cast(World_ortho, "MULTIPOLYGON")
World_ortho = World_ortho[!st_is_empty(World_ortho), ]
# works
tm_shape(World_ortho) +
tm_polygons() +
tm_layout() # works
sf_use_s2(FALSE)
#> Spherical geometry (s2) switched off
tm_shape(World_ortho) +
tm_polygons() +
tm_graticules() +
tm_layout() # does not work
sf_use_s2(TRUE)
#> Spherical geometry (s2) switched on
tm_shape(World_ortho) +
tm_polygons() +
tm_graticules() +
tm_layout()
#> Error in st_coordinates.sfc(st_geometry(lns_crop)[sum(lnsSel)]): not implemented for objects of class sfc_GEOMETRYCOLLECTION Created on 2021-07-05 by the reprex package (v2.0.0) |
The problem was that the intersection between visual bounding box and graticules resulted in a geometrycollection. If should be solved, but no guarantees that it is s2-bug-free. |
If you use |
See r-spatial/sf#1649 and consider commenting there in case this is not trivial to solve. @paleolimbot
looks like another world map that is not valid on S2?
The text was updated successfully, but these errors were encountered: