I have a shapefile with several
MULTILINESTRING geometries, representing the borders of some species' distributions, and I want to count the number the number of species occurring in each cell.
I used the
rasterize function from the
count.sp <- terra::rasterize(sp.lines, rast.w, fun = "count")
As an example, the lines in the figure below represent the borders of the distribution of a given species "X":
In the example, species' distribution was subdivided into several disjoint parts crossing the same raster pixel. With the code above, I got as a result the number of parts in each pixel (8 and 5, respectively), whereas I would like to get all the parts belonging to the same species and crossing the same pixel be counted as a single occurrence (i.e., I would like to get 1 in both pixels in the example below).
I also tried the function "sum" (with no field, and I obtained 208 and 130, I don't understand what these values represent)
What I am missing?