R語(yǔ)言,爬蟲,矢量地圖.

一、獲取國(guó)務(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')

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容