2010-07-26

Extracting Raster Values from Points in R and GRASS

A common task in GIS analysis is to extract the value of a remotely sensed environmental variable at a point location. For instance we may wish to extract the elevation of a field plot from a digital elevation model. The elevation data is a raster (i.e. grid) and the plots are a point shapefile (or a simple text file of X, Y locations). The command for doing this in ArcGIS is ExtractValuesToPoints available in the Spatial Analyst package. Situations may arise where ArcGIS is not the most efficient way of extracting these values. So, here, I provide a brief overview of how to extract raster values to points in R and GRASS.

Extract Values to Points in R

This is strikingly easy is R. My work usually requires more statistical sophistication than is available in ArcGIS. As a result, I have completely switched to doing the extraction in R. I known I am going to end in R eventually, and it is easier to automate than writing a long python script in ArcGIS.

Data required

For the purpose of this exercise. All the data must be have the same spatial projection.

gr.asc
an ESRI ASCII grid. This could also be an ArcGIS binary grid if you know how to use RGDAL. That perhaps will be another post.
pt.shp
a point shapefile.

You also need the maptools and sp packages.

The Code

That is it. Fast, and easy.

Extracting Values in GRASS

Extracting raster values in GRASS is somewhat faster than in R, but it takes a little bit more planning in that you have to explicitly create the column that the raster values will go into.

Data Required

  • gr : A GRASS grid
  • pt : A GRASS point dataset

The Code

The basic flow of this is that you create an empty column in the point dataset with the right data type (i.e. varchar(10) string of length 10, double precision floating point numbers, int integers). Then, fill the column with the raster values.

Labels: , ,

22 Comments:

Blogger Lori said...

Can this be done with multiple ASCIIs at the same time? I want to extract WorldClim variables to species presence points.

June 22, 2011 at 12:35 PM  
Blogger Ashis said...

Dear Todd,
Thanks for the nice posting.

I modified your solution according to my need(skipped the grass part and make workable for multiple raster files) and posted my solution in http://gis-techniques.blogspot.com/2012/10/extract-raster-values-from-points.html.

October 11, 2012 at 6:01 PM  
Blogger Sourav Tiwari said...

Thanks for the Great Information in the post


Egovtjobs

February 6, 2016 at 1:13 AM  
Blogger Govtapply said...

Latest Govtapply Jobs 2016

Thanks to sharing this nice information i really appreciate your thinking.......

February 15, 2016 at 4:23 AM  
Blogger Nitish Lakhera said...

Result

February 22, 2016 at 7:15 AM  
Blogger raphael said...

Wow amazing i saw this article with execution models you had posted. It was such informative. Really its a wonderful article. Thank you for sharing.

digital marketing training Chennai

February 26, 2016 at 12:23 AM  
Blogger henris said...

Thank you for posting it will be helpful by knowing more about GDAL. Thank you and please keep update like this with this site. Definitely it will be useful for all.


SQL DBA Training in Chennai

March 4, 2016 at 4:03 AM  
Blogger Konnie said...

Hi. When I run the R code with m data I'm getting following error message:

Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialGridDataFrame", "SpatialPointsDataFrame"’.

Any ideas why? regards, Konnie

March 18, 2016 at 9:06 PM  
Blogger Ridhima said...

Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up.

SEO training in Adyar

April 2, 2016 at 11:07 AM  
Blogger Dianne Wiest said...

It's nice blog I have really enjoyed keeping up with you on this blog.This is very useful post for everyone. Thank you so much this post.


__________________________
Washington dc dog training

April 7, 2016 at 1:01 AM  
Blogger pankaj karnwal said...

Nice article thanks for sharing with us.
ap 12th result 2016

April 19, 2016 at 7:15 AM  
Blogger pankaj karnwal said...

Nice article thanks for sharing with us.
telangana intermediate result 2016

April 20, 2016 at 3:15 AM  
Blogger subrata das said...

good morning images
good night images
rrb result 2016
whatsapp status
irctc online ticket booking
tatkal ticket booking
irctc.co.in
bsf.nic.in
best 10 exam result website

May 26, 2016 at 1:56 PM  
Blogger Souvik Das said...

putlocker

June 1, 2016 at 5:46 PM  
Blogger Training Coimbatore said...

great post

Hadoop training in coimbatore
Java training in coimbatore
Oracle training in coimbatore
Informatica training in coimbatore
Oracle training in coimbatore
Informatica training in coimbatore

June 22, 2016 at 11:26 AM  
Blogger pankaj karnwal said...

Nice article thanks for sharing with us.
ugc net answer key

July 10, 2016 at 3:25 AM  
Blogger pankaj karnwal said...

Nice article thanks for sharing with us.
ctet
ctet application form
ctet exam date
ctet notification
ctet admit card
ctet result
ctet online form
ctet answer key
ctet answer key
ctet
reet

July 17, 2016 at 5:04 AM  
Blogger Tony Starck said...

Top 10 lists
Tattoos
Tattoos
Tattoos
Tattoos

August 14, 2016 at 10:13 AM  
Blogger Koushik Mishra said...

megashare

megashare.info

megashare movie

September 7, 2016 at 5:47 AM  
Blogger Ashu Sharma said...

CTET Result 2016 will be going to be publishes soon by Central Board of Secondary Education. Download CTET Result 2016 as soon as possible once declared out.

November 4, 2016 at 5:43 AM  
Blogger Kate said...

http://tattoosboygirl.com/

November 21, 2016 at 6:03 AM  
Blogger Narendra Modi said...

Recruitment Notification is one of the Top most Job Portal Govt jobs in AP 2017 there

November 25, 2016 at 12:56 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home