Saturday, 10 February 2018

TrafficControl: Making TrackStationConnector Ignore Hidden Tracks/Stations

The python script TrackStationConnector adds tracks/stations and connects them to each other. if they are close enough. The input is a KML file, and the output defines the train network.

In Google Earth, it is possible to hide items. They are still present in the KML file but not visible.
Currently, that script adds all items it finds (including hidden items), and I need to make the script only consider the enabled items.

The invisible station has a corresponding tag.
When an item is hidden in the KML file, there is a visibility tag that is set to 0. That tag is present both for folders (meaning that there are no visible items in that folder) and for the hidden items.

To make the python script ignore the invisible tracks, I added a boolean variable ignorePM. That variable is set to false when the script reaches a placemark. If the script reaches the visibility tag, it sets the variable to 1.  The corresponding station/junction/track is created only if ignorePM is set to false and the placemark isn't added to the track network.

ignorePM is set to true if the visibility tag is present for the placemark. That variable is later used to decide whether to process that particular placemark.
Further, I've found a bug. The program assumes that all tracks has a station or junction at the start and end of the track. If that is not the case, the python script will use the same station for start and end for a track. I resolved that by adding a condition for connecting tracks to stations.

If the closest station is more than 200 meters from the end/start of the track, the script concludes that the search fails. In that case, the program will add the track but not connect it to any stations.

No comments:

Post a Comment