【问题标题】:Getting longitude and latitude from RDS gadm file从 RDS gadm 文件中获取经度和纬度
【发布时间】:2019-12-28 01:04:50
【问题描述】:

我想问一下,

有没有办法从下载的 RDS 地理文件中获取经度和纬度变量(在 data.frame 中),例如:https://gadm.org/download_country_v3.html

我知道我们可以很容易地从这个数据集中绘图,只需使用:

df2 <- readRDS("C:/Users/petr7/Downloads/gadm36_DEU_1_sp.rds")
library(leaflet)
library(ggplot2)

# Using leaflet
leaflet() %>% addProviderTiles("CartoDB.Positron")%>%addPolygons(data=df, weight = 0.5, fill = F)

# Using ggplot
ggplot() + 
  geom_polygon(data = df2, aes(x=long, y = lat, group = group), color = "black", fill = F)

怎么连df2$都没有经纬度选项

【问题讨论】:

    标签: ggplot2 leaflet maps


    【解决方案1】:

    我会这样做:

    # packages
    library(sf)
    #> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
    
    my_url <- "https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_ITA_0_sf.rds"
    data <- readRDS(url(my_url))
    
    italy_coordinate <- st_coordinates(data)
    head(italy_coordinate)
    #>             X        Y L1 L2 L3
    #> [1,] 12.61486 35.49292  1  1  1
    #> [2,] 12.61430 35.49292  1  1  1
    #> [3,] 12.61430 35.49347  1  1  1
    #> [4,] 12.61375 35.49347  1  1  1
    #> [5,] 12.61375 35.49403  1  1  1
    #> [6,] 12.61347 35.49409  1  1  1
    

    reprex package (v0.3.0) 于 2019 年 12 月 27 日创建

    现在您只需根据您的问题更改网址。阅读st_coordinates函数的帮助页面(即?sf::st_coordinates),了解L1、L2和L3列的含义。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 2016-09-29
    • 1970-01-01
    相关资源
    最近更新 更多