How to calculate raster cell for total length of street segment with weighted-overlay on centrality value?

I have completed the centrality calculation from the OSM database. I want to convert the data into a raster format for crossing analysis with other variables in R.

I have followed this topic [r - Convert line shapefile to raster, value=total length of lines within cell - Geographic Information Systems Stack Exchange](https://Convert line shapefile to raster, value=total length of lines within cell)

But I wish to add the weight value of centrality in the raster cell. I wonder which part I could add more procedure on weight overlay calculation?

library(raster)
library(rgdal)
library(rgeos)
roads <- shapefile("edges_bom.shp")
roads <- spTransform(roads, CRS("+proj=utm +zone=37 +south +datum=WGS84"))
rs <- raster(extent(roads), crs=projection(roads))
rs <- 1:ncell(rs)
rsp <- rasterToPolygons(rs)
rp <- intersect(roads, rsp)
rp$length <- gLength(rp, byid=TRUE) / 1000
x <- tapply(rp$length, rp$layer, sum)
r <- raster(rs)
r[as.integer(names(x))] <- x
plot(r)
require(RColorBrewer)
spplot(r, scales = list(draw=TRUE), xlab="x", ylab="y",
col.regions=colorRampPalette(brewer.pal(9, "YlOrRd")),
sp.layout=list("sp.lines", rp),
par.settings=list(fontsize=list(text=15)), at=seq(0, 1800, 200))
library(sp)
library(raster)
library(RColorBrewer)
require(RColorBrewer)
spplot(r, scales = list(draw=TRUE), xlab="x", ylab="y",
col.regions=colorRampPalette(brewer.pal(9, "YlOrRd")),
sp.layout=list("sp.lines", rp),
par.settings=list(fontsize=list(text=15)), at=seq(0, 1800, 200))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.