利用ArcGIS和Python计算路网密度

ArcGIS

相交

利用ArcGIS里面的相交工具,每个省把路标识了。
路网属性表

计算几何

分别计算路网的长度和各省的面积。
中国各省面积表

Python

利用Python对属性数据进行处理

导入相关模块

## 导入相关模块
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt

%matplotlib inline

解决中文乱码

plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']# 替换sans-serif字体为黑体
plt.rcParams['axes.unicode_minus'] = False   # 解决坐标轴负数的负号显示问题

数据读取

regibns = gpd.GeoDataFrame.from_file("省级行政区.shp")
regibns = regibns[["NAME","AREA","geometry"]]
regibns["AREA"] = regibns["AREA"]/1000000
regibns.head()
regibns.plot()

中国地图

road = gpd.GeoDataFrame.from_file("道路密度.shp")
road.head()
road = road[["NAME", "length", "geometry"]]
road.plot()

主要公路分布图

数据透视

pivot = pd.pivot_table(road, index="NAME",values="length",aggfunc=sum)
pivot.head()

数据连接

results = pd.merge(regibns, pivot, on="NAME")
results["Density"] = results["length"] / results["AREA"]
results.head()

道路密度表

数据可视化

data_geod = gpd.GeoDataFrame(results)

data_geod['coords'] = data_geod['geometry'].apply(lambda x: x.representative_point().coords[0])
data_geod.plot(figsize=(12, 12), column='Density', scheme='quantiles', legend=True, cmap='Reds', edgecolor='k')
for n, i in enumerate(data_geod['coords']):
    plt.text(i[0], i[1], data_geod['NAME'][n], size=12)


plt.title('中国各省主要公路密度图', size=25)
plt.grid(True, alpha=0.3)

中国各省主要公路密度图

总结和反思

因为arcpy只支持python2,我用ArcGIS Pro的python3,也没有geopandas模块,所以在两个软件切换了。在ArcGIS中注意坐标系,我们计算面积和长度都是在投影坐标系下进行的。还有那个大神可以告诉我geopandas里面我的线图层和面图层怎么叠加,就是在这个底图的基础上加入路网图层。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值