0
votes

I am trying to extract the values of pixels in a DSM(CHM) within digitized tree crowns.

first I set my working directory read in the shapefile and raster.

TreeCrowns <-shapefile("plot1sag_shape/plot1sag.shp")
CHM <- raster('272280split4.tif')

Then I try to extract the pixel values

pixel <- raster::extract(CHM, TreeCrowns, method= 'simple', weights=FALSE, fun=NULL)

But I get an empty list with all NULL values for every polygon. I have confirmed that the CHM and polygons are in the same location. What can I do to fix this?

2

2 Answers

0
votes

Since your shapefile consists of polygon, the extract() function need to know how to summarise the pixel values across a polygon via the fun= argument. Since you provide fun=NULL, the function interpret as returning NULL values to summarise the pixel values.

Try fun=mean or fun=sum (and they mean different thing so see which one suits you).

0
votes

That probably happens because the polygons and the raster do not overlap. Can you show(CHM) and TreeCrowns? Have you looked at

plot(CHM)
lines(TreeCrowns)

Or are your polygons very small relative to the raster cells? In that case try argument small=TRUE