[GIS] How to extract raster attributes by lat/long location

rraster

How can you extract an attribute value from a raster from a point (lat/long)?

Example data: Raster with attribute table – value of interest is temperature

I have a list of points with lat/long values, which I want to extract the temperature values for. The raster contains multiple attribute values, temp is not the "pixel" value

Best Answer

As it is you do not include a reproducible example. But assuming you're using R and you have a single layer raster:

location = data.frame(x = -68.8901643,
                      y = 44.9142272)
coordinates(location) <- ~x+y
mypoints = SpatialPoints(location,proj4string = CRS("+init=epsg:4326"))

myproj = CRS(myraster)
points.proj = spTransform(mypoints, myproj)
myvalues = extract(raster, points.proj)

If you have more than one lat/long pair you can extract everything at once by using a data.frame with more rows, e.g.:

location = data.frame(x = c(-68.8901643,-70,-72,-74),
                      y = c(44.9142272,45,47,49))