My goal is to create a 3D visualization in R. I have a shape file for the city blocks (Ortsteile) in Berlin and want to emphasize the value (inhabitants / km²) as z-value. I embedded the shapefile into R and colored the value for desnity ("Einwohnerd") as follows:
library(rgdal)
library(sp)
berlin=readOGR(dsn="C...etc.", layer="Ortsteile")
berlin@data
col <- rainbow(length(levels(berlin@data$Name)))
spplot(berlin, "Einwohnerd", col.regions=col, main="Ortsteil Berlins", sub="Datensatz der Stadt Berlin", lwd=.8, col="black")
How can a certain polygon (urban district) be attributed to the z value (resident / km²) and how can I distinguish this z value?
Hope someone will have an answer! Best Regan SB
Thanks for the answer, but I'm still on my way to find out how to use density as a z-value so that I can create a 3D model. I learned that it is impossible to use shape polygons, but you can rasterize a polygon and use the matrix for a different perspective and rotation.
, 3D- . , z , , z:
library(rgdal)
library(sp)
setwd("C:\\...")
berlin=readOGR(dsn="C:\\...\\Ortsteile", layer="Ortsteile")
col <- rainbow(length(levels(berlin@data$Name)))
spplot(berlin, "Einwohnerd", col.regions=col, main="Ortsteil Berlins",
sub="Datensatz der Stadt Berlin", lwd=.8, col="black")
library(raster)
raster <- raster(nrows=100, ncols=200, extent(berlin))
test <- rasterize(berlin, raster, field="Einwohnerd")
persp(test, theta = 40, phi = 40, col = "gold", border = NA, shade = 0.5)
for(i in seq(0,90,10)){
persp(test, theta = 40, phi = i, col = "gold", border = NA, shade = 0.5)
}
library(rgl)
library(colorRamps)
mat <- matrix(test[], nrow=test@nrows, byrow=TRUE)
image(mat)
persp3d(z = mat, clab = "m")
persp3d(z = mat, col = rainbow(10),border = "black")
persp3d(z = mat, facets = FALSE, curtain = TRUE)