AustralianAntarcticDivision / SOmap

Southern Ocean round maps
https://australianantarcticdivision.github.io/SOmap/
24 stars 6 forks source link

Crop Continents #13

Closed Maschette closed 5 years ago

Maschette commented 5 years ago

Ideally we would have a way to crop the continents layer so that we can export to eps and not have this happen: image

I feel like @mdsumner had a way to do this based on longitudes?

library(spbabel)
sptable(x) <- dplyr::filter(sptable(x), y_ > -90)

so we could essentially make an option for cropcont where if true it runs: sptable(x) <- dplyr::filter(sptable(x), y_ > Trim+1) ?

Maschette commented 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.

mdsumner commented 5 years ago

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.

mdsumner commented 5 years ago

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.

Maschette commented 5 years ago

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
mdsumner commented 5 years ago

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

Maschette commented 5 years ago

Done, I just went with the suppresswarnings option.