I'm trying to plot the network for a place where I want to check accessibility of my friends for me.
GDF I'm using:
bbox = [12.8881, 77.5079, 12.9918, 77.6562]
def make_gdf(file_name):
shp = pd.read_csv(os.path.join(pth, file_name))
shp = shp[['Name_E','E','N','Area_m2']]
shp['geometry'] = (list(zip(shp.E,shp.N)))
shp['geometry'] = shp.geometry.apply(lambda x: Point(x))
shp = gpd.GeoDataFrame(shp, crs = {'init' :'epsg:4326'})
return(shp)
friends = make_gdf('BOIS.csv')
Creating the network
def get_bounds(friend_gdf, buffer_fraction):
bounds = friend_gdf.unary_union.bounds
x_width = abs(bounds[2] - bounds[0])
y_height = abs(bounds[3] - bounds[1])
minx = bounds[0] - (x_width * buffer_fraction)
miny = bounds[1] + (y_height * buffer_fraction)
maxx = bounds[2] - (x_width * buffer_fraction)
maxy = bounds[3] + (y_height * buffer_fraction)
return(minx, miny, maxx, maxy)
def create_network(pois_gdf, bounding_increment):
coords = get_bounds(pois_gdf, bounding_increment)
coords = (coords[1],coords[0],coords[3],coords[2])
return(osm.pdna_network_from_bbox(*coords))
G_BOIS = create_network(friends, 0.2)
output:
Requesting network data within bounding box from Overpass API in 1 request(s)
Posting to http://www.overpass-api.de/api/interpreter with timeout=180, "{'data': '[out:json][timeout:180];(way["highway"]["highway"!~"motor|proposed|construction|abandoned|platform|raceway"]["foot"!~"no"]["pedestrians"!~"no"](12.91917720,77.51336840,13.01304320,77.63043640);>;);out;'}"
Downloaded 9,852.9KB from www.overpass-api.de in 4.21 seconds
Downloaded OSM network data within bounding box from Overpass API in 1 request(s) and 4.38 seconds
Returning OSM data with 65,969 nodes and 18,575 ways...
Edge node pairs completed. Took 30.58 seconds
Returning processed graph with 30,323 nodes and 45,812 edges...
Completed OSM data download and Pandana node and edge table creation in 36.52 seconds
Defining a method to plot accessibility
define and plot
def plot_Bangalore(network,pois_gdf,distance,n,city_name,highway=['motorway','trunk','primary','secondary'],
bounding_increment = 0.2):
plot_kwargs={'cmap':'gist_heat_r','s':8,'edgecolor':'none'}
fig_kwargs = {'figsize': [20, 20]}
network.precompute(distance)
network.set_pois(category='all', maxdist = distance,x_col=pois_gdf['E'], maxitems=1, y_col=pois_gdf['N'])
access_table = network.nearest_pois(distance=distance, category='all', num_pois=1)
bmap, fig, ax = network.plot(access_table[n], plot_kwargs=plot_kwargs, fig_kwargs=fig_kwargs)
ax.set_facecolor('w')
ax.set_title('{}: Driving distance to nearest boi, meters)'.format(city_name), fontsize=14);
return(network, access_table)
plot_accessibility_and_roads(G_BOIS, friends, 2500, 1, 'Bangalore')
Output:
I got this when running plot_accessibility_and_roads
method with required details
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-15-f1d7c3fc45d5> in <module>
----> 1 plot_accessibility_and_roads(G_BOIS, friends, 2500, 1, 'Bangalore')
<ipython-input-12-90e6300937a9> in plot_accessibility_and_roads(network, pois_gdf, distance, n, city_name, highway, bounding_increment)
5 network.set_pois(category='all', maxdist = distance,x_col=pois_gdf['E'], maxitems=1, y_col=pois_gdf['N'])
6 access_table = network.nearest_pois(distance=distance, category='all', num_pois=1)
----> 7 bmap, fig, ax = network.plot(access_table[n], plot_kwargs=plot_kwargs, fig_kwargs=fig_kwargs)
8 ax.set_facecolor('k')
9 ax.set_title('{}: Driving distance to nearest boi, meters)'.format(city_name), fontsize=14);
~\miniconda3\envs\ox\lib\site-packages\pandana\network.py in plot(self, data, bbox, plot_type, fig_kwargs, bmap_kwargs, plot_kwargs, cbar_kwargs)
457 bmap = Basemap(
458 bbox[1], bbox[0], bbox[3], bbox[2], ax=ax, **bmap_kwargs)
--> 459 bmap.drawcoastlines()
460 bmap.drawmapboundary()
461
~\miniconda3\envs\ox\lib\site-packages\mpl_toolkits\basemap\__init__.py in drawcoastlines(self, linewidth, linestyle, color, antialiased, ax, zorder)
1849 # get current axes instance (if none specified).
1850 ax = ax or self._check_ax()
-> 1851 coastlines = LineCollection(self.coastsegs,antialiaseds=(antialiased,))
1852 coastlines.set_color(color)
1853 coastlines.set_linestyle(linestyle)
~\miniconda3\envs\ox\lib\site-packages\matplotlib\collections.py in __init__(self, segments, linewidths, colors, antialiaseds, linestyles, offsets, transOffset, norm, cmap, pickradius, zorder, facecolors, **kwargs)
1358 **kwargs)
1359
-> 1360 self.set_segments(segments)
1361
1362 def set_segments(self, segments):
~\miniconda3\envs\ox\lib\site-packages\matplotlib\collections.py in set_segments(self, segments)
1373 _segments = self._add_offsets(_segments)
1374
-> 1375 self._paths = [mpath.Path(_seg) for _seg in _segments]
1376 self.stale = True
1377
~\miniconda3\envs\ox\lib\site-packages\matplotlib\collections.py in <listcomp>(.0)
1373 _segments = self._add_offsets(_segments)
1374
-> 1375 self._paths = [mpath.Path(_seg) for _seg in _segments]
1376 self.stale = True
1377
~\miniconda3\envs\ox\lib\site-packages\matplotlib\path.py in __init__(self, vertices, codes, _interpolation_steps, closed, readonly)
128 if vertices.ndim != 2 or vertices.shape[1] != 2:
129 raise ValueError(
--> 130 "'vertices' must be a 2D list or array with shape Nx2")
131
132 if codes is not None:
ValueError: 'vertices' must be a 2D list or array with shape Nx2
Please help me with the error and please comment If needed more information