中国省份坐标为r



有人知道如何访问中国的区域坐标吗。下面的代码显示了我在中国寻找的相同内容。提前感谢

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

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

# 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包(v0.3.0(创建于2020-11-06

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

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

使用EPSG:4326存储数据,因此X=长,Y=宽。

这是您想要的吗?

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

最新更新