想要使用arcmap绘图,需要数据格式.shp。
第一种方法:
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
from shapely import geometry
import os
###################原文https://zhuanlan.zhihu.com/p/556141415
plt.rcParams['font.sans-serif'] = 'Microsoft YaHei' # 设置字体为微软雅黑
# 使打印输出显示更全
pd.set_option('display.max_columns',500)
pd.set_option('display.width',1000)
# 读取丛台区geojson数据
data = gpd.read_file(r'路径\文件名.json')
print(data)
# 将列重命名缩短,防止保存为shp文件时因列名过程导致的警告
data = data.rename(columns = {'childrenNum':'childnum','subFeatureIndex':'rawIndex'})
print(data)
# 创建一个储存shp文件的文件夹
if not os.path.exists('SHP'):
os.mkdir('SHP')
data.to_file('SHP/文件名.shp',
driver='ESRI Shapefile',
encoding='utf-8')
第二种方法:
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
from shapely import geometry
import os
plt.rcParams['font.sans-serif'] = 'Microsoft YaHei' # 设置字体为微软雅黑
# 使打印输出显示更全
pd.set_option('display.max_columns',500)
pd.set_option('display.width',1000)
# 读取邯郸geojson数据
data = gpd.read_file('邯郸市.json')
#print(data)
#提取想要的区县
prd_city = ['邯山区','丛台区','复兴区']
prd_city_english = ['hanshan','congtai','fuxing']
prd = data[data['name'].isin(prd_city)]
# 将列重命名缩短,防止保存为shp文件时因列名过程导致的警告
prd = prd.rename(columns = {'childrenNum':'childnum','subFeatureIndex':'rawIndex'})
print(prd)
# 创建一个储存shp文件的文件夹
if not os.path.exists('SHP'):
os.mkdir('SHP')
# 保存为shp文件
prd.to_file('SHP/文件名.shp',
driver='ESRI Shapefile',
encoding='utf-8')
相关文章
发表评论