Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a sf::st_as_sf.recmap method? #13

Closed
cpsievert opened this issue Feb 15, 2019 · 3 comments
Closed

Provide a sf::st_as_sf.recmap method? #13

cpsievert opened this issue Feb 15, 2019 · 3 comments
Assignees

Comments

@cpsievert
Copy link

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 cpanse self-assigned this Feb 21, 2019
@cpanse
Copy link
Owner

cpanse commented Feb 21, 2019

@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 cpanse pinned this issue Feb 21, 2019
@cpanse
Copy link
Owner

cpanse commented Feb 21, 2019

@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

@cpsievert
Copy link
Author

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

@cpanse cpanse closed this as completed Feb 21, 2019
@cpanse cpanse unpinned this issue Feb 24, 2019
@cpanse cpanse pinned this issue Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants