Advertisement
davegimo

Untitled

Dec 26th, 2020
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. def createGraph(file,dist):
  2.     with open(file) as json_file:
  3.         json_data = json.load(json_file)
  4.         grafo = {}
  5.  
  6.         print(len(json_data['features']))
  7.  
  8.         for p in json_data['features']:
  9.             coord = p["geometry"]["coordinates"]
  10.             s = p["properties"]["code"]
  11.             inserisciMarker(m, coord[1], coord[0], s, "", "blue")
  12.             #print(s)
  13.             grafo[s] = {}
  14.             grafo[s]["coords"] = coord
  15.             grafo[s]["adjacent"] = []
  16.             #print(coord)
  17.             coordtuple = (coord[1],coord[0])
  18.             for pp in json_data['features']:
  19.                 if s != pp["properties"]["code"]:
  20.                     pptuple = (pp["geometry"]["coordinates"][1], pp["geometry"]["coordinates"][0])
  21.                     d = geodesic(coordtuple, pptuple).km
  22.                     if d < dist:
  23.                         l = []
  24.                         l.append(coordtuple)
  25.                         l.append(pptuple)
  26.                         inserisciLinea(m,l,"blue",3,0.2, d)
  27.                         grafo[s]["adjacent"].append(pp["properties"]["code"])
  28.  
  29.         with open('data.json', 'w') as fp:
  30.             json.dump(grafo, fp, indent=4)
  31.  
  32.         return grafo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement