User:Angeliki/Grad-prototyping: Difference between revisions
m (Angeliki moved page Zine-machines to User:Angeliki/Grad-prototyping) |
No edit summary |
||
Line 1: | Line 1: | ||
== Zine-machines == | |||
[https://zine-machines.kstraat.casa/ zine-machines.kstraat.casa] | [https://zine-machines.kstraat.casa/ zine-machines.kstraat.casa] | ||
export GPS data, publish routes/video frames to raw data-publish | export GPS data, publish routes/video frames to raw data-publish | ||
<syntaxhighlight lang="python" line='line'> | |||
import pykml | |||
from pykml import parser | |||
import csv | |||
import re | |||
from reportlab.lib.pagesizes import letter | |||
from reportlab.pdfgen import canvas | |||
def translate(value, leftMin, leftMax, rightMin, rightMax): | |||
# Figure out how 'wide' each range is | |||
leftSpan = leftMax - leftMin | |||
rightSpan = rightMax - rightMin | |||
# Convert the left range into a 0-1 range (float) | |||
valueScaled = float(value - leftMin) / float(leftSpan) | |||
# Convert the 0-1 range into a value in the right range. | |||
return rightMin + (valueScaled * rightSpan) | |||
kml_file='prlll.kml' | |||
all_routes = {} | |||
with open(kml_file) as f: | |||
doc = parser.parse(f).getroot().Document.Folder | |||
for pm in doc.iterchildren(): | |||
if hasattr(pm, 'LineString'): | |||
name = pm.name.text | |||
coordinates = pm.LineString.coordinates.text | |||
cordinatesinline = coordinates.split('\n') | |||
cordinatesasarray = [] | |||
for line in cordinatesinline: | |||
pattern = re.compile("^\s+|\s*,\s*|\s+$") | |||
array = [x for x in pattern.split(line) if x] | |||
if array: | |||
cordinatesasarray.append(array) | |||
all_routes[name]= cordinatesasarray | |||
canvas=canvas.Canvas("route.pdf", pagesize=letter) | |||
canvas.setLineWidth(.8) | |||
canvas.setFont('Helvetica', 6) | |||
for name in all_routes: | |||
x=[] | |||
y=[] | |||
for points in all_routes[name]: | |||
x.append(points[0]) | |||
y.append(points[1]) | |||
i=0 | |||
for a in x: | |||
if i < len(x)-1: | |||
x_new=translate(float(x[i]),float(min(x)), float(max(x)),50,500) | |||
y_new=translate(float(y[i]),float(min(y)),float(max(y)),50,500) | |||
x_new2=translate(float(x[i+1]),float(min(x)), float(max(x)),50,500) | |||
y_new2=translate(float(y[i+1]),float(min(y)),float(max(y)),50,500) | |||
print x_new,y_new,x_new2,y_new2 | |||
canvas.line(x_new,y_new,x_new2,y_new2) | |||
i=i+1 | |||
canvas.drawString(10,45,name) | |||
canvas.showPage() | |||
canvas.save() | |||
</syntaxhighlight> | |||
== Antennas == |
Revision as of 10:37, 18 September 2018
Zine-machines
export GPS data, publish routes/video frames to raw data-publish
import pykml
from pykml import parser
import csv
import re
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
def translate(value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
leftSpan = leftMax - leftMin
rightSpan = rightMax - rightMin
# Convert the left range into a 0-1 range (float)
valueScaled = float(value - leftMin) / float(leftSpan)
# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan)
kml_file='prlll.kml'
all_routes = {}
with open(kml_file) as f:
doc = parser.parse(f).getroot().Document.Folder
for pm in doc.iterchildren():
if hasattr(pm, 'LineString'):
name = pm.name.text
coordinates = pm.LineString.coordinates.text
cordinatesinline = coordinates.split('\n')
cordinatesasarray = []
for line in cordinatesinline:
pattern = re.compile("^\s+|\s*,\s*|\s+$")
array = [x for x in pattern.split(line) if x]
if array:
cordinatesasarray.append(array)
all_routes[name]= cordinatesasarray
canvas=canvas.Canvas("route.pdf", pagesize=letter)
canvas.setLineWidth(.8)
canvas.setFont('Helvetica', 6)
for name in all_routes:
x=[]
y=[]
for points in all_routes[name]:
x.append(points[0])
y.append(points[1])
i=0
for a in x:
if i < len(x)-1:
x_new=translate(float(x[i]),float(min(x)), float(max(x)),50,500)
y_new=translate(float(y[i]),float(min(y)),float(max(y)),50,500)
x_new2=translate(float(x[i+1]),float(min(x)), float(max(x)),50,500)
y_new2=translate(float(y[i+1]),float(min(y)),float(max(y)),50,500)
print x_new,y_new,x_new2,y_new2
canvas.line(x_new,y_new,x_new2,y_new2)
i=i+1
canvas.drawString(10,45,name)
canvas.showPage()
canvas.save()