# NOT RUN {
# Single location
location = rgeos::gCentroid(build)
location_geo = matrix(c(34.7767978098526, 31.9665936050395), ncol = 2)
time = as.POSIXct("2004-12-24 13:30:00", tz = "Asia/Jerusalem")
solar_pos = maptools::solarpos(location_geo, time)
plot(build, main = time)
plot(location, add = TRUE)
sun = shadow:::.sunLocation(location = location, sun_az = solar_pos[1,1], sun_elev = solar_pos[1,2])
sun_ray = ray(from = location, to = sun)
build_outline = as(build, "SpatialLinesDataFrame")
inter = rgeos::gIntersection(build_outline, sun_ray)
plot(sun_ray, add = TRUE, col = "yellow")
plot(inter, add = TRUE, col = "red")
shadowHeight(
location = location,
obstacles = build,
obstacles_height_field = "BLDG_HT",
solar_pos = solar_pos
)
# Automatically calculating 'solar_pos' using 'time'
proj4string(build) = CRS("+init=epsg:32636")
proj4string(location) = CRS("+init=epsg:32636")
shadowHeight(
location = location,
obstacles = build,
obstacles_height_field = "BLDG_HT",
time = time
)
# }
# NOT RUN {
# Two points - three times
location0 = rgeos::gCentroid(build)
location1 = raster::shift(location0, 0, -15)
location2 = raster::shift(location0, -10, 20)
locations = rbind(location1, location2)
time = as.POSIXct("2004-12-24 13:30:00", tz = "Asia/Jerusalem")
times = seq(from = time, by = "1 hour", length.out = 3)
shadowHeight( ## Using 'solar_pos'
location = locations,
obstacles = build,
obstacles_height_field = "BLDG_HT",
solar_pos = maptools::solarpos(location_geo, times)
)
shadowHeight( ## Using 'time'
location = locations,
obstacles = build,
obstacles_height_field = "BLDG_HT",
time = times
)
# Grid - three times
time = as.POSIXct("2004-12-24 13:30:00", tz = "Asia/Jerusalem")
times = seq(from = time, by = "1 hour", length.out = 3)
ext = as(raster::extent(build), "SpatialPolygons")
r = raster::raster(ext, res = 2)
proj4string(r) = proj4string(build)
x = Sys.time()
shadow1 = shadowHeight(
location = r,
obstacles = build,
obstacles_height_field = "BLDG_HT",
time = times,
parallel = 3
)
y = Sys.time()
y - x
x = Sys.time()
shadow2 = shadowHeight(
location = r,
obstacles = build,
obstacles_height_field = "BLDG_HT",
solar_pos = solarpos2(r, times),
parallel = 3
)
y = Sys.time()
y - x
shadow = shadow1
opar = par(mfrow = c(1, 3))
for(i in 1:raster::nlayers(shadow)) {
plot(shadow[[i]], col = grey(seq(0.9, 0.2, -0.01)), main = raster::getZ(shadow)[i])
raster::contour(shadow[[i]], add = TRUE)
plot(build, border = "red", add = TRUE)
}
par(opar)
# }
Run the code above in your browser using DataLab