-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9dce718
Showing
12 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
^data-raw$ | ||
^LICENSE\.md$ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Type: Package | ||
Package: nycgeo | ||
Title: Spatial Data Files for NYC | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person(given = "Matt", | ||
family = "Herman", | ||
role = c("aut", "cre"), | ||
email = "[email protected]") | ||
Maintainer: Matt Herman <[email protected]> | ||
Description: Spatial data files for various geographic | ||
boundaries in New York City. Data is in the in the sf (simple | ||
features) format and includes boundaries for boroughs (counties), | ||
neighborhood tabulation areas, community districts, public microdata | ||
areas, census tracts, and census blocks. | ||
License: MIT + file LICENSE | ||
Depends: | ||
R (>= 2.10) | ||
Suggests: | ||
sf | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2018 | ||
COPYRIGHT HOLDER: Matt Herman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2018 Matt Herman | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exportPattern("^[[:alpha:]]+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#' NYC census tract spatial dataset | ||
#' | ||
#' A dataset in sf format containing boundaries of all census tracts in New York | ||
#' City. | ||
#' | ||
#' @format An sf object with 2166 rows and 12 variables: | ||
#' \describe{ | ||
#' \item{boro_tract_id}{NYC DCP borough code and census tract number} | ||
#' \item{geoid}{Census Bureau GEOID; can be used to join spatial data with | ||
#' Census estimates} | ||
#' \item{state_fips}{ANSI state FIPS code} | ||
#' \item{county_fips}{ANSI county FIPS code} | ||
#' \item{tract_id}{Census Bureau tract number} | ||
#' \item{county_name}{County name} | ||
#' \item{boro_name}{Borough name} | ||
#' \item{boro_id}{NYC DCP borough code and census tract number} | ||
#' \item{nta_id}{NYC neighborhood tabulation area id} | ||
#' \item{nta_name}{NYC neighborhood tabulation area name} | ||
#' \item{puma_id}{Census Bureau public use microdata area id} | ||
#' \item{puma_name}{Census Bureau public use microdata area name} | ||
#' \item{geometry}{sfc_MULTIPOLYGON \cr | ||
#' NAD83 / New York Long Island (ftUS); EPSG:2263} | ||
#' } | ||
#' @source \url{https://www1.nyc.gov/site/planning/data-maps/open-data/districts-download-metadata.page} | ||
"nyc_tract" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
library(tidyverse) | ||
library(sf) | ||
library(devtools) | ||
|
||
# import geo files -------------------------------------------------------- | ||
|
||
# https://www1.nyc.gov/site/planning/data-maps/open-data/districts-download-metadata.page | ||
# set up urls for dowloading geojson boundaries from nyc dcp | ||
base_url <- "http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/" | ||
tail_url <- "/FeatureServer/0/query?where=1=1&outFields=*&outSR=4326&f=geojson" | ||
|
||
# geographies to download | ||
geos <- list( | ||
tract = "nyct2010", | ||
nta = "nynta", | ||
boro = "nybb" | ||
) | ||
|
||
# build list of urls | ||
urls <- map(geos, ~ paste0(base_url, .x, tail_url)) | ||
|
||
# download geojson and covert to sf | ||
nyc_sf <- map(urls, read_sf) | ||
|
||
|
||
# reference tables -------------------------------------------------------- | ||
|
||
# create boro code to county lookup table | ||
# Boro Codes | ||
# 1 = Manhattan | ||
# 2 = Bronx | ||
# 3 = Brooklyn | ||
# 4 = Queens | ||
# 5 = Staten Island | ||
|
||
boro_id_lookup <- tribble( | ||
~boro_id, ~county_fips, ~county_name, | ||
"1", "061", "New York", | ||
"2", "005", "Bronx", | ||
"3", "047", "Kings", | ||
"4", "081", "Queens", | ||
"5", "085", "Richmond" | ||
) | ||
|
||
# read in puma name lookup table | ||
puma_name_lookup <- read_csv("data-raw/puma-names.csv", col_types = "cc") | ||
|
||
|
||
# process tracts ---------------------------------------------------------- | ||
|
||
nyc_tract <- nyc_sf %>% | ||
pluck("tract") %>% | ||
left_join(boro_id_lookup, by = c("BoroCode" = "boro_id")) %>% | ||
mutate( | ||
state_fips = "36", | ||
geoid = paste0(state_fips, county_fips, CT2010) | ||
) %>% | ||
select( | ||
boro_tract_id = BoroCT2010, | ||
geoid, | ||
state_fips, | ||
county_fips, | ||
tract_id = CT2010, | ||
county_name, | ||
boro_name = BoroName, | ||
boro_id = BoroCode, | ||
nta_id = NTACode, | ||
nta_name = NTAName, | ||
puma_id = PUMA | ||
) %>% | ||
left_join(puma_name_lookup, by = "puma_id") %>% | ||
arrange(boro_tract_id) | ||
|
||
|
||
# build geo crosswalks ---------------------------------------------------- | ||
|
||
# create crosswalk to add nta, puma info to blocks | ||
tract_nta_puma_crosswalk <- nyc_tract %>% | ||
st_set_geometry(NULL) %>% | ||
select(county_fips, tract_id, nta_id, nta_name, puma_id, puma_name) | ||
|
||
# create crosswalk to add puma info to ntas | ||
nta_puma_crosswalk <- tract_nta_puma_crosswalk %>% | ||
distinct(nta_id, puma_id, puma_name) %>% | ||
filter(!str_detect(nta_id, "98|99")) # remove ntas with pumas (park, cemetary, etc) | ||
|
||
|
||
|
||
|
||
use_data(nyc_tract, overwrite = TRUE) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: knitr | ||
LaTeX: pdfLaTeX | ||
|
||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source |