File indexing completed on 2024-04-28 04:41:45

0001 #!/usr/bin/env python3
0002 #
0003 # SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0004 # SPDX-License-Identifier: LGPL-2.0-or-later
0005 #
0006 # Converts a serialized journey query response into GeoJSON
0007 # Useful for inspecting navigation path details in QGIS
0008 #
0009 
0010 import argparse
0011 import json
0012 import os
0013 import re
0014 
0015 parser = argparse.ArgumentParser(description='Generates a GeoJSON document from journey query result')
0016 parser.add_argument('--journey', type=str, required=True, help='Path to the journey JSON')
0017 arguments = parser.parse_args()
0018 
0019 output = {}
0020 output['type'] = 'FeatureCollection'
0021 output['name'] = 'Journey Paths'
0022 output['features'] = []
0023 
0024 inFile = open(arguments.journey, 'r')
0025 inJson = json.load(inFile)
0026 
0027 for journey in inJson:
0028     for section in journey['sections']:
0029         if not 'path' in section:
0030             continue
0031         for path in section['path']['sections']:
0032             properties = {}
0033             properties['name'] = path.get('description', '<anonymous>')
0034             feature = {}
0035             feature['type'] = 'Feature'
0036             feature['properties'] = properties
0037             feature['geometry'] = path.get('path', {})
0038             output['features'].append(feature)
0039 
0040 print(json.dumps(output))