Skip to content

Commit

Permalink
Release for image version 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
erikarasnick committed Apr 16, 2020
1 parent 81a7275 commit c046cbb
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 152 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# except what we need
!/renv.lock
!/census_block_group.R
!/NHGIS_US_2010_block_groups_5072_simplefeatures.rds
!/block_groups_2010_5072.rds
!/block_groups_2000_5072.rds
19 changes: 15 additions & 4 deletions 00_make_block_group_shp.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
library(tidyverse)
library(sf)

blk_grps_sf <- st_read("./nhgis0002_shape/nhgis0002_shapefile_tl2010_us_blck_grp_2010/US_blck_grp_2010.shp")
blk_grps_sf_2010 <- st_read("./nhgis0002_shape/nhgis0002_shapefile_tl2010_us_blck_grp_2010/US_blck_grp_2010.shp")

blk_grps_sf <- st_transform(blk_grps_sf, crs=5072) %>%
dplyr::select(fips_block_group_id = GEOID10,
blk_grps_sf_2010 <- st_transform(blk_grps_sf_2010, crs=5072) %>%
dplyr::select(fips_block_group_id_2010 = GEOID10,
geometry)

saveRDS(blk_grps_sf, "NHGIS_US_block_groups_5072_simplefeatures.rds")
saveRDS(blk_grps_sf_2010, "block_groups_2010_5072.rds")



blk_grps_sf_2000 <- st_read("/Users/RASV5G/Downloads/nhgis0015_shape/nhgis0015_shapefile_tl2000_us_blck_grp_2000/US_blck_grp_2000.shp")

blk_grps_sf_2000 <- st_transform(blk_grps_sf_2000, crs=5072) %>%
dplyr::select(fips_block_group_id_2000 = STFID,
geometry) %>%
mutate(fips_block_group_id_2000 = as.character(fips_block_group_id_2000))

saveRDS(blk_grps_sf_2000, "block_groups_2000_5072.rds")

4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ RUN apt-get update \
libgeos-dev=3.5.1-3 \
libudunits2-dev=2.2.20-1+b1 \
libproj-dev=4.9.3-1 \
libssl-dev \
&& apt-get clean

COPY renv.lock .
RUN R --quiet -e "renv::restore()"

COPY NHGIS_US_2010_block_groups_5072_simplefeatures.rds .
COPY block_groups_2010_5072.rds .
COPY block_groups_2000_5072.rds .
COPY census_block_group.R .

WORKDIR /tmp
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ build:
docker build -t $(IMAGE) .

test:
docker run --rm -v "${PWD}/test":/tmp $(IMAGE) my_address_file_geocoded.csv
docker run --rm -v "${PWD}/test":/tmp $(IMAGE) my_address_file_geocoded.csv 2010
docker run --rm -v "${PWD}/test":/tmp $(IMAGE) my_address_file_geocoded.csv 2000

shell:
docker run --rm -it --entrypoint=/bin/bash -v "${PWD}/test":/tmp $(IMAGE)
Expand Down
7 changes: 3 additions & 4 deletions census_block_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library(sf)

doc <- '
Usage:
census_block_group.R <filename>
census_block_group.R <filename> <census_year>
'

opt <- docopt::docopt(doc)
Expand All @@ -30,8 +30,7 @@ d <-
d <- st_transform(d, 5072)

message('\nloading block group shape files...')
block_groups <- readRDS(file="/app/NHGIS_US_2010_block_groups_5072_simplefeatures.rds") %>%
mutate(fips_block_group_id = as.character(fips_block_group_id))
block_groups <- readRDS(file=paste0("/app/block_groups_", opt$census_year, "_5072.rds"))

message('\nfinding block group for each point...')
d <- sf::st_join(d, block_groups, left = FALSE)
Expand All @@ -43,6 +42,6 @@ d <- d %>%

out <- left_join(raw_data, d, by = '.row') %>% select(-.row)

out_file_name <- paste0(tools::file_path_sans_ext(opt$filename), '_census_block_group.csv')
out_file_name <- paste0(tools::file_path_sans_ext(opt$filename), '_census_block_group_', opt$census_year, '.csv')
readr::write_csv(out, out_file_name)
message('\nFINISHED! output written to ', out_file_name)
Loading

0 comments on commit c046cbb

Please sign in to comment.