TransWikia.com

Calculating raster cell for total length of street segment with weighted-overlay on centrality value using R

Geographic Information Systems Asked by fhakulachang on June 5, 2021

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 the Q&A at Convert line shapefile to raster, value=total length of lines within cell

However, 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))

writeRaster(r,'r.tif') 

sss

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP