Giter Club home page Giter Club logo

Comments (2)

sanhozay avatar sanhozay commented on May 22, 2024

Thanks Israel

from pilotlog.

FGDATA avatar FGDATA commented on May 22, 2024

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)

from pilotlog.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.