Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through many rasters in a folder and extract values using a point shapefile

Tags:

r

raster

How do I loop through all rasters (TIFF) in a folder and extract values using a point shapefile which has several coordinates then have the output as a dataframe?

like image 488
jmutua Avatar asked Nov 24 '25 21:11

jmutua


1 Answers

library(raster)
library(rgdal)

files <- list.files(path=".", pattern="tif$", full.names=TRUE) # select all the tiff files in the directory
s <- stack(files) # stack all of them using r raster library
shp <- shapefile("points.shp") # read the point shape file
ext <- extract(s, shp) # extract the values from raster stack.
like image 174
Geo-sp Avatar answered Nov 26 '25 11:11

Geo-sp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!