You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#check_antimeridian incorrectly determines that bounding box crossing the antimeridian does notkiribati<-spatialgridr::get_boundary(name="Kiribati", country_type="sovereign")
kir_crs<-'+proj=laea +lon_0=-159.609375 +lat_0=0 +datum=WGS84 +units=m +no_defs'kir_local_crs<-sf::st_transform(kiribati, kir_crs)
kir_local_bbox<-sf::st_bbox(kir_local_crs) |>sf::st_bbox() |>sf::st_as_sfc() |>sf::st_as_sf()
#returns FALSE, i.e. does not cross antimeridian (but it does!)spatialgridr:::check_antimeridian(kir_local_bbox, 4326)
#> [1] FALSE#check_antimeridian projects the bounding box of the polygon into epsg:4326, but results in a bounding box that is 'inverse' - this is the code it uses:sf::sf_use_s2(TRUE)
sf::st_transform(kir_local_bbox, 4326) |>sf::st_bbox() |>sf::st_as_sfc() |>
plot(axes=T)
sf::st_transform(kir_local_bbox, 4326) |>sf::st_bbox()
#> xmin ymin xmax ymax #> -146.868970 -13.789183 167.699940 7.830588#this behaviour is only for the bbox, the polygon boundaries work okspatialgridr:::check_antimeridian(kir_local_crs, 4326)
#> [1] TRUEsf::st_transform(kir_local_crs, 4326) |>sf::st_bbox()
#> xmin ymin xmax ymax #> -180.000000 -13.838333 179.998831 7.879056#the problem is likely due to lack of nodes - when polygon is split at antimeridian, it is broken into two sets of points either side of the antimeridian which are then re-joined after projecting, but the join is the 'wrong' way since it cannot be joined across the antimeridian in 4326#try densifying before transforming - this add nodes and fixes the problemkir_local_bbox_dense<-terra::densify(terra::vect(kir_local_bbox), interval=1e4) |>sf::st_as_sf()
spatialgridr:::check_antimeridian(kir_local_bbox_dense, 4326)
#> [1] TRUEsf::st_transform(kir_local_bbox_dense, 4326) |>sf::st_bbox()
#> xmin ymin xmax ymax #> -179.962616 -13.876564 179.969959 7.879078sf::st_transform(kir_local_bbox_dense, 4326) |>
plot(axes=T)
#could improve check_antimeridian code using this idea: https://gis.stackexchange.com/questions/256329/determining-whether-polygon-crosses-the-antimeridian
#could improve check_antimeridian code using this idea: https://gis.stackexchange.com/questions/256329/determining-whether-polygon-crosses-the-antimeridian
Created on 2024-12-19 with reprex v2.1.1
The text was updated successfully, but these errors were encountered: