首页 > 解决方案 > 如何对齐谷歌地图经度纬度的ggmap CRS

问题描述

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

如果我去谷歌地图并进-35.016, 117.878入奥尔巴尼镇是旱地(如下图): 在此处输入图像描述

如果我在 R 中输入 lat/long 并尝试使用简单的功能包和 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()

在此处输入图像描述

标签: rggmapsf

解决方案


如果您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()

在此处输入图像描述

基于此评论,使用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,但这没有用。


推荐阅读