gpt4 book ai didi

r - 如何对齐谷歌地图经度纬度的ggmap CRS

转载 作者:行者123 更新时间:2023-12-04 12:42:58 24 4
gpt4 key购买 nike

尽管有很多 CRS 预测等帖子,但我无法阻止我的城镇下沉。

如果我去 Google Maps并输入 -35.016, 117.878奥尔巴尼镇位于旱地(如下图):
enter image description here

如果我在 R 中输入纬度/经度并尝试使用简单的功能包和 ggmap 进行映射,那么小镇就在海洋中:

library(tidyverse)
library(sf)
library(lwgeom)
library(ggmap)

lat <- c(-35.016)
lon <- c(117.878)
df <- tibble(lon,lat) %>% st_as_sf( coords = c("lon", "lat"), crs = 4326)

bbox_aus <- c(left = 113.338953078, bottom = -43.6345972634, right = 153.569469029, top = -10.6681857235)
ggmap_aus <- ggmap(get_stamenmap(bbox_aus, zoom = 5, maptype = "toner-background"))

ggmap_aus +
geom_sf(data = df, colour = "red" , size = 3, alpha = 0.5, inherit.aes = FALSE) +
# coord_sf(datum = sf::st_crs(4326)) +
labs(title = "Albany Sinking",
x = NULL,
y = NULL) +
theme_bw()

enter image description here

最佳答案

如果你使用 geom_point() 就可以了lon 和 lat 作为 x 和 y。

df <- tibble(lon,lat) %>% st_as_sf( coords = c("lon", "lat"), crs = 4326,
remove = FALSE)

ggmap_aus +
geom_point(data = df, colour = "red", size = 3, alpha = 0.5,
aes(x = lon, y = lat)) +
# coord_sf(datum = sf::st_crs(4326)) +
labs(title = "Albany is saved",
x = NULL,
y = NULL) +
theme_bw()

enter image description here

基于 this comment , 使用 geom_point()使用 x 和 y 美学更接近于 ggmap 生成 ggplot 的方式。

不幸的是,我不确定如何使它与 geom_sf() 一起使用。 ,使用 geometry 绘制柱子。该链接评论中有一些讨论,但解决方案似乎是使用 inherit.aes = FALSE ,您已经尝试过。

基于警告 Coordinate system already present. Adding new coordinate system, which will replace the existing one. ,我假设 ggmap 对象有一些不是 4326 的坐标系,但我找不到如何访问它。我确实尝试过重新投影 df到EPSG:3857,但这不起作用。

关于r - 如何对齐谷歌地图经度纬度的ggmap CRS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60066424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com