[14314] | 1 | #!/usr/bin/env python
|
---|
| 2 | #
|
---|
| 3 | # Quick to generate large (A1 size) image of node locations
|
---|
| 4 | #
|
---|
| 5 | import io, urllib2, datetime, time, re, random
|
---|
| 6 | import math
|
---|
| 7 | from PIL import Image, ImageDraw
|
---|
| 8 |
|
---|
| 9 | import make_network_kml
|
---|
| 10 |
|
---|
| 11 | def 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 |
|
---|
| 27 | delta_lat = lat_nw - lat_se
|
---|
| 28 | delta_lon = lon_nw - lon_se
|
---|
| 29 | print (lat_nw, lon_nw)
|
---|
| 30 | print (lat_se, lon_se)
|
---|
| 31 |
|
---|
| 32 | xpixels = (xmax - xmin + 1) * 256
|
---|
| 33 | ypixels = (ymax - ymin + 1) * 256
|
---|
| 34 | print (xpixels, ypixels)
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | debug=False
|
---|
| 38 |
|
---|
| 39 | # Input data
|
---|
| 40 | poel, 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")
|
---|
| 44 | resultImage = Image.open("map14-190204-2329.png")
|
---|
| 45 | draw = ImageDraw.Draw(resultImage)
|
---|
| 46 |
|
---|
| 47 | coord = {}
|
---|
| 48 | # Draw nodes
|
---|
| 49 | for 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
|
---|
| 57 | for 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 |
|
---|
| 64 | del draw
|
---|
| 65 |
|
---|
| 66 | now = datetime.datetime.now()
|
---|
| 67 | outputFileName = "foo.png"
|
---|
| 68 | resultImage.save(outputFileName)
|
---|