Alaios
2016-Feb-02 22:04 UTC
[R] find numbers that fall in a region or the next available.
Dear all,I have GPS coordinates (one vector for longitude and one for latitude: GPSLong and GPSLat) of small are that is around 300meters X 300 meters (location falls inside UK).At the same time I have two more vectors (Longitude and Latitude) that include position of food stores again the UK I would like to find within my 300x300 square area which as the food stores that fall inside.I thought to try to find which of the Longitude of the food stores fall inside my area. I tried something the below Longitude[Longitude>(min(GPSLong)-0.001)&&Longitude<(max(GPSLong)+0.001)] but this returned me zero results.The next option would be the code to return me at least the place that falls outside but still is close to that region.'Do you have any idea how to do that and not fall back in the time consuming look at each element iteration? I would like to thank you for your replyRegardsAlex [[alternative HTML version deleted]]
Rolf Turner
2016-Feb-02 22:33 UTC
[R] [FORGED] find numbers that fall in a region or the next available.
On 03/02/16 11:04, Alaios via R-help wrote:> Dear all,I have GPS coordinates (one vector for longitude and one for > latitude: GPSLong and GPSLat) of small are that is around 300meters X > 300 meters (location falls inside UK).At the same time I have two > more vectors (Longitude and Latitude) that include position of food > stores again the UK I would like to find within my 300x300 square > area which as the food stores that fall inside.I thought to try to > find which of the Longitude of the food stores fall inside my area. I > tried something the below > > Longitude[Longitude>(min(GPSLong)-0.001)&&Longitude<(max(GPSLong)+0.001)] > but this returned me zero results.The next option would be the code > to return me at least the place that falls outside but still is close > to that region.'Do you have any idea how to do that and not fall back > in the time consuming look at each element iteration? > I would like to thank you for your replyYou could make use of the distfun() function from the spatstat package. Represent your "small area" as an object of class "owin". The longitude and latitude coordinates will be treated as if they were Euclidean coordinates, but over distances of the order of 300 metres this should not matter much. You could of course convert your long and lat coordinates to metres, using some appropriate projection, which might make more sense in your context. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Alaios
2016-Feb-03 08:42 UTC
[R] [FORGED] find numbers that fall in a region or the next available.
Thanks. I am using distm of the geoshere package.I still wonder if there is a package that can tell me if a gps coordinate or not falls inside my area that is defined as: bbox <- c(min(PlotPoints[, 1])-0.001, min(PlotPoints[, 2])-0.001, max(PlotPoints[, 1])+0.001, max(PlotPoints[, 2])+0.001) PlotPoints are gps coordinates. That would make it sure that I have no mistakes in my code. Any ideas?Alex On Tuesday, February 2, 2016 11:33 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote: On 03/02/16 11:04, Alaios via R-help wrote:> Dear all,I have GPS coordinates (one vector for longitude and one for > latitude: GPSLong and GPSLat) of small are that is around 300meters X > 300 meters (location falls inside UK).At the same time I have two > more vectors (Longitude and Latitude) that include position of food > stores again the UK I would like to find within my 300x300 square > area which as the food stores that fall inside.I thought to try to > find which of the Longitude of the food stores fall inside my area. I > tried something the below > > Longitude[Longitude>(min(GPSLong)-0.001)&&Longitude<(max(GPSLong)+0.001)] > but this returned me zero results.The next option would be the code > to return me at least the place that falls outside but still is close > to that region.'Do you have any idea how to do that and not fall back > in the time consuming look at each element iteration? > I would like to thank you for your replyYou could make use of the distfun() function from the spatstat package. ? Represent your "small area" as an object of class "owin".? The longitude and latitude coordinates will be treated as if they were Euclidean coordinates, but over distances of the order of 300 metres this should not matter much.? You could of course convert your long and lat coordinates to metres, using some appropriate projection, which might make more sense in your context. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 [[alternative HTML version deleted]]
S Ellison
2016-Feb-03 16:33 UTC
[R] find numbers that fall in a region or the next available.
> Dear all,I have GPS coordinates (one vector for longitude and one for latitude: > GPSLong and GPSLat) of small are that is around 300meters X 300 meters > (location falls inside UK).At the same time I have two more vectors (Longitude > and Latitude) that include position of food stores again the UK I would like to > find within my 300x300 square area which as the food stores that fall inside.I > thought to try to find which of the Longitude of the food stores fall inside my > area. I tried something the below > > Longitude[Longitude>(min(GPSLong)- > 0.001)&&Longitude<(max(GPSLong)+0.001)] > but this returned me zero results.The next option would be the code to return > me at least the place that falls outside but still is close to that region.'Do you > have any idea how to do that and not fall back in the time consuming look at > each element iteration?Well, in a sense R has already looked at every element of Longitude to get Min and Max, so you're not avoiding that. But wouldn't something like which.min( c( GPSLong-Longitude, GPSLat-latitude )^2 ) return the index of the closest Latitude/Longitude pair to your GPS location? And once you have the distances you could use order() or rank() to pick the top 5 (maybe using head()) or just rank() on the distances. And once you've picked a set you can still additionally check whether a location was within the box. S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}