Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherman committed Dec 9, 2018
0 parents commit 9dce718
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^data-raw$
^LICENSE\.md$
^.*\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
23 changes: 23 additions & 0 deletions DESCRIPTION
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
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2018
COPYRIGHT HOLDER: Matt Herman
21 changes: 21 additions & 0 deletions LICENSE.md
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.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
25 changes: 25 additions & 0 deletions R/nyc_tract.R
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"
93 changes: 93 additions & 0 deletions data-raw/prep-geo.R
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)



1 change: 1 addition & 0 deletions data-raw/puma-names.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puma_name,puma_idBrooklyn Community District 1--Greenpoint & Williamsburg,4001Brooklyn Community District 4--Bushwick,4002Brooklyn Community District 3--Bedford-Stuyvesant,4003Brooklyn Community District 2--Brooklyn Heights & Fort Greene,4004"Brooklyn Community District 6--Park Slope, Carroll Gardens & Red Hook",4005Brooklyn Community District 8--Crown Heights North & Prospect Heights,4006Brooklyn Community District 16--Brownsville & Ocean Hill,4007Brooklyn Community District 5--East New York & Starrett City,4008Brooklyn Community District 18--Canarsie & Flatlands,4009"Brooklyn Community District 17--East Flatbush, Farragut & Rugby",4010"Brooklyn Community District 9--Crown Heights South, Prospect Lefferts & Wingate",4011Brooklyn Community District 7--Sunset Park & Windsor Terrace,4012Brooklyn Community District 10--Bay Ridge & Dyker Heights,4013"Brooklyn Community District 12--Borough Park, Kensington & Ocean Parkway",4014Brooklyn Community District 14--Flatbush & Midwood,4015"Brooklyn Community District 15--Sheepshead Bay, Gerritsen Beach & Homecrest",4016Brooklyn Community District 11--Bensonhurst & Bath Beach,4017Brooklyn Community District 13--Brighton Beach & Coney Island,4018"Manhattan Community District 12--Washington Heights, Inwood & Marble Hill",3801"Manhattan Community District 9--Hamilton Heights, Manhattanville & West Harlem",3802Manhattan Community District 10--Central Harlem,3803Manhattan Community District 11--East Harlem,3804Manhattan Community District 8--Upper East Side,3805Manhattan Community District 7--Upper West Side & West Side,3806"Manhattan Community District 4 & 5--Chelsea, Clinton & Midtown Business District",3807"Manhattan Community District 6--Murray Hill, Gramercy & Stuyvesant Town",3808Manhattan Community District 3--Chinatown & Lower East Side,3809"Manhattan Community District 1 & 2--Battery Park City, Greenwich Village & Soho",3810Queens Community District 1--Astoria & Long Island City,4101Queens Community District 3--Jackson Heights & North Corona,4102"Queens Community District 7--Flushing, Murray Hill & Whitestone",4103"Queens Community District 11--Bayside, Douglaston & Little Neck",4104"Queens Community District 13--Queens Village, Cambria Heights & Rosedale",4105"Queens Community District 8--Briarwood, Fresh Meadows & Hillcrest",4106Queens Community District 4--Elmhurst & South Corona,4107Queens Community District 6--Forest Hills & Rego Park,4108Queens Community District 2--Sunnyside & Woodside,4109"Queens Community District 5--Ridgewood, Glendale & Middle Village",4110Queens Community District 9--Richmond Hill & Woodhaven,4111"Queens Community District 12--Jamaica, Hollis & St. Albans",4112Queens Community District 10--Howard Beach & Ozone Park,4113"Queens Community District 14--Far Rockaway, Breezy Point & Broad Channel",4114"Staten Island Community District 3--Tottenville, Great Kills & Annadale",3901Staten Island Community District 2--New Springville & South Beach,3902"Staten Island Community District 1--Port Richmond, Stapleton & Mariner's Harbor",3903"Bronx Community District 8--Riverdale, Fieldston & Kingsbridge",3701"Bronx Community District 12--Wakefield, Williamsbridge & Woodlawn",3702"Bronx Community District 10--Co-op City, Pelham Bay & Schuylerville",3703"Bronx Community District 11--Pelham Parkway, Morris Park & Laconia",3704"Bronx Community District 3 & 6--Belmont, Crotona Park East & East Tremont",3705"Bronx Community District 7--Bedford Park, Fordham North & Norwood",3706"Bronx Community District 5--Morris Heights, Fordham South & Mount Hope",3707"Bronx Community District 4--Concourse, Highbridge & Mount Eden",3708"Bronx Community District 9--Castle Hill, Clason Point & Parkchester",3709"Bronx Community District 1 & 2--Hunts Point, Longwood & Melrose",3710
Expand Down
Binary file added data/nyc_tract.rda
Binary file not shown.
35 changes: 35 additions & 0 deletions man/nyc_tract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions nycgeo.Rproj
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

0 comments on commit 9dce718

Please sign in to comment.