Re: [R] Excluding coordinates that fall within a circle
... 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 Domalikwrote: > 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@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. __ R-help@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.
Re: [R] Excluding coordinates that fall within a circle
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 Domalikwrote: >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@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]] __ R-help@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.
Re: [R] Excluding coordinates that fall within a circle
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 Domalikwrote: > 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@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. __ R-help@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.
Re: [R] Excluding coordinates that fall within a circle
> On Jun 17, 2016, at 10:26 AM, Alice Domalikwrote: > > 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 Use 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)*1,origin="1970-01-01") ) reduced <- dfrm[ (dfrm$lat - .5)^2+(dfrm$long-.5)^2 > .25 , ] with( reduced, plot(lat,long) ) Rplot.pdf Description: Adobe PDF document 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 __ R-help@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.
Re: [R] Excluding coordinates that fall within a circle
This would be a good question for R-sig-geo. To do it properly, there would be a few steps: 1. transform from lat/long (units=degrees) to projected coordinate system (units = meters) 2. find one of the R functions for calculating distances (there are several) 3. subset the data according to your distance threshold The sp package provides a lot of the fundamental tools for these kinds of things. The spDists() function in the sp package may take care of both steps 1 and 2. The overhead required to learn R's spatial capabilities can be significant, but I think will be worth it if you will be needing to do a lot of spatial manipulations. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 6/17/16, 10:26 AM, "R-help on behalf of Alice Domalik"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@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. __ R-help@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.
[R] Excluding coordinates that fall within a circle
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@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.