【问题标题】:Chinese province coordinates in rr中的中国省坐标
【发布时间】:2023-04-10 19:38:02
【问题描述】:

有谁知道如何按地区访问中国的坐标。下面的代码显示了我正在寻找中国的相同内容。非常感谢提前

require(maps)
 states_map <- map_data("state")

【问题讨论】:

    标签: r leaflet maps sp


    【解决方案1】:

    这是你想要的吗?

     map_data("world",region="China")
    
          long      lat group order region subregion
    1 110.8888 19.99194     1     1  China         1
    2 110.9383 19.94756     1     2  China         1
    3 110.9707 19.88330     1     3  China         1
    4 110.9977 19.76470     1     4  China         1
    5 111.0137 19.65547     1     5  China         1
    6 110.9127 19.58608     1     6  China         1
    

    【讨论】:

    • 我需要多边形的坐标
    【解决方案2】:

    您可能需要检查以下方法:

    # load packages
    library(sf)
    #> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
    library(osmextract)
    
    # get polygons in china
    poly_china <- openstreetmap_fr_zones[which(openstreetmap_fr_zones$parent == "china"), ]
    
    # extract the coords and save the coords in a data.frame
    # you may want to keep the data in matrix format for better performances
    poly_china_coords <- as.data.frame(st_coordinates(poly_china))
    
    # extract the region name
    my_times <- vapply(st_geometry(poly_china), function(x) nrow(st_coordinates(x)), numeric(1))
    poly_china_coords$region_name <- rep(poly_china$name, times = my_times)
    
    # result
    head(poly_china_coords)
    #>         X      Y L1 L2 L3 region_name
    #> 1 114.875 32.960  1  1  1       Anhui
    #> 2 114.860 32.970  1  1  1       Anhui
    #> 3 114.870 33.025  1  1  1       Anhui
    #> 4 114.880 33.035  1  1  1       Anhui
    #> 5 114.895 33.035  1  1  1       Anhui
    #> 6 114.890 33.060  1  1  1       Anhui
    

    reprex package 创建于 2020-11-06 (v0.3.0)

    您可以从 CRAN 安装 sf,也可以按如下方式安装 osmextract

    install.packages("remotes")
    remotes::install_github("ITSLeeds/osmextract")
    

    数据使用 EPSG:4326 存储,因此 X = long 和 Y = lat。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 2017-10-25
      • 2021-08-22
      • 1970-01-01
      • 2011-04-07
      • 2021-06-12
      • 1970-01-01
      相关资源
      最近更新 更多