From cf4294fddf177369f989bb4e6a788d8c28e8e1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCnch?= Date: Sun, 26 Jan 2020 20:30:56 +0100 Subject: [PATCH] added svg drawing feature --- Karte_Deutschland.svg | 103 ++++++++++++++++++++++++++++++++++++++++++ get_coordinates.py | 23 +++++++--- index.html | 8 ++++ svgwrite-example.svg | 2 + 4 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 Karte_Deutschland.svg create mode 100644 index.html create mode 100644 svgwrite-example.svg diff --git a/Karte_Deutschland.svg b/Karte_Deutschland.svg new file mode 100644 index 0000000..1f81956 --- /dev/null +++ b/Karte_Deutschland.svg @@ -0,0 +1,103 @@ + + + +image/svg+xml + + + + + \ No newline at end of file diff --git a/get_coordinates.py b/get_coordinates.py index 260464f..186c30e 100755 --- a/get_coordinates.py +++ b/get_coordinates.py @@ -1,11 +1,13 @@ #!/usr/bin/python -import requests, json, pickle, os.path +import requests, json, pickle, os.path, svgwrite URL = "https://directory.spaceapi.io/" NORTHERNMOST = 55.05 EASTERNMOST = 15.033333 SOUTHERNMOST = 47.270108 WESTERNMOST = 5.866667 +YSPAN = NORTHERNMOST - SOUTHERNMOST +XSPAN = EASTERNMOST - WESTERNMOST locations = {} if os.path.isfile('locations.bin'): print ("using offline data...") @@ -36,17 +38,26 @@ else: with open("locations.bin", "wb") as f: pickle.dump(locations, f, pickle.HIGHEST_PROTOCOL) print ("Removing non-german points...") -nongerman_locations = locations.copy() +german_locations = locations.copy() for space in locations: if locations[space][0] > NORTHERNMOST: - del nongerman_locations[space] + del german_locations[space] print ("kicked " + space + " too far north") elif locations[space][0] < SOUTHERNMOST: - del nongerman_locations[space] + del german_locations[space] print ("kicked " + space + " too far south") elif locations[space][1] < WESTERNMOST: - del nongerman_locations[space] + del german_locations[space] print ("kicked " + space + " too far west") elif locations[space][1] > EASTERNMOST: - del nongerman_locations[space] + del german_locations[space] print ("kicked " + space + " too far east") + +dwg = svgwrite.Drawing('svgwrite-example.svg', profile='tiny') +dwg.add(svgwrite.image.Image(href="Karte_Deutschland.svg", size=(572,770))) +dwg.add(dwg.circle(center=(0,0), r=3, fill='black')) +for space in german_locations: + ypoint = (770 - (((german_locations[space][0] - SOUTHERNMOST) / YSPAN)* 770)) + dwg.add(dwg.circle(center=(((locations[space][1] - WESTERNMOST) / XSPAN) * + 572, ypoint), r=1, fill='black')) +dwg.save() diff --git a/index.html b/index.html new file mode 100644 index 0000000..1362920 --- /dev/null +++ b/index.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/svgwrite-example.svg b/svgwrite-example.svg new file mode 100644 index 0000000..9687f50 --- /dev/null +++ b/svgwrite-example.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file