UDST / pandana

Pandas Network Analysis by UrbanSim: fast accessibility metrics and shortest paths, using contraction hierarchies :world_map:
http://udst.github.io/pandana
GNU Affero General Public License v3.0
386 stars 84 forks source link

Not able to measure the accessibility to all the pois #121

Closed emanuelemassaro closed 5 years ago

emanuelemassaro commented 5 years ago

I am trying to use the pandana package for assigning point of interest (i.e. points) to a road network.

The problem is that this procedure is not able to assign the accessibility to all the pois we define. In particular here we define 100 pois and we only able to get the accessibility measure for 84 of them.

I am doing the following as suggested here and here.

I define a network from open street map.

# Bounding box for a small area in East Emeryville, South Berkeley and North Oakland

west, south, east, north = (-122.285535, 37.832531, -122.269571, 37.844596)

# Create a network from that bounding box

G = ox.graph_from_bbox(north, south, east, west, network_type='walk')

# Let's create n arbitrary points of interest (POI)

poi_count = 100

# this function makes those POI into Shapely points

def make_n_pois(north, south, east, west, poi_count):
    for poi in range(poi_count):
        x = (east - west) * random.random() + west
        y = (north - south) * random.random() + south
        yield Point(x, y)

pois = list(make_n_pois(north, south, east, west, poi_count))

nodes_gdf, edges_gdf = ox.graph_to_gdfs(G)
# Instantiate a Pandana (pdna) network (net)
net = pdna.Network(nodes_gdf['x'], nodes_gdf['y'],
                   edges_gdf['u'], edges_gdf['v'],
                   edges_gdf[['length']])

pois_df = pd.DataFrame(pois)
pois_df.columns = ['geometry']
pois_df=gpd.GeoDataFrame(pois_df)
pois_df['x']=pois_df['geometry'].x
pois_df['y']=pois_df['geometry'].y

## Measuring Accessibility

net.set_pois(category='pois', maxdist=30000, maxitems=1, x_col=pois_df['x'], y_col=pois_df['y'])

npi = net.nearest_pois(30000,
                       'pois',
                       num_pois=1,
                       include_poi_ids=True)

Now if I check the number of pois in npi it is only 81 and not 100.

len(pd.unique(npi['poi1']))
84

Why?

sablanchard commented 5 years ago

Hi @emanuelemassaro , Looks like the result is correct. You get back 399 nearest poi records from all 399 nodes in your nodes_gdf. You are doing a count on poi id using unique which is why you only get 84. What is happening is that your result shows some network nodes have the same poi id that it finds as being the closest which make sense. For example in my replicated analysis of your same data, node ids: 5483212914 and 5483212915 both have poi id 66 as its closest poi id.

On the other hand if you really wanted to get the opposite of this - nearest node id to each poi you could try setting the num_pois param to be 100 and then would have to reshape the results in some way...

Hope this helps. Closing as its not issue.