我有一个旋转特定sf个对象的进程,在ggplot2plotly中都可以很好地进行渲染.

然而,在shiny 的应用程序中,我们需要接受用户的点击并用它做一些有用的事情,但坐标在转换后的CRS中,而不是原始的,我不确定如何逆转转换.

我们使用proj4字符串及其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"))

推荐答案

您可以从旋转后的CR中的用户输入创建一个sf对象,并将其转换回原始CR,如下所示:

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

R相关问答推荐

跨列应用多个摘要函数:summerise_all:列表对象无法强制为double类型'

在ggplot的注释表格中突出显示最大值

如何删除多个.CSV文件的行

检测(并替换)字符串中的数学符号

如何利用模型函数在格图中添加双曲/指数曲线

如何直接从Fortran到R的数组大小?

使用较长的查询提取具有部分匹配的列表中的较短目标,

在R中按行按列范围查找最大值的名称

更改STAT_VALLES/STAT_PEAKS中的箭头线宽/大小

提高圣彼得堡模拟的速度

为什么我对圆周率图的蒙特卡罗估计是空的?

将统计检验添加到GGPUBR中的盒图,在R

R -基线图-图形周围的阴影区域

带RStatix的Wilcoxon环内检验

避免在图例中显示VLINS组

在同一单元格中创建包含整数和百分比的交叉表

在ggplot2图表中通过端点连接点

从字符串01JAN2021创建日期

汇总数据:在跨越()all_of()Dynamic_list_of_vars=>;所选内容不能有缺失值的汇总()中出错

列间序列生成器的功能