Saturday 4 August 2018

TrafficControl: Refactoring the KML Parser

Until now, the KML parser (trackStationConnector.py) expected the tracks to be in one folder, stations to be in another one and junctions to be in a third folder. This made it more difficult to use the program.

After the refactoring of the KML parser, the parser doesn't care where the tracks/stations/junctions are.

Placemarks are interpreted as below:

  • A placemark with only one coordinate will be seen as a station or a junction. 
    • If the name of that placemark starts with an uppercase "J" and the second character is also uppercase, that placemark is a junction. Example: "JHyllieS".
    • Otherwise, it is a station. Example: "JerusalemC".
  • A placemark with more than one coordinate is a track. 
    • If the name of the track starts with "d", it is a double track. The parser will create two parrallel tracks. Example: "dLun-Sta" becomes "dLun_Sta_N" and "dLun_Sta_S".

I used regular expressions in the new script. There is some more work with this script and I'll elaborate more about that in future blog posts.




No comments:

Post a Comment