批量抓取全国GeoJSON数据(DataV.GeoAtlas)方法
抓取思路
我们先观察一下数据结构,如下:
全国数据:
https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json
# 或
https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=100000_full
省级数据:
https://geo.datav.aliyun.com/areas_v3/bound/320000_full.json
# 或
https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=320000_full
地级市数据:
https://geo.datav.aliyun.com/areas_v3/bound/320100_full.json
# 或
https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=320100_full
全国数据:
下载全图的数据只有一个,直接下载就好。即:https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json
省级数据:
下载所有省级数据只要有所有省份的 adcode
,并构造出一个下载地址就好,比如:
甘肃:https://geo.datav.aliyun.com/areas_v3/bound/620000_full.json
内蒙古:https://geo.datav.aliyun.com/areas_v3/bound/150000_full.json
以此类推,地级市数据和省级类似,不过把 adcode
换成了各个地级市的而已。
数据下载
# /bin/bash
# 下载全国province标签下的json数据
wget http://datavmap-public.oss-cn-hangzhou.aliyuncs.com/areas/csv/100000_province.json
# 下载国家
wget https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json
# 下载省份
cat 100000_province.json | grep -Eo \"adcode\"\:\"\(\[0-9\]{6}\)\", >provinces.txt
sed 's/\"adcode\"\:\"/https:\/\/geo\.datav\.aliyun\.com\/areas_v3\/bound\//g' provinces.txt >tmp.txt
sed 's/\"\,/\_full\.json/g' tmp.txt >provinces.txt && rm tmp.txt
wget -i provinces.txt
# 下载各省份city标签下的json数据
cat 100000_province.json | grep -Eo \"adcode\"\:\"\(\[0-9\]{6}\)\", >provinces.txt
sed 's/\"adcode\"\:\"/http:\/\/datavmap-public\.oss-cn-hangzhou\.aliyuncs\.com\/areas\/csv\//g' provinces.txt >tmp.txt
sed 's/\"\,/\_city\.json/g' tmp.txt >provinces.txt && rm tmp.txt
wget -i provinces.txt
# 遍历目录下的_city.json 下载地市json数据
for file in $(ls | grep _city.json); do
# 下载地市
cat ${file} | grep -Eo \"adcode\"\:\"\(\[0-9\]{6}\)\", >city${file}.txt
sed 's/\"adcode\"\:\"/https:\/\/geo\.datav\.aliyun\.com\/areas_v3\/bound\//g' city${file}.txt >tmp${file}.txt
sed 's/\"\,/\_full\.json/g' tmp${file}.txt >city${file}.txt && rm tmp${file}.txt
wget -i city${file}.txt
done
if [[ ! -d ../GeoJson/ ]]; then
mkdir ../GeoJson/
fi
# 遍历目录下的_full.json 下载地市json数据
for file in $(ls | grep _full.json); do
cp ${file} ../GeoJson/${file:0:6}.json
done
由于时间仓促,错误与疏忽之处在所难免,希望各位朋友们以邮件的形式反馈问题给我,再次表示感谢!
- 作者:xmlwch
- 原文链接:https://m730.xmlwch.cn/2021/07/13/html/capture-geojson.html
- 版权声明:本作品采用 知识共享 署名-相同方式共享 4.0 国际(CC BY-SA 4.0)许可协议 进行许可,转载无需与我联系,但请注明出处。