Provide a sf::st_as_sf.recmap method?
cpsievert opened this issue · 3 comments
cpsievert commented
Nice package! It would be great if there was an easy way convert a recmap object to an sf object to make it easier to visualize outside of plot()
cpanse commented
@cpsievert I wonder if the as.SpatialPolygonsDataFrame function could help you for the moment.
library(recmap)
SpDf <- as.SpatialPolygonsDataFrame(recmap(checkerboard(8)))
## US example
usa <- data.frame(x = state.center$x,
y = state.center$y,
# make the rectangles overlapping by correcting
# lines of longitude distance.
dx = sqrt(state.area) / 2
/ (0.8 * 60 * cos(state.center$y * pi / 180)),
dy = sqrt(state.area) / 2 / (0.8 * 60),
z = sqrt(state.area),
name = state.name)
usa$z <- state.x77[, 'Population']
US.Map <- usa[match(usa$name,
c('Hawaii', 'Alaska'), nomatch = 0) == 0, ]
as.SpatialPolygonsDataFrame(recmap(US.Map))
cpanse commented
@cpsievert Seems to work. Is that what you want?
library(sf)
SPDF <- as.SpatialPolygonsDataFrame(recmap(US.Map))
st_as_sf(SPDF)
cpsievert commented
Ahh, yes, that's works for me, thanks!
