daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(sf)
  2. gages <- st_read('C:/Users/mweber/Temp/gages_test.shp')
  3. class(gages)
  4.  
  5. # Let's pretend it's a csv file we read in rather than a shapefile - I'll strip out the 'spatial'
  6. # part (the geometry column) and make it just a data.frame with Lon and Lat columns, then show
  7. # how to promote it back
  8.  
  9. st_geometry(gages) <- NULL
  10. class(gages)
  11. # now imagine we've read in a flat file with coordinate info to a data frame 'gages' - since we're just using the 'Lat'
  12. # and 'Lon' columns, we apply NAD83 as the coordinate ref system rather than projection the shapefile was in
  13. gages <- st_as_sf(gages, coords = c("LON_SITE", "LAT_SITE"), crs = 4269,agr = "constant")
  14. class(gages)
  15.  
  16. # These are gages in Oregon so I'm reading in NHDPlus catchments for hydro-region 17
  17. NHD_cats <- st_read('H:/NHDPlusV21/NHDPlusPN/NHDPlus17/NHDPlusCatchment/Catchment.shp')
  18. # Projection have to be the same to join features - check
  19. st_crs(NHD_cats) == st_crs(gages)
  20. # Just encoded slightly differently
  21. gages <- st_transform(gages, st_crs(NHD_cats))
  22.  
  23. # Now do spatial join of points and polys
  24. z <- st_join(gages, NHD_cats)
  25. head(z)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top