参照这里只写了怎么绘制省级、市级地图,这是因为文中找来的地图数据https://datav.aliyun.com/portal/school/atlas/area_selector只到市级。
楼主最近想要绘制县级的地图。在网上一通搜索找到http://xzqh.mca.gov.cn/map这里可以查看县级地图,但是只能查看,不提供下载,略微翻了下网页源代码,看不太懂里面的那些数字,因此没想到怎么把县级地图数据搞下来。请各位路过的坛友们帮忙出出主意吧,感谢大家。
参照这里只写了怎么绘制省级、市级地图,这是因为文中找来的地图数据https://datav.aliyun.com/portal/school/atlas/area_selector只到市级。
楼主最近想要绘制县级的地图。在网上一通搜索找到http://xzqh.mca.gov.cn/map这里可以查看县级地图,但是只能查看,不提供下载,略微翻了下网页源代码,看不太懂里面的那些数字,因此没想到怎么把县级地图数据搞下来。请各位路过的坛友们帮忙出出主意吧,感谢大家。
我发现阿里云的那个地图虽然不能直接下载全国的县级地图数据,但是可以选中一个省以后下载县级地图,理论上我应该是可以把每个省的单独下下来,然后拼接成一个,俺试试。
yuanfan https://www.webmap.cn/commres.do?method=dataDownload,这里有类似的,1:100万比例尺所包含的 shp 细节更多(缺点就是要填简单的申请表,不过不会审查,填完了就可以下载shp文件)
可以试试mapchina。
以绘制江西省的县级地图为例:
install.packages("mapchina")
library(mapchina)
library(tidyverse)
library(sf)
province <- china %>%
filter(Name_Province %in% c("江西省"))
cities <- province %>%
group_by(Name_Perfecture) %>%
summarise(geometry = st_union(geometry))
countries <- province %>%
group_by(Name_County) %>%
summarise(geometry = st_union(geometry))
ggplot() +
geom_sf(data = countries,
aes(fill = factor(generate_map_colors(countries))),
linetype = "solid", size = 0.5) +
scale_fill_brewer(palette = "Pastel1") +
geom_sf(data = province, alpha = 0, linetype = "dashed", size = 0.2) +
geom_sf(data = cities, alpha = 0, linetype = "solid", size = 1.2) +
geom_sf_label(data = countries, aes(label = Name_County), size = 2.3) +
theme_bw() +
theme(legend.position = "none")
一些属性(比如字体大小、坐标轴是否显示)可以根据自己需要再进行调整。
可以使用这个可靠的数据源:https://www.shengshixian.com/
IRONAnthony 跟着你的,我也绘制了湖南地图
install.packages("mapchina") # 如果尚未安装
install.packages("tidyverse") # 如果尚未安装
install.packages("sf") # 如果尚未安装
library(mapchina)
library(tidyverse)
library(sf)
province <- china %>%
filter(Name_Province == "湖南省") # 仅选择湖南省
cities <- province %>%
group_by(Name_Perfecture) %>%
summarise(geometry = st_union(geometry))
countries <- province %>%
group_by(Name_County) %>%
summarise(geometry = st_union(geometry))
ggplot() +
geom_sf(data = countries,
aes(fill = factor(generate_map_colors(countries))),
linetype = "solid", size = 0.5) +
scale_fill_brewer(palette = "Pastel1") +
geom_sf(data = province, alpha = 0, linetype = "dashed", size = 0.2) +
geom_sf(data = cities, alpha = 0, linetype = "solid", size = 1.2) +
geom_sf_label(data = countries, aes(label = Name_County), size = 2.3) +
theme_bw() +
theme(legend.position = "none")