对现实世界坐标进行反向 st_transform

问题描述 投票:0回答:1

我有一个旋转特定

sf
对象的过程,这对于渲染来说效果很好,无论是在
ggplot2
还是
plotly
中。

但是,在闪亮的应用程序中,我们需要用户的点击并用它做一些有用的事情,但坐标位于转换后的 CRS 中,而不是原始坐标中,我不确定如何反转转换。

我们使用 proj4string 及其

gamma=
参数来影响旋转:

realpoint
#        lon    lat
# 1 -79.8524 36.634
realpoint_sf
# Simple feature collection with 1 feature and 0 fields
# Geometry type: POINT
# Dimension:     XY
# Bounding box:  xmin: -79.8524 ymin: 36.634 xmax: -79.8524 ymax: 36.634
# Geodetic CRS:  WGS 84
#                  geometry
# 1 POINT (-79.8524 36.634)
crs_rot <- "+proj=omerc +lat_0=36.634073240 +lonc=-79.851657820 +datum=WGS84 +alpha=0 +gamma=67.000"

realpoint_sf_rot <- sf::st_transform(realpoint_sf, crs = crs_rot)
realpoint_sf_rot
# Simple feature collection with 1 feature and 0 fields
# Geometry type: POINT
# Dimension:     XY
# Bounding box:  xmin: -33.41711 ymin: 57.92568 xmax: -33.41711 ymax: 57.92568
# Projected CRS: +proj=omerc +lat_0=36.634073240 +lonc=-79.851657820 +datum=WGS84 +alpha=0 +gamma=67.000
#                     geometry
# 1 POINT (-33.41711 57.92568)

### in a shiny app showing a ggplot including the above point,
### a user "click" returns data effectively like this:
userclick <- data.frame(sf::st_coordinates(realpoint_sf_rot))

如何反转该过程以获得原始

79.85, 36.63
坐标?我不需要绝对的精确度,“接近”就足够了,尽管我更喜欢理论上合理的精确度。


原始数据:

realpoint <- structure(list(lon = -79.8524, lat = 36.634), row.names = c(NA, -1L), class = "data.frame")
realpoint_sf <- structure(list(geometry = structure(list(structure(c(-79.8524, 36.634), class = c("XY", "POINT", "sfg"))), n_empty = 0L, crs = structure(list(input = "EPSG:4326", wkt = "GEOGCRS[\"WGS 84\",\n    ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n        MEMBER[\"World Geodetic System 1984 (Transit)\"],\n        MEMBER[\"World Geodetic System 1984 (G730)\"],\n        MEMBER[\"World Geodetic System 1984 (G873)\"],\n        MEMBER[\"World Geodetic System 1984 (G1150)\"],\n        MEMBER[\"World Geodetic System 1984 (G1674)\"],\n        MEMBER[\"World Geodetic System 1984 (G1762)\"],\n        MEMBER[\"World Geodetic System 1984 (G2139)\"],\n        ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n            LENGTHUNIT[\"metre\",1]],\n        ENSEMBLEACCURACY[2.0]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433]],\n    CS[ellipsoidal,2],\n        AXIS[\"geodetic latitude (Lat)\",north,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        AXIS[\"geodetic longitude (Lon)\",east,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n    USAGE[\n        SCOPE[\"Horizontal component of 3D system.\"],\n        AREA[\"World.\"],\n        BBOX[-90,-180,90,180]],\n    ID[\"EPSG\",4326]]"), class = "crs"), class = c("sfc_POINT",  "sfc"), precision = 0, bbox = structure(c(xmin = -79.8524, ymin = 36.634, xmax = -79.8524, ymax = 36.634), class = "bbox"))), row.names = 1L, sf_column = "geometry", agr = structure(integer(0), class = "factor", levels = c("constant", "aggregate", "identity"), names = character(0)), class = c("sf", "data.frame"))
r geospatial r-sf
1个回答
0
投票

您可以根据旋转的 CRS 中的用户输入创建一个

sf
对象,并将其转换回原始 CRS,如下所示:

library(sf)
userclick_sf_rot <- st_as_sf(userclick, coords=c('X', 'Y'), crs=crs_rot)
userclick_sf <- st_transform(userclick_sf_rot, crs=st_crs(realpoint_sf))

st_coordinates(userclick_sf)
#          X      Y
# 1 -79.8524 36.634
st_coordinates(realpoint_sf)
#          X      Y
# 1 -79.8524 36.634
© www.soinside.com 2019 - 2024. All rights reserved.