可视化网络和 GeoDataframe
import osmnx as ox
from shapely.geometry import Polygon
coords = [上一篇文章结尾中的数组]
poly = Polygon(coords)
graph = ox.graph_from_polygon(poly, network_type='drive',simplify=True)
ox.plot_graph(graph)
我们可以使用GeoPandas转换 GeoDataframe 中的网络。
nodes, edges = ox.utils_graph.graph_to_gdfs(graph)
然后我们可以进行空间分析,例如找出一个点在一定距离内有多少个节点:
from shapely.geometry import Point
import geopandas as gpd
# Creating a point geometry
point = Point(23.7265, 37.9838)
buffer_distance = 0.01
# Creating a buffer around the point
buffer = point.buffer(buffer_distance)
# Performing a spatial join with nodes within the buffer
nodes_within_buffer = gpd.sjoin(nodes[nodes.within(buffer)], nodes, how="inner")
print(f"Number of nodes within the buffer: {len(nodes_within_buffer)}")
可视化:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
edges.plot(ax=ax, linewidth=1, edgecolor='#BC8F8F')
nodes.plot(ax=ax, marker='o', color='red', markersize=5)
# Highlighting nodes within the buffer
nodes_with