cpanse/recmap

Provide a sf::st_as_sf.recmap method?

cpsievert opened this issue · 3 comments

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()

@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))

@cpsievert Seems to work. Is that what you want?

library(sf)
SPDF <- as.SpatialPolygonsDataFrame(recmap(US.Map))
st_as_sf(SPDF)

screenshot 2019-02-21 at 10 01 09

Ahh, yes, that's works for me, thanks!