Daniel
Daniel

Reputation: 1

Getting unique ids summed in rasterize function

I have got these lines of code:

r_res1 <- raster(extent(-180, 180, -90, 90), res = 1)
rasterized_shapefile <- rasterize(shapefile.shp, r_res1, field = "id_no", fun = "count")

In this way, I am able to sum the number of polygons overlapping raster grid cells based on the id_no column. Or in other words, I know how many unique id_no's overlap the corresponding grid cell.

However, I would also like to see which specific id_no's were taken into the count. The ideal output would be a data frame of grid cells with the corresponding id_no.

Do you know how to build a code that would do that?

Massive thanks

I among many other things tried this code:

rasterized_shapefile <- rasterize(shapefile.shp, r_res1, field = "id_no", fun = function(x) unique(x$id_no), progress = "text")

but it doesn´t work.

Upvotes: 0

Views: 18

Answers (0)

Related Questions