[R] How to find data in a map according to coordinates?
jeff6868
geoffrey_klein at etu.u-bourgogne.fr
Thu Aug 9 08:56:12 CEST 2012
Hello,
I have created a spatial map of temperature over an area thanks to
interpolation. So I have temperature data everywhere on my map.
My question is: how can I find temperature data on my map for a specific
location according to coordinates?
For this, I have a data frame containing 4 columns: "x" for longitude, "y"
for latitude, "z" for altitude" and "temperature" for my data, for each
pixel of my map. My real data has more than 9 million of rows (because I
have a temperature data for each 0.0008° of longitude or latitude).
Let's take a smallest example with 10 rows and so just 1° of LAT and LON for
each pixel (just with "x", "y" and my data):
test <- data.frame(x=c(1:10),y=c(41:50),temperature=rnorm(1:10))
In this example, I would like to ask the user of the algorithm to type on R
the coordinates (x and y) for which the user wants the temperature.
For example:
cat("choose your coordinates:\n")
x: "HERE THE USER SHOULD TYPE A NUMERIC VALUE"
y: "HERE THE USER SHOULD TYPE A NUMERIC VALUE"
and then R gives the value for temperature (in my third column).
In this example, if the user type 6 for "x" and "46" for y, R should give
as a result: "0.9713693"
And if the coordinates typed by the user are between the coordinates in my
data.frame, it should response the temperature value of the nearest pixel.
For example, if the user type 3.89 for "x" and 43.62 for "y", R should give
as a result: "0.6871172" (value of the nearest pixel: 4 for "x" and 44 for
"y").
I absolutely don't know how to do this, and if it's easy to do or not. I
didn't find anything about it on the web for R.
Have you any idea or suggestions about a package, function or a way to do
this?
Hope you've understood!
thanks everybody!
--
View this message in context: http://r.789695.n4.nabble.com/How-to-find-data-in-a-map-according-to-coordinates-tp4639724.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list