title: Write shapefile in NetworkX using write_shp
body: <p>I am trying to compare how ordered street networks are in comparison to randomly generated street networks.</p>
  
  <p>As a starting point I have created a random graph with NetworkX with each node having a random location. I wanted to export this to a shapefile so that I can use it in ArcGIS. I checked the NetworkX documentattion and was elated to see that they have a write_shp() method. Their documentation mentions:</p>
  
  <blockquote>
    <p>"Nodes and edges are expected to have a Well Known Binary (Wkb) or
    Well Known Text (Wkt) key in order to generate geometries. Also
    acceptable are nodes with a numeric tuple key (x,y)."</p>
  </blockquote>
  
  <p>I decided to store the location of each node as a (x,y) tuple instead of including WKT as node's attributes.</p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>g=nx.fast_gnp_random_graph(15, 0.25)
  
  #Relabel Nodes
  mapping=dict(zip(g.nodes(),"ABCDEFGHIJKLMNO"))
  g=nx.relabel_nodes(g, mapping)
  
  radius=100000  #100 Km
  
  for d in g.nodes_iter(data=True): #I know this is a round about way to do this, but I might need node attributes later
          #Generate point location
          t = random.random() * (math.pi * math.pi)
          r = radius * math.sqrt(random.random())
          x = r * math.cos(t)
          y = r * math.sin(t)
          co_od=(x,y)
          nx.set_node_attributes(g, 'loc', {d[0]: co_od})
  
  nx.write_shp(g, './shp/trialAgainShp')
  </code></pre>
  
  <p>I am getting the following error trace:</p>
  
  <pre><code>File "D:\ProgramFiles\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
      execfile(filename, namespace)
  
    File "D:\ProgramFiles\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
      exec(compile(scripttext, filename, 'exec'), glob, loc)
  
    File "C:/Users/Dipto/Desktop/CSProceedings_AuthorTools_Word_2003/createGrapg.py", line 62, in &lt;module&gt;
      nx.write_shp(g, './shp/trialAgainShp')
  
    File "D:\ProgramFiles\Anaconda\lib\site-packages\networkx\readwrite\nx_shp.py", line 183, in write_shp
      g = netgeometry(n, data)
  
    File "D:\ProgramFiles\Anaconda\lib\site-packages\networkx\readwrite\nx_shp.py", line 157, in netgeometry
      fkey = [float(x) for x in key]
  
  ValueError: could not convert string to float: A
  </code></pre>
  
  <p>However, when I open the folder 'trialAgainShp', I do see shapefiles created with the name 'node', but they are empty.</p>
  
  <p>I am not sure where I am going wrong</p>
  
  <hr>
  
  <p>EDITS:</p>
  
  <p>I tried 2 more things:</p>
  
  <ol>
  <li>I thought maybe the nodes have to have numeric labels to be converted to shapefiles and changing the label to alphabets was causing the failure.</li>
  <li><p>I tried adding WKT to each node with the following code as the last lines of the FOR loop:</p>
  
  <pre><code>    #Create WKT 
      wkt='POINT(' + str(x) + ' ' + str(y) + ')'
      print wkt
      nx.set_node_attributes(g, 'WKT', {d[0]: wkt})
  </code></pre></li>
  </ol>
  
  <p>The first option does not have any effect as the error remains the same. The second changes the error to the following:</p>
  
  <pre><code>...
  nx.write_shp(g, './shp/trialAgainShp')
  
    File "D:\ProgramFiles\Anaconda\lib\site-packages\networkx\readwrite\nx_shp.py", line 183, in write_shp
      g = netgeometry(n, data)
  
    File "D:\ProgramFiles\Anaconda\lib\site-packages\networkx\readwrite\nx_shp.py", line 139, in netgeometry
      elif type(key[0]).__name__ == 'tuple':  # edge keys are packed tuples
  
  TypeError: 'int' object has no attribute '__getitem__'
  </code></pre>