-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspatial-police.R
38 lines (35 loc) · 1021 Bytes
/
spatial-police.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(aws.s3)
library(dplyr)
library(purrr)
library(sf)
source("utils.R")
# This script retrieves police districts
AWS_S3_RAW_BUCKET <- Sys.getenv("AWS_S3_RAW_BUCKET")
output_bucket <- file.path(AWS_S3_RAW_BUCKET, "spatial", "police")
sources_list <- bind_rows(list(
# POLICE
"pol_2012" = c(
"source" = "https://data.cityofchicago.org/api/geospatial/",
"api_url" = "p3h8-xsd4?method=export&format=GeoJSON",
"boundary" = "police_district",
"year" = "2012"
),
"pol_2018" = c(
"source" = "https://data.cityofchicago.org/api/geospatial/",
"api_url" = "fthy-xz3r?method=export&format=GeoJSON",
"boundary" = "police_district",
"year" = "2018"
)
))
# Function to call referenced API, pull requested data, and write it to S3
pwalk(sources_list, function(...) {
df <- tibble::tibble(...)
open_data_to_s3(
s3_bucket_uri = output_bucket,
base_url = df$source,
data_url = df$api_url,
dir_name = df$boundary,
file_year = df$year,
file_ext = ".geojson"
)
})