Grokbase Groups R r-help June 2016
FAQ
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]]

Search Discussions

  • MacQueen, Don at Jun 17, 2016 at 6:09 pm
    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"
    <r-help-bounces@r-project.org on behalf of adomalik@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.
  • David Winsemius at Jun 17, 2016 at 6:09 pm

    On Jun 17, 2016, at 10:26 AM, 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



    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)*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
  • Tom Wright at Jun 17, 2016 at 6:15 pm
    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 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.
  • Jeff Newmiller at Jun 17, 2016 at 6:29 pm
    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 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]]
  • Bert Gunter at Jun 17, 2016 at 6:40 pm
    ...
    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 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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedJun 17, '16 at 5:26p
activeJun 17, '16 at 6:40p
posts6
users6
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase