使用纬度和经度坐标的热图

问题描述 投票:0回答:1

我有一个超过 1000 万行的非常大的数据框,其中包含有关海上交通中船只的航线点的信息。我想使用 python 创建一个热图来突出显示交通流量较高的区域,但这样做有点迷失了。

我尝试了一些方法,但有些选项需要很长时间才能运行,或者可视化不是很好。

有谁知道处理这个数据框的好方法。我正在考虑将地图划分为正方形,并可以选择调节要使用的正方形数量。

如果有人有建议,我愿意接受。

我尝试了一些方法,但有些选项需要很长时间才能运行,或者可视化不是很好。

有谁知道处理这个数据框的好方法。我正在考虑将地图划分为正方形,并可以选择调节要使用的正方形数量。

如果有人有建议,我愿意接受。

python heatmap latitude-longitude analysis traffic
1个回答
0
投票

您可能想在 https://gis.stackexchange.com/ 上询问,但您可以尝试以下代码:

import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

# Read the shapefile
data = gpd.read_file('your_shapefile.shp')

# Extract coordinates
x = data.geometry.x
y = data.geometry.y

# Calculate kernel density estimation (KDE) for smoothing
kde = gaussian_kde(np.vstack([x, y]))
xi, yi = np.mgrid[x.min():x.max():1000j, y.min():y.max():1000j]
zi = kde(np.vstack([xi.flatten(), yi.flatten()]))

# Plot heatmap
plt.figure(figsize=(10, 8))
plt.pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap=plt.cm.jet)
plt.colorbar(label='Density')
plt.scatter(x, y, color='k', s=1)  # Overlay original points
plt.title('Point Density Heatmap')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.