I want to extract values from a raster file containing gridded population in US (spatial resolution of 1X1 km) based on points shapefile, also in US.

Both are in the projection.

Here is my code:

# The points layer
USGridSite <- readRDS("USGridSite.rds")
writeOGR(USGridSite, "USGridSite.shape.file", "USGridSite.shape.file", driver = "ESRI Shapefile")

# The raster file    

# Extracting mean population from the raster
gridded_population_mean <- extract(gridded_population,
                                  USGridSiteCoords, # should it be the USGridSite file?
                                  sp = TRUE, # create spatial object
                                  buffer = 1000) # I want 1X1 km results

It is not working, am I doing something wrong?

  • Can you print the outputs of each of them? Would like to see why this is going wrong. – Vijay Ramesh Jan 24 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.