OpenStreetMap

Expanding Bisangkot to Malaysia

Posted by rtnf on 20 December 2023 in English.

Inspired by this talk, I aim to expand the coverage of this OSM-public-transportation-route-viewer to include Malaysia.

To begin, I extracted this list from routes.tracestrack.com, comprising 236 bus route relations in Malaysia (last data update: 30 Oct 2023). My objective is to obtain the OSM ID for each route listed. Therefore, I copied all the data (Ctrl+A, Ctrl+V) into a plaintext file, saved it, and processed it with this simple Python script.

def process_line(line):
    if "iDJOSM" in line:
        print(line.split(" ")[0], end=",")
    
def process_file(file_path):
    try:
        with open(file_path, 'r') as file:
            for line in file:
                process_line(line)
    except FileNotFoundError:
        print("File not found:", file_path)
    except Exception as e:
        print("An error occurred:", str(e))

if __name__ == "__main__":
    file_path = 'my.txt'
    process_file(file_path)

Subsequently, I used this list of OSM route IDs to download all the routes using JOSM. File -> Download object… -> Object type: relation -> Download relation members -> Download object.

After waiting for the download to complete, I saved the download data as an OSM file.

Following this, I used this script to preprocess all the downloaded routes, converting the OSM file to a GeoJSON file.

Finally, I embedded the resulting GeoJSON file into a leaflet viewer. And it’s done.

See the result here : https://altilunium.github.io/bisangkot/my.html

And here is the tabular view : https://github.com/altilunium/bisangkot/wiki/v23.12.20

Discussion

Comment from GOwin on 24 December 2023 at 08:19

Thank you for sharing @rtnf, and we’re glad that you were able to join us and found inspiration from last week’s activity, specifically Nabil’s snappy map-py talk. That’s an awesome follow-up. 😊

We’re looking forward to seeing you again in next month’s Map-py Wednesday.

Log in to leave a comment