I have a line shapefile representing a road network. I wish to rasterize this data, with the resulting values in the raster showing the total length of the lines that fall within the raster cell.
The data is in the British National Grid projection so the units will be meters.
Ideally I would like to perform this operation using R
, and i'm guessing that the rasterize
function from the raster
package would play a part in achieving this, I just can't work out what the function applied should be.
Best Answer
You can now do this with
terra::rasterizeGeom
Example data:
Solution:
The below is a solution with the older spatial packages. It is based on Jeffrey Evans' answer, but this one is much faster as it does not use rasterize