Hi List, I'm working with some bird tracking data, and to filter the data set, I need to exclude points taken at the colony. I would like to exclude coordinates from within a 500 meter radius of a point centered on the colony. However, as an R novice, I'm not sure how to accomplish this. My df looks like this: AnimalID Latitude Longitude Datetime Any suggestions would be greatly appreciated. [[alternative HTML version deleted]]
> On Jun 17, 2016, at 10:26 AM, Alice Domalik <adomalik at sfu.ca> wrote: > > Hi List, > > I'm working with some bird tracking data, and to filter the data set, I need to exclude points taken at the colony. > I would like to exclude coordinates from within a 500 meter radius of a point centered on the colony. > However, as an R novice, I'm not sure how to accomplish this. > > My df looks like this: > > AnimalID Latitude Longitude DatetimeUse the first argument of the "[" function to select rows that meet your requirement. I constructed values in hte unit square and select only items in hte corners by excluding values within 0.5 units of the center, (0.5,0.5) dfrm <- data.frame(ID=1:100, lat=runif(100), long=runif(100), Datetime=as.POSIXct(runif(100)*10000,origin="1970-01-01") ) reduced <- dfrm[ (dfrm$lat - .5)^2+(dfrm$long-.5)^2 > .25 , ] with( reduced, plot(lat,long) ) -------------- next part -------------- A non-text attachment was scrubbed... Name: Rplot.pdf Type: application/pdf Size: 90150 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20160617/a96d318d/attachment.pdf> -------------- next part -------------- Probably should have plotted (long, lat), and it might have been more eser freindly to use subset instead of `[ logical-vector, ]` but I think this demonstrates the essential steps. -- David Winsemius Alameda, CA, USA
I'm no expert here but I have recently been playing with the package 'geosphere' it contains plenty of options to calculate distance between two coordinates specified as lat and long. install.packages('geosphere') # only needed once library(geosphere) coord1 <- c(43.60923,-79.322799) coord2 <- c(43.683266,-79.323703) distHaversine(coord1,coord2) Once you have a vector of distances you can then filter your df df <- df[df$distance < radius,] On Fri, Jun 17, 2016 at 1:26 PM, Alice Domalik <adomalik at sfu.ca> wrote:> Hi List, > > I'm working with some bird tracking data, and to filter the data set, I need to exclude points taken at the colony. > I would like to exclude coordinates from within a 500 meter radius of a point centered on the colony. > However, as an R novice, I'm not sure how to accomplish this. > > My df looks like this: > > AnimalID Latitude Longitude Datetime > > Any suggestions would be greatly appreciated. > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
This is mostly a domain-specific question about coordinate conversion and algebra, not really about R. However, there are packages that could be useful for this problem that are discussed in the CRAN "Analysis of Spatial Data" Task View [1] and on the R-sig-geo mailing list [2]. Some points to get you started: 1) You need to know about georeferencing coordinate systems. In particular, what LatLon system are the coordinates you have measured in. The range of values in your data will be something to mention when you ask your question on R-sig-geo if they are to help you figure that out. 2) A small sample of your data extracted from R with the dput function will be helpful. 3) Read the Posting Guide. Note in particular that you need to tell your email client to use plain text format if you want to insure that the recipients see what you sent instead of some garbled version of it. [1] https://cran.r-project.org/view=Spatial [2] https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Sent from my phone. Please excuse my brevity. On June 17, 2016 10:26:32 AM PDT, Alice Domalik <adomalik at sfu.ca> wrote:>Hi List, > >I'm working with some bird tracking data, and to filter the data set, I >need to exclude points taken at the colony. >I would like to exclude coordinates from within a 500 meter radius of a >point centered on the colony. >However, as an R novice, I'm not sure how to accomplish this. > >My df looks like this: > >AnimalID Latitude Longitude Datetime > >Any suggestions would be greatly appreciated. > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
... and adding, perhaps, to what David and Jeff told you: Let ctr = c(ctr.lat, ctr.long) be the center of a bird colony (this can be vectorized for many centers). Then you need to figure out how much change in latitude and longitude a distance of 500 meters is at that ctr (I think latitudes are easy; it's longitudes that vary in distance depending on where you. But I hasten to add that I ain't an expert). You can approximate this by pretending the latitudes and longitude are perpendicular on a plane unless you are close to the poles.I strongly suspect there are functions in geostatistics and/or ecology packages that do this: search (e.g. web or rseek.org) on "convert distance to latitude and longitude" or similar (this seemed to yield useful results when I tried it). Then apply David's (and Jeff's) suggestions. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Jun 17, 2016 at 10:26 AM, Alice Domalik <adomalik at sfu.ca> wrote:> Hi List, > > I'm working with some bird tracking data, and to filter the data set, I need to exclude points taken at the colony. > I would like to exclude coordinates from within a 500 meter radius of a point centered on the colony. > However, as an R novice, I'm not sure how to accomplish this. > > My df looks like this: > > AnimalID Latitude Longitude Datetime > > Any suggestions would be greatly appreciated. > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.