利用ArcGIS和Python計算中國各省路網密度

ArcGIS

相交

利用ArcGIS裏面的相交工具,每一個省把路標識了。 路網屬性表python

計算幾何

分別計算路網的長度和各省的面積。app

中國各省面積表

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裏面個人線圖層和麪圖層怎麼疊加,就是在這個底圖的基礎上加入路網圖層。code

相關文章
相關標籤/搜索