daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 11th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(dplyr)
  2.  
  3. nests<-df %>%
  4.     filter(type %in% "Nest2017")
  5.  
  6. library(maptools)
  7. library(sp)
  8. library(rgeos)
  9.  
  10. nests$lon <- as.numeric(as.character(nests$lon))
  11. nests$lat <- as.numeric(as.character(nests$lat))
  12. coordinates(nests) <- c("lon", "lat")
  13.  
  14. proj4string(nests) <- CRS("+init=epsg:3578") #setting the projection of the points
  15.  
  16. spTransform(nests,CRS("+init=epsg:3578")) #tranforming the coordinates
  17.  
  18. gBuffer(nests, width=30, byid=TRUE) #puts a circular buffer around each individual point
  19.    
  20. lat                  lon                NatalMidden   squirrelID    type
  21. 60.9577819984406    -138.0347849708050  -27           NA            Nest2017
  22. 60.9574120212346    -138.0345689691600  -27           NA            NatalMidden
  23. 60.9578209742904    -138.0346520338210  -27           23054         Foray
  24. 60.9575380012393    -138.0348329991100  -27           23054         Foray
  25. 60.9576250053942    -138.0339069664480  -27           23054         Foray
  26. 60.957643026486     -138.0338829942050  -27           23054         Foray
  27. 60.9575670026243    -138.0348739866170  -27           23054         Foray
  28. 60.9600000176579    -138.032592013478   -515          22780         Foray
  29. 60.9600180387497    -138.032631995156   -515          22780         Foray
  30. 60.9599519893527    -138.032342987135   -515          NA            NatalMidden
  31. 60.959974033758     -138.032317003235   -515          NA            Nest2017
  32.    
  33. > df = read.table("./figshare.txt",sep="t",head=TRUE)
  34. > df = st_as_sf(df, coords=c("lon","lat"))
  35. > st_crs(df)=4326
  36. > df = st_transform(df, 3578)
  37. > plot(df$geometry,col=df$type,pch=19)
  38.    
  39. > Forays = df[df$type=="Foray",]
  40. > Nests = df[df$type=="Nest2017","NatalMidden"]
  41.    
  42. > Forays = dplyr::left_join(Forays, data.frame(Nests), c("NatalMidden"="NatalMidden"))
  43. > head(Forays)
  44. Simple feature collection with 6 features and 3 fields
  45. Active geometry column: geometry.x
  46. geometry type:  POINT
  47. dimension:      XY
  48. bbox:           xmin: 200427.2 ymin: 731035 xmax: 200451.7 ymax: 731043.8
  49. epsg (SRID):    3578
  50. proj4string:    +proj=aea +lat_1=61.66666666666666 +lat_2=68 +lat_0=59 +lon_0=-132.5 +x_0=500000 +y_0=500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
  51.   NatalMidden sq_id  type                geometry.x                geometry.y
  52. 1        -515 22780 Foray   POINT (200427.3 731035) POINT (200465.3 731052.2)
  53. 2        -515 22780 Foray POINT (200446.1 731041.4) POINT (200465.3 731052.2)
  54. 3        -515 22780 Foray POINT (200450.9 731043.5) POINT (200465.3 731052.2)
  55. 4        -515 22780 Foray POINT (200451.7 731043.8) POINT (200465.3 731052.2)
  56. 5        -515 22780 Foray POINT (200448.5 731042.7) POINT (200465.3 731052.2)
  57. 6        -515 22780 Foray   POINT (200427.2 731035) POINT (200465.3 731052.2)
  58.                   geometry
  59. 1 GEOMETRYCOLLECTION EMPTY
  60. 2 GEOMETRYCOLLECTION EMPTY
  61. 3 GEOMETRYCOLLECTION EMPTY
  62. 4 GEOMETRYCOLLECTION EMPTY
  63. 5 GEOMETRYCOLLECTION EMPTY
  64. 6 GEOMETRYCOLLECTION EMPTY
  65.    
  66. > Forays$geometry = NULL
  67. > Forays$dist = st_distance(Forays$geometry.x, Forays$geometry.y, by_element=TRUE)
  68. > head(Forays)
  69. Simple feature collection with 6 features and 4 fields
  70. Active geometry column: geometry.x
  71. geometry type:  POINT
  72. dimension:      XY
  73. bbox:           xmin: 200427.2 ymin: 731035 xmax: 200451.7 ymax: 731043.8
  74. epsg (SRID):    3578
  75. proj4string:    +proj=aea +lat_1=61.66666666666666 +lat_2=68 +lat_0=59 +lon_0=-132.5 +x_0=500000 +y_0=500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
  76.   NatalMidden sq_id  type                geometry.x                geometry.y
  77. 1        -515 22780 Foray   POINT (200427.3 731035) POINT (200465.3 731052.2)
  78. 2        -515 22780 Foray POINT (200446.1 731041.4) POINT (200465.3 731052.2)
  79. 3        -515 22780 Foray POINT (200450.9 731043.5) POINT (200465.3 731052.2)
  80. 4        -515 22780 Foray POINT (200451.7 731043.8) POINT (200465.3 731052.2)
  81. 5        -515 22780 Foray POINT (200448.5 731042.7) POINT (200465.3 731052.2)
  82. 6        -515 22780 Foray   POINT (200427.2 731035) POINT (200465.3 731052.2)
  83.           dist
  84. 1 41.69695 [m]
  85. 2 21.97295 [m]
  86. 3 16.79233 [m]
  87. 4 15.91557 [m]
  88. 5 19.27717 [m]
  89. 6 41.79212 [m]
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