Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
R
 
 
 
 
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

CRAN_Status_Badge CRAN_Downloads_Badge

Introduction

shadow is an R package for geometric shadow calculations in an urban environment. A detailed description can be found in the R Journal paper (2019):

Abstract

Installation

CRAN version:

install.packages("shadow")

GitHub version:

install.packages("remotes")
remotes::install_github("michaeldorman/shadow")

Quick demo

library(shadow)
#> Loading required package: sp
library(raster)

# Point
location = rgeos::gCentroid(build)

# Time
time = as.POSIXct(
  "2004-12-24 13:30:00",
  tz = "Asia/Jerusalem"
  )

# Location in geographical coordinates
location_geo = sp::spTransform(
  location,
  "+proj=longlat +datum=WGS84"
  )

# Solar position
solar_pos = maptools::solarpos(
  crds = location_geo,
  dateTime = time
  )
solar_pos
#>          [,1]     [,2]
#> [1,] 208.7333 28.79944

# Shadow height at a single point
h = shadowHeight(
  location = location,
  obstacles = build,
  obstacles_height_field = "BLDG_HT",
  solar_pos = solar_pos
  )
#> Warning in proj4string(location): CRS object has comment, which is lost in
#> output
#> Warning in proj4string(obstacles): CRS object has comment, which is lost in
#> output
#> Warning in sp::proj4string(from): CRS object has comment, which is lost in
#> output
#> Warning in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td,
#> unaryUnion_if_byid_false, : spgeom1 and spgeom2 have different proj4 strings

# Result
h
#>          [,1]
#> [1,] 19.86451

# Visualization
sun = shadow:::.sunLocation(
  location = location,
  sun_az = solar_pos[1, 1],
  sun_elev = solar_pos[1, 2]
  )
sun_ray = ray(from = location, to = sun)
#> Warning in sp::proj4string(from): CRS object has comment, which is lost in
#> output
build_outline = as(build, "SpatialLinesDataFrame")
inter = rgeos::gIntersection(build_outline, sun_ray)
#> Warning in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td,
#> unaryUnion_if_byid_false, : spgeom1 and spgeom2 have different proj4 strings
plot(build)
plot(sun_ray, add = TRUE, col = "yellow")
plot(location, add = TRUE)
text(location, paste(round(h, 2), "m"), pos = 3)
plot(inter, add = TRUE, col = "red")

# Raster template
ext = as(raster::extent(build)+50, "SpatialPolygons")
r = raster::raster(ext, res = 2)
proj4string(r) = proj4string(build)
#> Warning in proj4string(build): CRS object has comment, which is lost in output

# Shadow height surface
height_surface = shadowHeight(
  location = r,
  obstacles = build,
  obstacles_height_field = "BLDG_HT",
  solar_pos = solar_pos,
  parallel = 2
)
#> Warning in proj4string(location): CRS object has comment, which is lost in
#> output
#> Warning in proj4string(obstacles): CRS object has comment, which is lost in
#> output

# Visualization
plot(height_surface, col = grey(seq(0.9, 0.2, -0.01)))
contour(height_surface, add = TRUE)
plot(build, add = TRUE, border = "red")
text(rgeos::gCentroid(build, byid = TRUE), build$BLDG_HT)
text(location, paste(round(h, 2), "m"), pos = 3, col = "red", font = 2)
plot(sun_ray, add = TRUE, col = "yellow")
plot(inter, add = TRUE, col = "red")
plot(location, add = TRUE)

About

R Package for Geometric Shadow Calculations

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.