Closed Maschette closed 5 years ago
This is not going to work as easily as I hoped. SOmap_data$continents is in polar projection so I cant easily specify a longitude to crop at without reprojecting first.
Try cropping to a buffered point, the centre is 0,0 in the projection so
st_buffer(st_point(cbind(0, 0)), 111111 * (90-abs(lat)))
something like that ... that magic number is the km per degree - 1852m (a nautical mile) in every 1/60th of a degree, more or less.
This works:
library(SOmap)
lat <- -30
x <-sf::st_as_sf(SOmap::SOmap_data$continent)
x <- sf::st_buffer(x, 0)
buf <- sf::st_sf(a = 1, geometry = sf::st_sfc(sf::st_buffer(sf::st_point(cbind(0, 0)), 111111 * (90-abs(lat)))), crs = raster::projection(SOmap_data$continent))
lat_continent <- sf::st_intersection(buf, x)
sf will generally be better than sp/rgeos for cropping, but note I need the st_buffer hack to avoid topology problems ... which we should probably apply to the data in the package for good measure.
Hmm this works but when you use it in the SOmap function than you get:
Warning message:
attribute variables are assumed to be spatially constant throughout all geometries
Yeah it's hard to shut sf up. Maybe use just st_sfc, remove the st_sf part - if you commit push and ping me I'll finish it up
Done, I just went with the suppresswarnings option.
Ideally we would have a way to crop the continents layer so that we can export to eps and not have this happen:
I feel like @mdsumner had a way to do this based on longitudes?
so we could essentially make an option for cropcont where if true it runs:
sptable(x) <- dplyr::filter(sptable(x), y_ > Trim+1)
?