【发布时间】:2019-02-20 01:24:35
【问题描述】:
我正在尝试加入 R 中的一些数据,我想将有关行政区、街区等的人口普查信息添加到我拥有的 longlat 坐标中。我的数据如下所示:
census_data <- blocks <- tigris::blocks("NY", "Kings", 2010) #manhattan data
long_lat <- raw_data %>% select(pickup_longitude, pickup_latitude)
long_lat 是一个数据框,并且:
head(long_lat)
# A tibble: 6 x 2
pickup_latitude pickup_longitude
<dbl> <dbl>
1 40.8 -74.0
2 40.7 -74.0
3 40.8 -74.0
4 40.7 -74.0
5 40.7 -74.0
6 40.8 -74.0
class(blocks)
[1] "sf" "data.frame"
head(blocks)
Simple feature collection with 6 features and 17 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.98255 ymin: 40.58305 xmax: -73.92447 ymax: 40.62601
epsg (SRID): 4269
proj4string: +proj=longlat +datum=NAD83 +no_defs
我将我的 long_lat 数据转换为可与我的块数据连接,如下所示:
long_lat_st <- st_as_sf(long_lat, coords = c("pickup_longitude",
"pickup_latitude"),
crs = st_crs(blocks))
对于 crs 参数,我只是将它传递给匹配块数据。我曾尝试将其手动编码为:“+proj=longlat +datum=NAD83”,但是当我这样做时,尽管我的规范,我最终会得到不匹配的 crs。
运行此功能后,我有以下内容:
head(long_lat_st)
Simple feature collection with 6 features and 0 fields
geometry type: POINT
dimension: XY
bbox: xmin: -74.01006 ymin: 40.72139 xmax: -73.96774 ymax: 40.77356
epsg (SRID): 4269
proj4string: +proj=longlat +datum=NAD83 +no_defs
geometry
1 POINT (-73.97399 40.75726)
2 POINT (-74.01006 40.72139)
3 POINT (-73.97784 40.77356)
4 POINT (-73.9964 40.73223)
5 POINT (-73.9786 40.72432)
6 POINT (-73.96774 40.76598)
proj4strings 现在匹配了。
是否可以按照我的方式传递 crs 参数,或者它是否会使我的 longlat 配对无效?
从这里我可以像这样加入我的数据而不会出错:
joined <- st_join(long_lat_st, blocks, left = FALSE)
我认为这可以正常工作,但我只是想确定一下。
【问题讨论】:
标签: r geospatial sf