如何解决使用 GeoDataFrame 中的网格单元
我有一个 GeoDataFrame,里面装满了来自给定城市 xy 的点,我是从 osmnx 包中加载的。 如果我绘制此图,我将在图上将经度和纬度作为 x 轴和 y 轴。 (见图)
到目前为止我所拥有的
包:
import pandas as pd
import geopandas as gpd
import numpy as np
from shapely.geometry import Point,polygon,Linestring
%matplotlib inline
import matplotlib.pyplot as plt
import shapely
import plotly_express as px
import networkx as nx
import osmnx as ox
ox.config(use_cache=True,log_console=True)
创建图形函数
def create_graph(loc,dist,transport_mode,loc_type="address"):
"""Transport mode = ‘walk’,‘bike’,‘drive’,‘drive_service’,‘all’,‘all_private’,‘none’"""
if loc_type == "address":
V = ox.graph_from_address(loc,dist=dist,network_type=transport_mode)
elif loc_type == "points":
V = ox.graph_from_point(loc,network_type=transport_mode )
return V
输入城市:
V = create_graph("Enter a city here",2500,"drive")
ox.plot_graph(V)
# Retrieve nodes and edges
nodes,edges = ox.graph_to_gdfs(V)
在它上面放一个网格并绘制它:
pcproj = ccrs.PlateCarree()
fig = plt.figure(figsize=(12,8))
extent =[16.01,16.10,48.305,48.345] #lonmin,lonmax,latmin,latmax
ax = plt.axes(projection= pcproj )
ax.set_extent(extent,crs=pcproj)
lon_grid = np.arange(16.0,16.09,0.01)
lat_grid = np.arange(48.310,48.340,0.005)
gl = ax.gridlines(draw_labels=True,xlocs=lon_grid,ylocs=lat_grid,x_inline=False,y_inline=False,color='r',linestyle='dotted')
ax = nodes.plot(ax=ax,edgecolor='k',lw=0.9)
ax.set_title("Gridded Version : Some_City Points")
plt.show()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。