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里面我的線圖層和面圖層怎么疊加,就是在這個底圖的基礎上加入路網圖層。