Repository: HTenkanen/pyrosm

Issue:
BUG: creating network creates ghost copies of each node
I've discovered what looks to be a bug in the `to_graph` algorithm.  
The number of nodes in the graph resulting from `to_graph` is double the number of nodes pulled by `get_network`.  Furthermore, exactly half the nodes in the graph have no `geometry` attribute (which is how I found the problem).
I have not yet checked whether it always does this, or whether it is a byproduct of one of the options I'm using.
I also haven't checked whether the edges are also doubled.

```
thisAreaData = pyrosm.OSM('../Data/OSMData/kanto-latest.osm.pbf', bounding_box=thisBoundingPolygon)
nodes, edges = thisAreaData.get_network(nodes=True, network_type="walking")
print("numNodes1:", len(nodes))   ##---> 104,950
thisWalkingGraph = thisAreaData.to_graph(nodes, edges, graph_type="networkx", osmnx_compatible=False, retain_all=True)
print("numNodes2:", walkingNetwork.number_of_nodes())    ##---> 209,900
```

Discussion:

Patch:
diff --git a/pyrosm/graphs.py b/pyrosm/graphs.py
index 9d010fc..b4e46d5 100644
--- a/pyrosm/graphs.py
+++ b/pyrosm/graphs.py
@@ -162,9 +162,9 @@ def to_networkx(nodes,
         edges = edges.rename(columns={edge_id_col: 'osmid'})
         node_id_col = "osmid"
 
-        # Add 'osmid' as index
-        nodes = nodes.set_index('osmid', drop=False)
-        nodes = nodes.rename_axis([None])
+    # Add node-id as index
+    nodes = nodes.set_index(node_id_col, drop=False)
+    nodes = nodes.rename_axis([None])
 
     # Create NetworkX graph
     return _create_nxgraph(nodes, edges, from_id_col, to_id_col, node_id_col)


Test patch:
diff --git a/tests/test_graph_exports.py b/tests/test_graph_exports.py
index 461220e..cc3c140 100644
--- a/tests/test_graph_exports.py
+++ b/tests/test_graph_exports.py
@@ -435,3 +435,16 @@ def test_to_graph_api(test_pbf):
     assert isinstance(nxg, nx.MultiDiGraph)
     assert isinstance(ig, igraph.Graph)
     assert isinstance(pdg, pandana.Network)
+
+
+def test_graph_exports_correct_number_of_nodes(test_pbf):
+    """
+    Check issue: #97
+    """
+    from pyrosm import OSM
+    osm = OSM(test_pbf)
+    # NetworkX
+    nodes, edges = osm.get_network(nodes=True)
+    node_cnt = len(nodes)
+    nxg = osm.to_graph(nodes, edges, graph_type="networkx", osmnx_compatible=False, retain_all=True)
+    assert node_cnt == nxg.number_of_nodes()
\ No newline at end of file