# NOT RUN {
# Method for 3D points - Manually defined
opar = par(mfrow = c(1, 3))
# Ground level
location = sp::spsample(
rgeos::gBuffer(rgeos::gEnvelope(build), width = 20),
n = 80,
type = "regular"
)
solar_pos = as.matrix(tmy[9, c("sun_az", "sun_elev")])
s = inShadow(
location = location,
obstacles = build,
obstacles_height_field = "BLDG_HT",
solar_pos = solar_pos
)
plot(location, col = ifelse(s[, 1], "grey", "yellow"), main = "h=0")
plot(build, add = TRUE)
# 15 meters above ground level
coords = coordinates(location)
coords = cbind(coords, z = 15)
location1 = SpatialPoints(coords, proj4string = CRS(proj4string(location)))
solar_pos = as.matrix(tmy[9, c("sun_az", "sun_elev")])
s = inShadow(
location = location1,
obstacles = build,
obstacles_height_field = "BLDG_HT",
solar_pos = solar_pos
)
plot(location, col = ifelse(s[, 1], "grey", "yellow"), main = "h=15")
plot(build, add = TRUE)
# 30 meters above ground level
coords = coordinates(location)
coords = cbind(coords, z = 30)
location2 = SpatialPoints(coords, proj4string = CRS(proj4string(location)))
solar_pos = as.matrix(tmy[9, c("sun_az", "sun_elev")])
s = inShadow(
location = location2,
obstacles = build,
obstacles_height_field = "BLDG_HT",
solar_pos = solar_pos
)
plot(location, col = ifelse(s[, 1], "grey", "yellow"), main = "h=30")
plot(build, add = TRUE)
par(opar)
# Shadow on a grid covering obstacles surface
# }
# NOT RUN {
# Method for 3D points - Covering building surface
obstacles = build[c(2, 4), ]
location = surfaceGrid(
obstacles = obstacles,
obstacles_height_field = "BLDG_HT",
res = 2,
offset = 0.01
)
solar_pos = tmy[c(9, 16), c("sun_az", "sun_elev")]
solar_pos = as.matrix(solar_pos)
s = inShadow(
location = location,
obstacles = obstacles,
obstacles_height_field = "BLDG_HT",
solar_pos = solar_pos
)
location$shadow = s[, 1]
plotGrid(location, color = c("yellow", "grey")[as.factor(location$shadow)], size = 0.5)
location$shadow = s[, 2]
plotGrid(location, color = c("yellow", "grey")[as.factor(location$shadow)], size = 0.5)
# Method for ground locations raster
ext = as(raster::extent(build) + 20, "SpatialPolygons")
location = raster::raster(ext, res = 2)
proj4string(location) = proj4string(build)
obstacles = build[c(2, 4), ]
solar_pos = tmy[c(9, 16), c("sun_az", "sun_elev")]
solar_pos = as.matrix(solar_pos)
s = inShadow( ## Using 'solar_pos'
location = location,
obstacles = obstacles,
obstacles_height_field = "BLDG_HT",
solar_pos = solar_pos,
parallel = 3
)
time = as.POSIXct(tmy$time[c(9, 16)], tz = "Asia/Jerusalem")
s = inShadow( ## Using 'time'
location = location,
obstacles = obstacles,
obstacles_height_field = "BLDG_HT",
time = time,
parallel = 3
)
plot(s)
# Method for pre-calculated shadow height raster
ext = as(raster::extent(build), "SpatialPolygons")
r = raster::raster(ext, res = 1)
proj4string(r) = proj4string(build)
r[] = rep(seq(30, 0, length.out = ncol(r)), times = nrow(r))
location = surfaceGrid(
obstacles = build[c(2, 4), ],
obstacles_height_field = "BLDG_HT",
res = 2,
offset = 0.01
)
s = inShadow(
location = location,
shadowHeightRaster = r
)
location$shadow = s[, 1]
r_pnt = raster::as.data.frame(r, xy = TRUE)
coordinates(r_pnt) = names(r_pnt)
proj4string(r_pnt) = proj4string(r)
r_pnt = SpatialPointsDataFrame(
r_pnt,
data.frame(
shadow = rep(TRUE, length(r_pnt)),
stringsAsFactors = FALSE
)
)
pnt = rbind(location[, "shadow"], r_pnt)
plotGrid(pnt, color = c("yellow", "grey")[as.factor(pnt$shadow)], size = 0.5)
# Automatically calculating 'solar_pos' using 'time' - Points
location = sp::spsample(
rgeos::gBuffer(rgeos::gEnvelope(build), width = 20),
n = 500,
type = "regular"
)
time = as.POSIXct("2004-12-24 13:30:00", tz = "Asia/Jerusalem")
s = inShadow(
location = location,
obstacles = build,
obstacles_height_field = "BLDG_HT",
time = time
)
plot(location, col = ifelse(s[, 1], "grey", "yellow"), main = time)
plot(build, add = TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab