Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'vertices' must be a 2D list or array with shape Nx2 happening only for Banglaore? #24

Closed
lucky-verma opened this issue Jul 14, 2020 · 4 comments

Comments

@lucky-verma
Copy link

lucky-verma commented Jul 14, 2020

Description of the bug

I have done the same over different regions of India and USA, I didn't get this issue untill trying over Banglore... Any thoughts and answers are most welcomed, Thanks!

OSM data (optional)

bbox = [12.8881, 77.5079, 12.9918, 77.6562]

Environment

  • Operating system: Windows 10 pro

  • Python version: 3.7.6

  • OSMnet version: 0.1.5

  • OSMnet required packages versions (optional): pandana 0.4.4, pandas 0.25.3, geopandas 0.6.3

Paste the code that reproduces the issue here:

import pandas as pd, geopandas as gpd
df = pd.DataFrame(
    {'id':[1522786113, 2227865111, 309601717, 1513928857, 2220792136, 6455354942],
        'Name': ['Neil', 'Nitin', 'Mukesh','Alpha','Beta','Office'],
     'Area': ['Valsad', 'Silvasa', 'Daman','Rajkot','Dui','Vapi'],
     'lat': [12.956550, 12.950360, 12.912047,12.955546,12.939653,12.928109],
     'lon': [77.540640, 77.581135, 77.586969,77.529658,77.542523,77.639337]})
pois = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))

network = osm.network_from_bbox(bbox[0], bbox[1], bbox[2], bbox[3],network_type='drive')
network=pandana.Network(network[0]["x"],network[0]["y"], network[1]["from"], network[1]["to"],network[1][["distance"]])
lcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance')

network.precompute(distance + 1)
network.init_pois(num_categories=1, max_dist=distance, max_pois=7)
network.set_pois(category='my_amenity', x_col=pois['lon'], y_col=pois['lat'])
access = network.nearest_pois(distance=distance, category='my_amenity', num_pois=7)

bbox_aspect_ratio = (bbox[2] - bbox[0]) / (bbox[3] - bbox[1])
fig_kwargs = {'facecolor':'w', 
              'figsize':(15, 15 * bbox_aspect_ratio)}

# keyword arguments to pass for scatter plots
plot_kwargs = {'s':5, 
               'alpha':0.9, 
               'cmap':'viridis_r', 
               'edgecolor':'none'}

n = 1
bmap, fig, ax = network.plot(access[n], bbox=bbox, plot_kwargs=plot_kwargs, fig_kwargs=fig_kwargs)
ax.set_facecolor('k')
ax.set_title('Walking distance (m) to nearest boi around Bangalore-India', fontsize=15)
fig.savefig('images/accessibility.png', dpi=200, bbox_inches='tight')
plt.show()

Paste the error message (if applicable):

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-22-d557c4f5993e> in <module>
      1 # plot the distance to the nth nearest amenity
      2 n = 1
----> 3 bmap, fig, ax = network.plot(access[n], bbox=bbox, plot_kwargs=plot_kwargs, fig_kwargs=fig_kwargs)
      4 ax.set_facecolor('k')
      5 ax.set_title('Walking distance (m) to nearest {} around Berkeley/Oakland'.format(amenity), fontsize=15)

~\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)
   1357             **kwargs)
   1358 
-> 1359         self.set_segments(segments)
   1360 
   1361     def set_segments(self, segments):

~\miniconda3\envs\ox\lib\site-packages\matplotlib\collections.py in set_segments(self, segments)
   1372             _segments = self._add_offsets(_segments)
   1373 
-> 1374         self._paths = [mpath.Path(_seg) for _seg in _segments]
   1375         self.stale = True
   1376 

~\miniconda3\envs\ox\lib\site-packages\matplotlib\collections.py in <listcomp>(.0)
   1372             _segments = self._add_offsets(_segments)
   1373 
-> 1374         self._paths = [mpath.Path(_seg) for _seg in _segments]
   1375         self.stale = True
   1376 

~\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
@jamesjoyce92
Copy link

I get the same error for different cities in Central Europe like Berlin, Cologne and Amsterdam. Other queries in Lisbon and Dublin work.

I think the difficulties are with pyProj , I get a future warning:

c:\users\sven.conda\envs\thesisox\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=:' syntax is deprecated. "Authority: code is the preferred initialization method. When making the change, be mindful of axis order changes:
return _prepare_from_string(" ".join(pjargs))

There a change of the axis order is mentioned, which I also recognize in my code.

network = osm.network_from_bbox(lat_min=bbox[0], lng_min=bbox[1], lat_max=bbox[2], lng_max=bbox[3])
print(network[0]["x"], network[0]["y"])

  • id
  • 21518835 7.617888
  • 21518840 7.619910
  • 21518841 7.619844
  • 21518843 7.622686
  • 21518845 7.623884
  •             ...   
    
  • 7622832878 7.624866
  • 7622832880 7.624928
  • 7623060866 7.629284
  • 7623060875 7.631151
  • 7645051167 7.611426
  • Name: x, Length: 4722, dtype: float64 id
  • 21518835 51.951031
  • 21518840 51.954686
  • 21518841 51.954977
  • 21518843 51.955540
  • 21518845 51.955627
  •             ...    
    
  • 7622832878 51.964202
  • 7622832880 51.964346
  • 7623060866 51.963732
  • 7623060875 51.965294
  • 7645051167 51.968587
  • Name: y, Length: 4722, dtype: float64

The expected format is x = 51.951031 y = 7.617888

For this reason the data probably cannot be visualized.

However, I haven't found a solution yet, and would be very grateful for some ideas.

@lucky-verma
Copy link
Author

Hi @jamesjoyce92 , I have compared the format for working and not working region, they both are similar.

I hope someone helps!

@jamesjoyce92
Copy link

Hey @thinkersloo,

yeah, you're right. I was a bit hastily, I've checked it for some working bboxes and get the same order, too.

@lucky-verma lucky-verma changed the title 'vertices' must be a 2D list or array with shape Nx2 happening only for Banglaore. 'vertices' must be a 2D list or array with shape Nx2 happening only for Banglaore? Sep 25, 2020
@sablanchard
Copy link
Contributor

@lucky-verma its been awhile since we have taken a look at this issue, I tried recently to replicate the issue and I dont think I can replicate using the example given or at least in this version of testing it I get a result without error:

env info:

Windows 10 Pro
Python 3.6.11
pandana=0.6.1
geopandas=0.9.0
pandas=1.1.0
osmnet=0.1.6

reproducible example:

import matplotlib.pyplot as plt
import pandana
import pandas as pd, geopandas as gpd
# use osmnet directly instead of from pandana
from osmnet import load

bbox = [12.8881, 77.5079, 12.9918, 77.6562]
# distance was not originally provided so I picked 1000 m
distance=1000

df = pd.DataFrame(
    {'id':[1522786113, 2227865111, 309601717, 1513928857, 2220792136, 6455354942],
        'Name': ['Neil', 'Nitin', 'Mukesh','Alpha','Beta','Office'],
     'Area': ['Valsad', 'Silvasa', 'Daman','Rajkot','Dui','Vapi'],
     'lat': [12.956550, 12.950360, 12.912047,12.955546,12.939653,12.928109],
     'lon': [77.540640, 77.581135, 77.586969,77.529658,77.542523,77.639337]})
pois = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))

network = load.network_from_bbox(bbox[0], bbox[1], bbox[2], bbox[3],network_type='drive')
network=pandana.Network(network[0]["x"],network[0]["y"], network[1]["from"], network[1]["to"],network[1][["distance"]])

network.precompute(distance + 1)
network.set_pois(category='my_amenity', x_col=pois['lon'], y_col=pois['lat'], maxdist=distance, maxitems=7)
access = network.nearest_pois(distance=distance, category='my_amenity', num_pois=7)

bbox_aspect_ratio = (bbox[2] - bbox[0]) / (bbox[3] - bbox[1])
fig_kwargs = {'facecolor':'w',
              'figsize':(15, 15 * bbox_aspect_ratio)}

# keyword arguments to pass for scatter plots
plot_kwargs = {'s':5,
               'alpha':0.9,
               'cmap':'viridis_r',
               'edgecolor':'none'}

n = 1
bmap, fig, ax = network.plot(access[n], bbox=bbox, plot_kwargs=plot_kwargs, fig_kwargs=fig_kwargs)
ax.set_facecolor('k')
ax.set_title('Walking distance (m) to nearest boi around Bangalore-India', fontsize=15)
fig.savefig('images/accessibility.png', dpi=200, bbox_inches='tight')
plt.show()

result:
image

Ill close this for now, but if the issue persists when you update your packages, please let us know and can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants