source: genesis/tools/make_nodemap_png.py@ 14380

Last change on this file since 14380 was 14314, checked in by rick, 6 years ago

Add crude attempt of creating A1 size nodemap picture

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/env python
2#
3# Quick to generate large (A1 size) image of node locations
4#
5import io, urllib2, datetime, time, re, random
6import math
7from PIL import Image, ImageDraw
8
9import make_network_kml
10
11def num2deg(xtile, ytile, zoom):
12 n = 2.0 ** zoom
13 lon_deg = xtile / n * 360.0 - 180.0
14 lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * ytile / n)))
15 lat_deg = math.degrees(lat_rad)
16 return (lat_deg, lon_deg)
17
18## bigmap_leiden
19#(zoom, xmin, ymin, xmax, ymax) = (16, 33568, 21592, 33599, 21615)
20# bigmap_region
21(zoom, xmin, ymin, xmax, ymax) = (14, 8379, 5390, 8417, 5416)
22
23
24(lat_nw, lon_nw) = num2deg(xmin, ymin, zoom)
25(lat_se, lon_se) = num2deg(xmax + 1, ymax + 1, zoom)
26
27delta_lat = lat_nw - lat_se
28delta_lon = lon_nw - lon_se
29print (lat_nw, lon_nw)
30print (lat_se, lon_se)
31
32xpixels = (xmax - xmin + 1) * 256
33ypixels = (ymax - ymin + 1) * 256
34print (xpixels, ypixels)
35
36
37debug=False
38
39# Input data
40poel, link_type, link_data, link_status, hosts = make_network_kml.get_graph_data(debug)
41
42# Input image
43#resultImage = Image.open("map16-190204-2154.png")
44resultImage = Image.open("map14-190204-2329.png")
45draw = ImageDraw.Draw(resultImage)
46
47coord = {}
48# Draw nodes
49for nodename, datadump in hosts.iteritems():
50 lat_y = (lat_nw - float(datadump['latitude'])) / delta_lat * ypixels
51 lon_x = (lon_nw - float(datadump['longitude'])) / delta_lon * xpixels
52 coord[nodename] = (lon_x, lat_y)
53 r = 20
54 draw.ellipse((lon_x - r, lat_y - r, lon_x + r, lat_y + r), fill = 'blue', outline ='blue')
55
56# Draw links
57for addr,leden in poel.iteritems():
58 for index,lid in enumerate(leden[:-1]):
59 for buur in leden[index + 1:]:
60 x1, y1 = coord[hosts[buur]['nodename']]
61 x2, y2 = coord[hosts[lid]['nodename']]
62 draw.line((x1, y1, x2, y2), fill = 'green', width = 5)
63
64del draw
65
66now = datetime.datetime.now()
67outputFileName = "foo.png"
68resultImage.save(outputFileName)
Note: See TracBrowser for help on using the repository browser.