R/nyc_point_poly.R
nyc_point_poly.Rd
Point-in-polygon operation for NYC administrative boundaries. Use
nyc_point_poly()
on a set of points to determine which administrative
district each point lies within.
nyc_point_poly(points, geography = c("borough", "puma", "nta", "cd", "tract", "block", "school", "police", "council", "cong"))
points | An |
---|---|
geography | A character vector of administrative boundaries to append to points. Possible values are "borough", "puma", "cd", "nta", "school", "council", "police", "cong", "tract" and "block". If more than one geography is selected, names and codes for each geography is appended. |
An sf
object of point features with administrative district names
and and codes appended.
Using nyc_point_poly()
requires installing the sf package.
if (require(sf)) { # generate 100 random points in nyc points <- st_sf(geometry = st_sample(nyc_boundaries(), 100)) nyc_point_poly(points = points, geography = c("borough", "nta", "cd")) }#> Simple feature collection with 103 features and 6 fields #> geometry type: POINT #> dimension: XY #> bbox: xmin: 914354.3 ymin: 124868 xmax: 1065947 ymax: 268347.5 #> epsg (SRID): 2263 #> proj4string: +proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs #> # A tibble: 103 x 7 #> borough_name borough_id nta_name nta_id cd_name borough_cd_id #> <chr> <chr> <chr> <chr> <chr> <chr> #> 1 Queens 4 Baisley… QN76 Queens… 412 #> 2 Queens 4 Hunters… QN31 Queens… 402 #> 3 Staten Isla… 5 Todt Hi… SI24 Staten… 502 #> 4 Staten Isla… 5 Charles… SI11 Staten… 503 #> 5 Bronx 2 Allerto… BX31 Bronx … 211 #> 6 Bronx 2 park-ce… BX99 Bronx … 210 #> 7 Queens 4 Bayside… QN46 Queens… 411 #> 8 Staten Isla… 5 Charles… SI11 Staten… 503 #> 9 Staten Isla… 5 Charles… SI11 Staten… 503 #> 10 Staten Isla… 5 Old Tow… SI36 Staten… 502 #> # … with 93 more rows, and 1 more variable: geometry <POINT [US_survey_foot]>