Re: [R-sig-Geo] extract values to points
Dear list, thank you very much for all the many suggestions on how to extract values to points! I ended up using the RSAGA package with the pick.from.ascii.grid() function. Cheers, Frauke Date: Tue, 10 Mar 2009 20:19:17 +0800 Subject: Re: [R-sig-Geo] extract values to points From: r.hijm...@gmail.com To: p.hiems...@geo.uu.nl CC: ks...@mail.orn.mpg.de; r-sig-geo@stat.math.ethz.ch; fkbarthol...@hotmail.com Just for the record. this is how I would do this with the raster package (Kamran's example should work, but seems a bit unnecessarily complex; just what we are trying to avoid with that package :): install.packages(raster, repos=http://R-Forge.R-project.org;) library(raster) xy - your matrix raster - rasterFromFile(C:/yourfile) v - xyValues(raster, xy) xyv - cbind(xy, v) Robert On Tue, Mar 10, 2009 at 7:50 PM, Paul Hiemstra p.hiems...@geo.uu.nl wrote: Hi, Funny to see how you can do things in multiple ways in R :). To add to the possibilities, you could probably also get this functionality using R and Grass. I would personally recommend to use overlay() as you don't have to install anything apart from the sp package, unlike using rsaga and SAGA. Especially if the only thing you want is to do an overlay. When there was other SAGA specific functionality you needed, SAGA would be a good option. In addition to not having to install a lot of software, overlay() has been used extensively, this in contrast to the raster package which is still experimental. But this is strictly my personal opinion ofcourse :). cheers, Paul Kamran Safi Radolfzell wrote: Hi all, the raster package is although in its alpha stage very helpful in this respect: install.packages(raster, repos=http://R-Forge.R-project.org;) library(raster) library(maptools) X - Y - raster - rasterFromFile(C:/yourfile) (result - data.frame(Long=x, Lat=y, Value=xyValues(raster, matrix(c(x,y), ncol=2) That should work. Remember to take out the install.package after initial install. Of course you can work with several coordinates. Peadagogically better is the overlay() function... Very straight forward. Kami On Tue, 10 Mar 2009 11:04:23 +0100, Paul Hiemstra wrote Hi, An option using only R is to use the overlay() command from the sp package, try running this example: # Load data library(sp) data(meuse) # point data coordinates(meuse) = ~x+y data(meuse.grid) # grid data gridded(meuse.grid) = ~x+y overlay(meuse.grid, meuse) # Returns the indices in meuse.grid correpsonding to the points in meuse # get the data from meuse.grid, for example the column dist # a non spatial vector dist = meuse.grid$dist[overlay(meuse.grid, meuse)] # A spatialPointsDataFrame dist = meuse.grid[overlay(meuse.grid, meuse), dist] Also check out the rgdal pacakge to get your data into R-spatial objects. cheers, Paul Frauke Barthold wrote: Dear list, I have a soilmap as an Ascii grid and a dataframe with x and y coordinates (these are sampling points). I would now like to extract values from the soilmap to the dataframe based on location, the x and y values. Is there any way to do this in R? Cheers, Frauke _ [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Open WebMail Project (http://openwebmail.org) -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo _ [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] extract values to points
Hi, An option using only R is to use the overlay() command from the sp package, try running this example: # Load data library(sp) data(meuse) # point data coordinates(meuse) = ~x+y data(meuse.grid) # grid data gridded(meuse.grid) = ~x+y overlay(meuse.grid, meuse) # Returns the indices in meuse.grid correpsonding to the points in meuse # get the data from meuse.grid, for example the column dist # a non spatial vector dist = meuse.grid$dist[overlay(meuse.grid, meuse)] # A spatialPointsDataFrame dist = meuse.grid[overlay(meuse.grid, meuse), dist] Also check out the rgdal pacakge to get your data into R-spatial objects. cheers, Paul Frauke Barthold wrote: Dear list, I have a soilmap as an Ascii grid and a dataframe with x and y coordinates (these are sampling points). I would now like to extract values from the soilmap to the dataframe based on location, the x and y values. Is there any way to do this in R? Cheers, Frauke _ [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] extract values to points
Hi, Funny to see how you can do things in multiple ways in R :). To add to the possibilities, you could probably also get this functionality using R and Grass. I would personally recommend to use overlay() as you don't have to install anything apart from the sp package, unlike using rsaga and SAGA. Especially if the only thing you want is to do an overlay. When there was other SAGA specific functionality you needed, SAGA would be a good option. In addition to not having to install a lot of software, overlay() has been used extensively, this in contrast to the raster package which is still experimental. But this is strictly my personal opinion ofcourse :). cheers, Paul Kamran Safi Radolfzell wrote: Hi all, the raster package is although in its alpha stage very helpful in this respect: install.packages(raster, repos=http://R-Forge.R-project.org;) library(raster) library(maptools) X - Y - raster - rasterFromFile(C:/yourfile) (result - data.frame(Long=x, Lat=y, Value=xyValues(raster, matrix(c(x,y), ncol=2) That should work. Remember to take out the install.package after initial install. Of course you can work with several coordinates. Peadagogically better is the overlay() function... Very straight forward. Kami On Tue, 10 Mar 2009 11:04:23 +0100, Paul Hiemstra wrote Hi, An option using only R is to use the overlay() command from the sp package, try running this example: # Load data library(sp) data(meuse) # point data coordinates(meuse) = ~x+y data(meuse.grid) # grid data gridded(meuse.grid) = ~x+y overlay(meuse.grid, meuse) # Returns the indices in meuse.grid correpsonding to the points in meuse # get the data from meuse.grid, for example the column dist # a non spatial vector dist = meuse.grid$dist[overlay(meuse.grid, meuse)] # A spatialPointsDataFrame dist = meuse.grid[overlay(meuse.grid, meuse), dist] Also check out the rgdal pacakge to get your data into R-spatial objects. cheers, Paul Frauke Barthold wrote: Dear list, I have a soilmap as an Ascii grid and a dataframe with x and y coordinates (these are sampling points). I would now like to extract values from the soilmap to the dataframe based on location, the x and y values. Is there any way to do this in R? Cheers, Frauke _ [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Open WebMail Project (http://openwebmail.org) -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] extract values to points
Just for the record. this is how I would do this with the raster package (Kamran's example should work, but seems a bit unnecessarily complex; just what we are trying to avoid with that package :): install.packages(raster, repos=http://R-Forge.R-project.org;) library(raster) xy - your matrix raster - rasterFromFile(C:/yourfile) v - xyValues(raster, xy) xyv - cbind(xy, v) Robert On Tue, Mar 10, 2009 at 7:50 PM, Paul Hiemstra p.hiems...@geo.uu.nl wrote: Hi, Funny to see how you can do things in multiple ways in R :). To add to the possibilities, you could probably also get this functionality using R and Grass. I would personally recommend to use overlay() as you don't have to install anything apart from the sp package, unlike using rsaga and SAGA. Especially if the only thing you want is to do an overlay. When there was other SAGA specific functionality you needed, SAGA would be a good option. In addition to not having to install a lot of software, overlay() has been used extensively, this in contrast to the raster package which is still experimental. But this is strictly my personal opinion ofcourse :). cheers, Paul Kamran Safi Radolfzell wrote: Hi all, the raster package is although in its alpha stage very helpful in this respect: install.packages(raster, repos=http://R-Forge.R-project.org;) library(raster) library(maptools) X - Y - raster - rasterFromFile(C:/yourfile) (result - data.frame(Long=x, Lat=y, Value=xyValues(raster, matrix(c(x,y), ncol=2) That should work. Remember to take out the install.package after initial install. Of course you can work with several coordinates. Peadagogically better is the overlay() function... Very straight forward. Kami On Tue, 10 Mar 2009 11:04:23 +0100, Paul Hiemstra wrote Hi, An option using only R is to use the overlay() command from the sp package, try running this example: # Load data library(sp) data(meuse) # point data coordinates(meuse) = ~x+y data(meuse.grid) # grid data gridded(meuse.grid) = ~x+y overlay(meuse.grid, meuse) # Returns the indices in meuse.grid correpsonding to the points in meuse # get the data from meuse.grid, for example the column dist # a non spatial vector dist = meuse.grid$dist[overlay(meuse.grid, meuse)] # A spatialPointsDataFrame dist = meuse.grid[overlay(meuse.grid, meuse), dist] Also check out the rgdal pacakge to get your data into R-spatial objects. cheers, Paul Frauke Barthold wrote: Dear list, I have a soilmap as an Ascii grid and a dataframe with x and y coordinates (these are sampling points). I would now like to extract values from the soilmap to the dataframe based on location, the x and y values. Is there any way to do this in R? Cheers, Frauke _ [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Open WebMail Project (http://openwebmail.org) -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] extract values to points
Hi Frauke, in the RSAGA package there is a function pick.from.ascii.grid which does exactly what you want. Even works with large grids as it can process them row by row. I use it for extracting point data from stacks of Landsat bands, terrain attributes etc. Here a case study (landslide susceptibility modeling): http://www.environment.uwaterloo.ca/u/brenning/Brenning-2008-RSAGA.html also available as pdf: http://www.environment.uwaterloo.ca/u/brenning/Brenning-2008-RSAGA.pdf I hope this helps Cheers Alex Frauke Barthold wrote: Dear list, I have a soilmap as an Ascii grid and a dataframe with x and y coordinates (these are sampling points). I would now like to extract values from the soilmap to the dataframe based on location, the x and y values. Is there any way to do this in R? Cheers, Frauke _ [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Alexander Brenning brenn...@uwaterloo.ca - T +1-519-888-4567 ext 35783 Department of Geography and Environmental Management University of Waterloo 200 University Ave. W - Waterloo, ON - Canada N2L 3G1 http://www.fes.uwaterloo.ca/geography/faculty/brenning/ ___ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo