diff --git a/DESCRIPTION b/DESCRIPTION index 2c85084..8fa3a0f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: superblock Type: Package Title: Analyses of potential superblock -Version: 0.1.0.110 +Version: 0.1.0.111 Authors@R: person(given = "Mark", family = "Padgham", diff --git a/R/population-estimate.R b/R/population-estimate.R index 118d213..98faa3e 100644 --- a/R/population-estimate.R +++ b/R/population-estimate.R @@ -5,33 +5,31 @@ #' @export sb_car_spaces_per_resident <- function (osmdat) { - a_per_res <- area_per_resident (osmdat) - a_per_res_floor <- 10 * floor (mean (a_per_res$floor) / 10) - a_per_res_roof <- 10 * floor (mean (a_per_res$roof) / 10) - - a_building <- building_areas (osmdat) - area_floor <- sum (a_building$floor) - area_roof <- sum (a_building$roof) - - num_res_floor <- as.numeric (area_floor) / a_per_res_floor - num_res_roof <- as.numeric (area_roof) / a_per_res_roof - num_res <- num_res_floor + num_res_roof + num_res <- estimate_num_residents (osmdat) + num_res_tot <- sum (num_res$floor) + sum (num_res$roof) p <- car_parking_areas (osmdat) num_parking_spaces <- sum (p$num_parking_spaces) - num_parking_spaces / num_res + num_parking_spaces / num_res_tot } -#' Estimate floor and roof area per resident. +#' Estimate numbers of residents in floor and roof levels of buildings. #' #' Uses example building with known numbers of residents, and which is typical #' of the neighbourhood. #' @noRd -area_per_resident <- function (osmdat) { +estimate_num_residents <- function (osmdat) { + + requireNamespace ("jsonlite", quietly = TRUE) + + f <- system.file ("extdata", "population.json", package = "superblock") + if (!file.exists (f)) { + cli::cli_abort ("population estimates not bound at {f}") + } - num_residents_floors <- 21 - num_residents_roof <- 2.5 - area <- 181 # m2 + pop <- jsonlite::read_json (f, simplify = TRUE)$population + m2_per_res_floor <- mean (pop$area * pop$num_levels / pop$residents_floors) + m2_per_res_roof <- mean (pop$area * pop$num_levels_roof / pop$residents_roof) b <- filter_residential_buildings (osmdat$buildings) num_levels <- as.numeric (b$`building:levels`) @@ -47,11 +45,11 @@ area_per_resident <- function (osmdat) { num_levels <- ifelse (is.na (num_levels), num_levels_mn, num_levels) num_roof_levels <- ifelse (is.na (num_roof_levels), num_roof_levels_mn, num_roof_levels) - a_per_res_floors <- area * num_levels / num_residents_floors - # This is artifically inflated, because roof areas are always smaller: - a_per_res_roof <- area * num_roof_levels / num_residents_roof + building_areas <- as.numeric (sf::st_area (b)) + num_res_floor <- building_areas * num_levels / m2_per_res_floor + num_res_roof <- building_areas * num_roof_levels / m2_per_res_roof - data.frame (osm_id = b$osm_id, floor = a_per_res_floors, roof = a_per_res_roof) + data.frame (osm_id = b$osm_id, floor = num_res_floor, roof = num_res_roof) } exclude_ground_floor <- c ("civic", "office", "retail", "supermarket") diff --git a/codemeta.json b/codemeta.json index 000ee59..4cf4965 100644 --- a/codemeta.json +++ b/codemeta.json @@ -7,7 +7,7 @@ "codeRepository": "https://github.com/UrbanAnalyst/superblock-ms", "issueTracker": "https://github.com/UrbanAnalyst/superblock-ms/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.0.110", + "version": "0.1.0.111", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/inst/extdata/population.json b/inst/extdata/population.json new file mode 100644 index 0000000..9684087 --- /dev/null +++ b/inst/extdata/population.json @@ -0,0 +1,18 @@ +{ + "population": [ + { + "area": 181, + "residents_floors": 20, + "residents_roof": 2.5, + "num_levels": 4, + "num_levels_roof": 1 + }, + { + "area": 182, + "residents_floors": 22, + "residents_roof": 4, + "num_levels": 4, + "num_levels_roof": 1 + } + ] +}