Guest User

Untitled

a guest
May 16th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #States need to be in equal area projection
  2. #5070 is EPSG code for the USGS Alber's projection
  3. states <- st_transform(states, crs = 5070)
  4. #Create centroids of states
  5. cntr <- st_centroid(states)
  6. #Bind these coordinates to the centroid feature
  7. cntr <- cbind(cntr, st_coordinates(cntr))
  8. #Get centroid for conterminous US
  9. xy <- states %>% st_union() %>%
  10. st_centroid() %>% st_coordinates()
  11. #Define column 'region' and break US up into regions
  12. cntr$region <- 'NE'
  13. cntr$region[cntr$X > xy[1] & cntr$Y < xy[2]] <- 'SE'
  14. cntr$region[cntr$X < xy[1] & cntr$Y < xy[2]] <- 'SW'
  15. cntr$region[cntr$X < xy[1] & cntr$Y > xy[2]] <- 'NW'
  16. #Region IDs back to state polygons
  17. states$region <- cntr$region
  18. #Dissolve by region ID
  19. regions <- states %>%
  20. group_by(region) %>%
  21. summarise()
  22. plot(regions$geometry)
  23. plot(cntr['region'], pch = 19, add=T)
Add Comment
Please, Sign In to add comment