这是一个无效的MWE,但与我最近的MWE
library(data.table)
library(sf)
# The DT data.table is the data I have (but 10,000s of rows, each row is a point)
DT <- data.table(
place=c("Finland", "Canada", "Tanzania", "Bolivia", "France"),
longitude=c(27.472918, -90.476303, 34.679950, -65.691146, 4.533465),
latitude=c(63.293001, 54.239631, -2.855123, -13.795272, 48.603949),
crs="+proj=longlat +datum=WGS84")
DT[, rowid:=1:.N]
# The following two rows do not work
DT[, place.sfg:=st_point(x=c(longitude, latitude), dim="XY"), by=rowid]
places.sfc <- st_sfc(DT[, place.sfg], crs=DT[, crs])
# This should result in five points, which it doesn't
plot(places.sfc)
我正在尝试学习简单功能(这就是为什么我不想使用库sp的原因),后来需要在st_buffer上运行证监会。
最好直接创建sfc,而无需每点sfg?
我将data.table用于速度原因(也分析了10,000的点)
我想我需要一个sfg点的sfc,而不是MULTIPOINT sfg。
#1 楼
您是否尝试过st_as_sf()将对象(sp,dataframe,...)转换为sf对象?library(data.table)
library(sf)
# your data (removed crs column)
DT <- data.table(
place=c("Finland", "Canada", "Tanzania", "Bolivia", "France"),
longitude=c(27.472918, -90.476303, 34.679950, -65.691146, 4.533465),
latitude=c(63.293001, 54.239631, -2.855123, -13.795272, 48.603949))
# st_as_sf() ######
# sf version 0.2-7
DT_sf = st_as_sf(DT, coords = c("longitude", "latitude"),
crs = 4326, relation_to_geometry = "field")
# sf version 0.3-4, 0.4-0
DT_sf = st_as_sf(DT, coords = c("longitude", "latitude"),
crs = 4326, agr = "constant")
plot(DT_sf)
@cengel评论,紧跟该程序包的快速开发非常重要。
评论
在SO上提出了类似的问题:stackoverflow.com/questions/29736577/…