Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(dplyr)
- nests<-df %>%
- filter(type %in% "Nest2017")
- library(maptools)
- library(sp)
- library(rgeos)
- nests$lon <- as.numeric(as.character(nests$lon))
- nests$lat <- as.numeric(as.character(nests$lat))
- coordinates(nests) <- c("lon", "lat")
- proj4string(nests) <- CRS("+init=epsg:3578") #setting the projection of the points
- spTransform(nests,CRS("+init=epsg:3578")) #tranforming the coordinates
- gBuffer(nests, width=30, byid=TRUE) #puts a circular buffer around each individual point
- lat lon NatalMidden squirrelID type
- 60.9577819984406 -138.0347849708050 -27 NA Nest2017
- 60.9574120212346 -138.0345689691600 -27 NA NatalMidden
- 60.9578209742904 -138.0346520338210 -27 23054 Foray
- 60.9575380012393 -138.0348329991100 -27 23054 Foray
- 60.9576250053942 -138.0339069664480 -27 23054 Foray
- 60.957643026486 -138.0338829942050 -27 23054 Foray
- 60.9575670026243 -138.0348739866170 -27 23054 Foray
- 60.9600000176579 -138.032592013478 -515 22780 Foray
- 60.9600180387497 -138.032631995156 -515 22780 Foray
- 60.9599519893527 -138.032342987135 -515 NA NatalMidden
- 60.959974033758 -138.032317003235 -515 NA Nest2017
- > df = read.table("./figshare.txt",sep="t",head=TRUE)
- > df = st_as_sf(df, coords=c("lon","lat"))
- > st_crs(df)=4326
- > df = st_transform(df, 3578)
- > plot(df$geometry,col=df$type,pch=19)
- > Forays = df[df$type=="Foray",]
- > Nests = df[df$type=="Nest2017","NatalMidden"]
- > Forays = dplyr::left_join(Forays, data.frame(Nests), c("NatalMidden"="NatalMidden"))
- > head(Forays)
- Simple feature collection with 6 features and 3 fields
- Active geometry column: geometry.x
- geometry type: POINT
- dimension: XY
- bbox: xmin: 200427.2 ymin: 731035 xmax: 200451.7 ymax: 731043.8
- epsg (SRID): 3578
- 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
- NatalMidden sq_id type geometry.x geometry.y
- 1 -515 22780 Foray POINT (200427.3 731035) POINT (200465.3 731052.2)
- 2 -515 22780 Foray POINT (200446.1 731041.4) POINT (200465.3 731052.2)
- 3 -515 22780 Foray POINT (200450.9 731043.5) POINT (200465.3 731052.2)
- 4 -515 22780 Foray POINT (200451.7 731043.8) POINT (200465.3 731052.2)
- 5 -515 22780 Foray POINT (200448.5 731042.7) POINT (200465.3 731052.2)
- 6 -515 22780 Foray POINT (200427.2 731035) POINT (200465.3 731052.2)
- geometry
- 1 GEOMETRYCOLLECTION EMPTY
- 2 GEOMETRYCOLLECTION EMPTY
- 3 GEOMETRYCOLLECTION EMPTY
- 4 GEOMETRYCOLLECTION EMPTY
- 5 GEOMETRYCOLLECTION EMPTY
- 6 GEOMETRYCOLLECTION EMPTY
- > Forays$geometry = NULL
- > Forays$dist = st_distance(Forays$geometry.x, Forays$geometry.y, by_element=TRUE)
- > head(Forays)
- Simple feature collection with 6 features and 4 fields
- Active geometry column: geometry.x
- geometry type: POINT
- dimension: XY
- bbox: xmin: 200427.2 ymin: 731035 xmax: 200451.7 ymax: 731043.8
- epsg (SRID): 3578
- 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
- NatalMidden sq_id type geometry.x geometry.y
- 1 -515 22780 Foray POINT (200427.3 731035) POINT (200465.3 731052.2)
- 2 -515 22780 Foray POINT (200446.1 731041.4) POINT (200465.3 731052.2)
- 3 -515 22780 Foray POINT (200450.9 731043.5) POINT (200465.3 731052.2)
- 4 -515 22780 Foray POINT (200451.7 731043.8) POINT (200465.3 731052.2)
- 5 -515 22780 Foray POINT (200448.5 731042.7) POINT (200465.3 731052.2)
- 6 -515 22780 Foray POINT (200427.2 731035) POINT (200465.3 731052.2)
- dist
- 1 41.69695 [m]
- 2 21.97295 [m]
- 3 16.79233 [m]
- 4 15.91557 [m]
- 5 19.27717 [m]
- 6 41.79212 [m]
Add Comment
Please, Sign In to add comment