一、获取国务院官网地图
# Thu Oct 22 20:42:32 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
rm(list=ls());gc()
#审图号: GS(2018)2512号
library(sf) # Simple Features for R
library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
library(tidyr) # Tidy Messy Data
library(dplyr) # A Grammar of Data Manipulation
library(tibble) # Simple Data Frames
# Thu Aug 13 20:05:12 2020 ---获取---------------------------
# API前缀
# 直接用sf包读取在线数据。
API_pre <- "http://xzqh.mca.gov.cn/data/"
# xian_quanguo <- st_read(dsn = paste0(API_pre, "xian_quanguo.json"),
# stringsAsFactors=FALSE) # 这个县级地图太大,很卡。
map.qg.shenjie <-
st_read('http://xzqh.mca.gov.cn/data/quanguo.json')
# Thu Aug 13 20:04:58 2020 ---作图---------------------------
plot(map.qg.shenjie[1])
st_crs(map.qg.shenjie) <- 4326 # 不知道它什么投影随便安排一个先。
#ggplot2作图预览
ggplot()+geom_sf(data = map.qg.shenjie)
names(map.qg.shenjie)
ggplot() + geom_sf(
data = map.qg.shenjie,
show.legend = FALSE,
color = 'green',
# 描边色
aes(fill = 1:156)
) # 填充色
## Reading layer `xian_quanguo' from data source `http://xzqh.mca.gov.cn/data/xian_quanguo.json' using driver `GeoJSON'
## Simple feature collection with 3246 features and 4 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 73.61808 ymin: 3.984257 xmax: 135.2154 ymax: 53.6871
## epsg (SRID): NA
## proj4string: NA
二、获取阿里云地图选择器DataV.GeoAtlas
网址: https://datav.aliyun.com/tools/atlas

复制API地址使用
# Thu Aug 13 22:52:36 2020 --阿里云矢量地图----------------------------
#
require(sf)
require(ggplot2)
json.dizhi <- 'https://geo.datav.aliyun.com/areas_v2/bound/100000.json'
map.ali.qg <- st_read(dsn = json.dizhi)
# Reading layer `100000' from data source `https://geo.datav.aliyun.com/areas_v2/bound/100000.json' using driver `GeoJSON'
# Simple feature collection with 2 features and 8 fields
# geometry type: MULTIPOLYGON
# dimension: XY
# bbox: xmin: 73.50235 ymin: 3.397162 xmax: 135.0957 ymax: 53.56327
# geographic CRS: WGS 84
#
plot(map.ali.qg[1])
ggplot()+geom_sf(data = map.ali.qg)
json.dizhi <- 'https://geo.datav.aliyun.com/areas_v2/bound/440100_full.json'
map.ali.gz <- st_read(dsn = json.dizhi)
plot(map.ali.gz[1])
ggplot()+geom_sf(data = map.ali.gz)
names(map.ali.gz)
ggplot(map.ali.gz)+
geom_sf(aes(fill = name), # 填充色
color = 'green') # 边界色。
ggplot(map.ali.gz)+
geom_sf()+
geom_sf_text(aes(label = name))+ #显示文字。
# geom_sf_label(aes(label = name),color= 'blue') #标签
ggtitle('投影坐标系统:WGS 84')