一缩滨、獲取國務(wù)院官網(wǎng)地圖
# Thu Oct 22 20:42:32 2020 -
# 字符編碼:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 個(gè)人筆記不負(fù)責(zé)任
# —— 拎了個(gè)梨??
.rs.restartR()
rm(list=ls());gc()
#審圖號(hào): GS(2018)2512號(hào)
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包讀取在線數(shù)據(jù)势就。
API_pre <- "http://xzqh.mca.gov.cn/data/"
# xian_quanguo <- st_read(dsn = paste0(API_pre, "xian_quanguo.json"),
# stringsAsFactors=FALSE) # 這個(gè)縣級(jí)地圖太大,很卡脉漏。
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 # 不知道它什么投影隨便安排一個(gè)先苞冯。
#ggplot2作圖預(yù)覽
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
網(wǎng)址: https://datav.aliyun.com/tools/atlas
復(fù)制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') #標(biāo)簽
ggtitle('投影坐標(biāo)系統(tǒng):WGS 84')