我正在尝试将数据帧中的 sf 点(CRS:4326,基于度数)转换为本地度量投影(EPSG:23867,DGN95 / UTM 区域 47N)。
所以我有一个数据框“航路点”,其中包含我的所有属性以及 lon / lat 作为列。我在数据框中创建了一个 sf 点几何,其中“lat”和“lon”作为输入(waypoints_sf)。(另外我将坐标保存为 Northing 和 Easting 在两个新列中)
waypoints_sf <- st_as_sf(waypoints,
coords = c("lat", "lon"),
crs = 4326)
coordinates_tmp <- st_coordinates(waypoints_sf)
colnames(coordinates_tmp) <- c("E","N")
waypoints_sf <- cbind(waypoints_sf,coordinates_tmp) # save coordinates as column E and N
class(waypoints_sf)
[1] "sf" "grouped_df" "tbl_df" "tbl" "data.frame"
class(waypoints_sf$geometry)
[1] "sfc_POINT" "sfc"
st_crs(waypoints_sf$geometry)
[1] Coordinate Reference System:
EPSG: 4326
proj4string: "+proj=longlat +datum=WGS84 +no_defs"
现在,当我尝试对这个数据帧进行 st_transform 时,它不会引发错误或警告,但无论我尝试什么,sf 点都是空几何c(NaN, NaN) 。
waypoints_sf <- st_transform(waypoints_sf, 23867)
waypoints_sf$geometry[1]
[1] Geometry set for 1 feature (with 1 geometry empty)
geometry type: POINT
dimension: XY
bbox: xmin: NA ymin: NA xmax: NA ymax: NA
epsg (SRID): 23867
proj4string: +proj=utm +zone=47 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
POINT EMPTY
那么我做错了什么,也许我真的很想念简单的东西,我真的不知道为什么它不起作用?如果它不与 st_transform 一起使用可能使用 N 和 E raw,那么简单的解决方法是什么?
现在对我有用的解决方法(“航点”是简单的df):
waypoints_sf <- waypoints
waypoints_sf <- waypoints_sf %>% mutate(longitude=lon,latitude=lat) # save if later needed
coordinates(waypoints_sf) <- c("lon","lat")
proj4string(waypoints_sf) <- CRS("+proj=longlat +datum=WGS84") # set crs
waypoints_sf <- spTransform(test, CRS("+init=epsg:23867")) # transform
waypoints_sf <- st_as_sf(waypoints_sf,crs = 23867)