import geopandas as gpd
import matplotlib.pyplot as plt
import networkx as nx
import osmnx as ox
from shapely.geometry import LineString
from shapely.geometry import Point
from shapely.geometry import Polygon
ox.__version__
# configure the place, network type, trip times, and travel speed
place = {"city": "Berkeley", "state": "California"}
network_type = "walk"
trip_times = [5] # in minutes
travel_speed = 4.5 # walking speed in km/hour
# download the street network
G = ox.graph_from_place(place, network_type=network_type)
# find the centermost node and then project the graph to UTM
gdf_nodes = ox.graph_to_gdfs(G, edges=False)
x, y = gdf_nodes["geometry"].unary_union.centroid.xy
center_node = ox.distance.nearest_nodes(G, x[0], y[0])
Gb = ox.project_graph(G)
# add an edge attribute for time in minutes required to traverse each edge
meters_per_minute = travel_speed * 1000 / 60 # km per hour to m per minute
for _, _, _, data in Gb.edges(data=True, keys=True):
data["time"] = data["length"] / meters_per_minute
# get one color for each isochrone
iso_colors = ox.plot.get_colors(n=len(trip_times), cmap="plasma", start=0)
def make_iso_polys(G, edge_buff=25, node_buff=50, infill=False):
isochrone_polys = []
for trip_time in sorted(trip_times, reverse=True):
subgraph = nx.ego_graph(G, center_node, radius=trip_time, distance="time")
node_points = [Point((data["x"], data["y"])) for node, data in subgraph.nodes(data=True)]
nodes_gdf = gpd.GeoDataFrame({"id": list(subgraph.nodes)}, geometry=node_points)
nodes_gdf = nodes_gdf.set_index("id")
edge_lines = []
for n_fr, n_to in subgraph.edges():
f = nodes_gdf.loc[n_fr].geometry
t = nodes_gdf.loc[n_to].geometry
edge_lookup = G.get_edge_data(n_fr, n_to)[0].get("geometry", LineString([f, t]))
edge_lines.append(edge_lookup)
n = nodes_gdf.buffer(node_buff).geometry
e = gpd.GeoSeries(edge_lines).buffer(edge_buff).geometry
all_gs = list(n) + list(e)
new_iso = gpd.GeoSeries(all_gs).unary_union
# try to fill in surrounded areas so shapes will appear solid and
# blocks without white space inside them
if infill:
new_iso = Polygon(new_iso.exterior)
isochrone_polys.append(new_iso)
return isochrone_polys
# make the isochrone polygons
isochrone_polys = make_iso_polys(Gb, edge_buff=25, node_buff=0, infill=True)
gdf = gpd.GeoDataFrame(geometry=isochrone_polys)
# plot the network then add isochrones as colored polygon patches
fig, ax = ox.plot_graph(
G, show=False, close=False, edge_color="#999999", edge_alpha=0.2, node_size=0
)
gdf.plot(ax=ax, color=iso_colors, ec="none", alpha=0.6, zorder=-1)
plt.show()
Насколько я понимаю, данные сначала извлекаются в lon/lat (-122.271, 37.871), но затем конвертируются в другой формат...Может ли кто-нибудь помочь мне понять, почему требуется преобразование и как я могу преобразовать isochrone_polys обратно в lon/lat
Я работаю над примером ниже https://github.com/gboeing/osmnx-examples/blob/v2.0.0b0/notebooks/13-isolines-isochrones .ipynb [code]import geopandas as gpd import matplotlib.pyplot as plt import networkx as nx import osmnx as ox from shapely.geometry import LineString from shapely.geometry import Point from shapely.geometry import Polygon
ox.__version__
# configure the place, network type, trip times, and travel speed place = {"city": "Berkeley", "state": "California"} network_type = "walk" trip_times = [5] # in minutes travel_speed = 4.5 # walking speed in km/hour
# download the street network G = ox.graph_from_place(place, network_type=network_type)
# find the centermost node and then project the graph to UTM gdf_nodes = ox.graph_to_gdfs(G, edges=False) x, y = gdf_nodes["geometry"].unary_union.centroid.xy center_node = ox.distance.nearest_nodes(G, x[0], y[0]) Gb = ox.project_graph(G)
# add an edge attribute for time in minutes required to traverse each edge meters_per_minute = travel_speed * 1000 / 60 # km per hour to m per minute for _, _, _, data in Gb.edges(data=True, keys=True): data["time"] = data["length"] / meters_per_minute
# get one color for each isochrone iso_colors = ox.plot.get_colors(n=len(trip_times), cmap="plasma", start=0)
def make_iso_polys(G, edge_buff=25, node_buff=50, infill=False): isochrone_polys = [] for trip_time in sorted(trip_times, reverse=True): subgraph = nx.ego_graph(G, center_node, radius=trip_time, distance="time")
node_points = [Point((data["x"], data["y"])) for node, data in subgraph.nodes(data=True)] nodes_gdf = gpd.GeoDataFrame({"id": list(subgraph.nodes)}, geometry=node_points) nodes_gdf = nodes_gdf.set_index("id")
edge_lines = [] for n_fr, n_to in subgraph.edges(): f = nodes_gdf.loc[n_fr].geometry t = nodes_gdf.loc[n_to].geometry edge_lookup = G.get_edge_data(n_fr, n_to)[0].get("geometry", LineString([f, t])) edge_lines.append(edge_lookup)
n = nodes_gdf.buffer(node_buff).geometry e = gpd.GeoSeries(edge_lines).buffer(edge_buff).geometry all_gs = list(n) + list(e) new_iso = gpd.GeoSeries(all_gs).unary_union
# try to fill in surrounded areas so shapes will appear solid and # blocks without white space inside them if infill: new_iso = Polygon(new_iso.exterior) isochrone_polys.append(new_iso) return isochrone_polys
# make the isochrone polygons isochrone_polys = make_iso_polys(Gb, edge_buff=25, node_buff=0, infill=True) gdf = gpd.GeoDataFrame(geometry=isochrone_polys)
# plot the network then add isochrones as colored polygon patches fig, ax = ox.plot_graph( G, show=False, close=False, edge_color="#999999", edge_alpha=0.2, node_size=0 ) gdf.plot(ax=ax, color=iso_colors, ec="none", alpha=0.6, zorder=-1) plt.show() [/code] Насколько я понимаю, данные сначала извлекаются в lon/lat (-122.271, 37.871), но затем конвертируются в другой формат...Может ли кто-нибудь помочь мне понять, почему требуется преобразование и как я могу преобразовать isochrone_polys обратно в lon/lat
Я хотел бы отметить широту и долготу соседней аптеки, возвращенную с портала данных, с помощью маркера, основанного на местоположении пользователя. Но когда я запускаю свое приложение, оно даже не считается местоположением пользователя, и маркер не...
Я хочу получать широту и долготу пользователя, даже когда приложение закрывается пользователем во флаттере.
Я использовал пакет фонового местоположения 2, и он работает хорошо, но когда я использовал его в MIUI ( На устройстве Redmi (особенно в...