Closed FGDATA closed 5 years ago
Thanks Israel
No problem. The primitive python code that I drafted fast and furious for creating the geoJSON specification is pasted below
from sys import argv
import xml.etree.ElementTree as ET
#global variables
separator=","
#open files
tracker_file=argv[1]
route_file=argv[2]
tree = ET.parse(route_file)
root = tree.getroot()
json_file=open(argv[3],"w")
with open(tracker_file) as f:
lines = [line.rstrip('\n').split(separator) for line in open(tracker_file)]
del lines[0:5]
#read generic output csv and preproccess
callsign=lines[-1][0]
aircraft=lines[-1][1]
server=lines[-1][2]
GMT_departure=lines[0][3]
GMT_arrival=lines[-1][3]
elapsedtime=[float(lines[0][4])]
for i in lines:
elapsedtime.append(float(i[4]))
simrate=[float(lines[0][5])]
for i in lines:
simrate.append(float(i[5]))
lon=[float(lines[0][6])]
for i in lines:
lon.append(float(i[6]))
lat=[float(lines[0][7])]
for i in lines:
lat.append(float(i[7]))
elev=[float(lines[0][8])]
for i in lines:
elev.append(float(i[8]))
coordinates=[[lon[0],lat[0],elev[0]]]
for i in range(1,len(elev)):
coordinates.append([lon[i],lat[i],elev[i]])
agl=[float(lines[0][9])]
for i in lines:
agl.append(float(i[9]))
gs=[float(lines[0][10])]
for i in lines:
gs.append(float(i[10]))
elapsedtimeText = ','.join(map(str, elapsedtime))
simrateText = ','.join(map(str, simrate))
aglText = ','.join(map(str, agl))
gsText = ','.join(map(str, gs))
coordinatesText = ',\n\t\t'.join(map(str, coordinates))
departure=coordinates[0]
arrival=coordinates[-1]
##Reading the GPX route
pointNames=[]
pointCoords=[[0,0]]
for elem in tree.iter():
if "name" in elem.tag:
pointNames.append(elem.text)
if "rtept" in elem.tag:
pointCoords.append([float(elem.attrib["lon"]),float(elem.attrib["lat"])])
del pointNames[0]
del pointCoords[0]
print pointNames
print pointCoords
pointCoordsText = ',\n\t\t'.join(map(str, pointCoords))
pointNamesText = ',\n\t\t'.join(map(str, pointNames))
##write geojson
#produces a valid geoJson specification
#Blackbox
json_file.write("{ \"type\": \"FeatureCollection\",\n")
json_file.write(" \"features\": [\n")
json_file.write(" { \"type\": \"Feature\",\n")
json_file.write("\t\"geometry\": {\n")
json_file.write("\t \"type\": \"LineString\",\n")
json_file.write("\t \"coordinates\": [\n")
json_file.write("\t\t" + coordinatesText)
json_file.write("\n\t ]\n")
json_file.write("\t},\n")
json_file.write("\t\"properties\": {\n")
json_file.write(" \"stroke\": \"#cd3232\",\n")
json_file.write(" \"stroke-width\": 3,\n")
json_file.write(" \"stroke-opacity\": 0.75,\n")
json_file.write("\t \"title\": \"blackbox\",\n")
json_file.write("\t \"callsign\":" + callsign + ",\n")
json_file.write("\t \"aircraft\":" + aircraft + ",\n")
json_file.write("\t \"server\":" + server + ",\n")
json_file.write("\t \"elapsed time (s)\": [" + elapsedtimeText + "],\n")
json_file.write("\t \"AGL (ft)\": [" + aglText + "],\n")
json_file.write("\t \"ground speed (kts)\": [" + gsText + "],\n")
json_file.write("\t \"simrate\": [" + simrateText + "]\n")
json_file.write("\t}\n")
json_file.write(" },\n")
json_file.write(" { \"type\": \"Feature\",\n")
json_file.write(" \"geometry\": {\n")
json_file.write(" \"type\": \"Point\",\n")
json_file.write(" \"coordinates\": ")
json_file.write(str(departure))
json_file.write("\n },\n")
json_file.write(" \"properties\": {\n")
json_file.write(" \"marker-size\": \"small\",\n")
json_file.write(" \"marker-symbol\": \"circle\",\n")
json_file.write(" \"marker-color\": \"#00f705\",\n")
json_file.write(" \"title\": \"departure\",\n")
json_file.write(" \"GMT\":" + GMT_departure + "\n")
json_file.write(" }\n")
json_file.write(" },\n")
json_file.write(" { \"type\": \"Feature\",\n")
json_file.write(" \"geometry\": {\n")
json_file.write(" \"type\": \"Point\",\n")
json_file.write(" \"coordinates\":\n")
json_file.write(str(arrival))
json_file.write("\n },\n")
json_file.write(" \"properties\": {\n")
json_file.write(" \"marker-size\": \"small\",\n")
json_file.write(" \"marker-symbol\": \"star-stroked\",\n")
json_file.write(" \"marker-color\": \"#0a00f7\",\n")
json_file.write(" \"title\": \"arrival\",\n")
json_file.write(" \"GMT\":" + GMT_arrival + "\n")
json_file.write(" }\n")
json_file.write(" },\n")
#route
json_file.write(" { \"type\": \"Feature\",\n")
json_file.write("\t\"geometry\": {\n")
json_file.write("\t \"type\": \"LineString\",\n")
json_file.write("\t \"coordinates\": [\n")
json_file.write("\t\t" + pointCoordsText)
json_file.write("\n\t ]\n")
json_file.write("\t},\n")
json_file.write("\t\"properties\": {\n")
json_file.write(" \"stroke\": \"#000066\",\n")
json_file.write(" \"stroke-width\": 3,\n")
json_file.write(" \"stroke-opacity\": 0.75,\n")
json_file.write("\t \"title\": \"route\"\n")
json_file.write("\t}\n")
json_file.write(" },\n")
#routePTS
for pts in range(len(pointNames)-1):
json_file.write(" { \"type\": \"Feature\",\n")
json_file.write(" \"geometry\": {\n")
json_file.write(" \"type\": \"Point\",\n")
json_file.write(" \"coordinates\": ")
json_file.write(str(pointCoords[pts]))
json_file.write("\n },\n")
json_file.write(" \"properties\": {\n")
json_file.write(" \"marker-size\": \"small\",\n")
json_file.write(" \"marker-symbol\": \"circle\",\n")
json_file.write(" \"marker-color\": \"#000066\",\n")
json_file.write(" \"waypoint\": \"" + pointNames[pts] +"\"\n")
json_file.write(" }\n")
json_file.write(" },\n")
json_file.write(" { \"type\": \"Feature\",\n")
json_file.write(" \"geometry\": {\n")
json_file.write(" \"type\": \"Point\",\n")
json_file.write(" \"coordinates\": ")
json_file.write(str(pointCoords[-1]))
json_file.write("\n },\n")
json_file.write(" \"properties\": {\n")
json_file.write(" \"marker-size\": \"small\",\n")
json_file.write(" \"marker-symbol\": \"circle\",\n")
json_file.write(" \"marker-color\": \"#000066\",\n")
json_file.write(" \"waypoint\": \"" + pointNames[-1] +"\"\n")
json_file.write(" }\n")
json_file.write(" }\n")
json_file.write(" ]\n")
json_file.write("}\n")
Clearly I could've use some JSON modlues to do a nicer job, but Oh well! (License: Public Domain. Author: IAHM-COL)
a csv file created using generic protocol. 2018-03-07_01:25:38-blackbox.csv.zip
a geojson generated with a dirty python script from that csv 2018-03-02_05:54:28-flight.geojson.zip