I have some origin data that contains lat-lng coordinates, and when I use osmnx's get_nearest_edges method, I want to filter those coordinates that are not in the given city (San Francisco in this example). Is there any convenient method that implement this feature?
Here is part of my code:
roadId = ox.utils.get_nearest_edges(G, df['longitude'], df['latitude'], method='balltree')
df['startId'] = roadId[:,0]
df['endId'] = roadId[:,1]
startId = roadId[:,0]
endId = roadId[:,1]
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)
startInfo = gdf_nodes.loc[startId]
endInfo = gdf_nodes.loc[endId]
df['startLat'] = startInfo.loc[:, ['y']].values
df['startLon'] = startInfo.loc[:, ['x']].values
df['endLat'] = endInfo.loc[:, ['y']].values
df['endLon'] = endInfo.loc[:, ['x']].values
The first line's G is from this:
G = ox.graph_from_place('San Francisco, California, USA', network_type='drive')
And the output file is like this:
latitude 37.61549
longitude -122.38821
startId 65365765
endId 65365766
startLat 37.708957
startLon -122.392803
endLat 37.708785
endLon -122.393012
This example is what I want to express, because the road in the result is not in San Francisco, how can I identify it in the code and remove it?