1 需要的包
import geopandas as gpd
import pandas as pd
import numpy as np
import requests
import matplotlib.pyplot as plt
import os
import json
from json import JSONDecodeError
from shapely.geometry import MultiLineString
2 省级地图
2.1 爬数据
China_sheng = (gpd.read_file(‘https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json’, crs=‘EPSG:4326’)
.query(“name != ‘’”) # 移除南海九段线,这个数据是polygon, 不是linestring
.reindex([‘adcode’, ‘name’, ‘geometry’], axis=1)
.explode(ignore_index=True, index_parts=False) # 拆分
.groupby(by=[‘adcode’, ‘name’])[‘geometry’] # 分组后buffer(0)以消除交叉点
.agg(lambda x: x.buffer(0).unary_union) # 再合并
.reset_index()
.set_crs(crs=‘EPSG:4326’)
)
China_sheng.head()