【问题标题】:How to align ggmap CRS of google map longitude latitude如何对齐谷歌地图经度纬度的ggmap CRS
【发布时间】:2020-05-20 19:32:50
【问题描述】:

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

如果我转到Google Maps 并输入-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()

【问题讨论】:

    标签: r ggmap sf


    【解决方案1】:

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

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

    【讨论】:

    • 感谢@Eugene 拯救奥尔巴尼!!!。仍然有点好奇为什么 geom_sf 不起作用但不足以继续调查。真的很高兴有这个解决方案,并且会坚持使用 geom_point :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多