本文主要是介绍使用 NetworkX 调整 OpenStreetMap 街道网络图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
可视化网络和 GeoDataframe
续上篇
import osmnx as ox
from shapely.geometry import Polygoncoords = [上一篇文章结尾中的数组]
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 pltfig, 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
这篇关于使用 NetworkX 调整 OpenStreetMap 街道网络图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!