Reputation: 1
I have a spatial points file which has a list of coordinates for sample sites. I need to find how close each of these sample sites is to highly human-modified areas. I'm using the global human modification index (https://sedac.ciesin.columbia.edu/data/set/lulc-human-modification-terrestrial-systems), which is in raster format. For each point (sample site), I need to find the shortest distance to the nearest raster grid cell that has a value > 0.7. Is there a way in R to select the nearest grid cell with a value > 0.7 and then calculate the distance between this (probably the central point of the cell?) and my other points?
I have too many sites to calculate the distance manually.
So, my final dataframe would have a column for site number, latitude, longitude, and distance to high human modification.
I may opening a whole other can of worms by saying that I preferably need the distance in km - can I do this by converting the CRS of my points and raster to UTM with units=m first?
Thanks in advance!
Upvotes: 0
Views: 402
Reputation: 1
I created a vector out of the specific values of the raster and applied the distance() to that so:
# Extract the values larger than 0.7 from the raster
value_lt <- ifel(cell_value >0.7 ,1, NA)
# Convert to a polygon
value_lt_sf <- value_lt %>%
as.polygons()
# calculate distance of points to the polygon
dist_to_value <- distance(points, value_lt_sf)
Upvotes: 0