Last change
on this file since 22368 was
22368,
checked in by kdrangmeister, 5 years ago

roads as network  layer heights averaged

File size:
1.1 KB

Line  

1  # * coding: utf8 * 

2  # by kay  basic functions 

3  

4  import networkx as nx 

5  

6  class osrayNetwork(): 

7  

8  G = None 

9  

10  def __init__(self): 

11  self.G = nx.Graph() 

12  

13  def add_highway(self,highway_way,layer): 

14  lastpoint = None 

15  for point in highway_way: 

16  self.G.add_node(point) 

17  print "adding node:",point 

18  if(lastpoint!=None): 

19  self.G.add_edge(lastpoint,point,layer=layer) 

20  print "adding edge:",(lastpoint,point,layer) 

21  lastpoint=point 

22  print "G=",self.G.number_of_nodes(),self.G.number_of_edges() 

23  

24  def calculate_height_on_nodes(self): 

25  for n in self.G.nodes(): 

26  neighbors = self.G.neighbors(n) 

27  sum_height = 0.0 

28  for m in neighbors: 

29  edge = self.G[n][m] 

30  print "Edge(n,m)=",n,m,edge 

31  sum_height += edge['layer']*5.0 

32  self.G.node[n]['height'] = sum_height/len(neighbors) 

33  

34  def get_height(self,n): 

35  return self.G.node[n]['height'] 

36  

37  def printG(self): 

38  print "G=",self.G.edges() 

39  

40  

Note: See
TracBrowser
for help on using the repository browser.