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

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 our GBFS feed repository into GeoJSON
0007 # Useful for inspecting GBFS coverage areas
0008 
0009 import argparse
0010 import json
0011 import os
0012 import re
0013 
0014 parser = argparse.ArgumentParser(description='Generates a GeoJSON document from GBFS feed repository')
0015 parser.add_argument('--feeds', type=str, required=True, help='Path to the GBFS feed repository file')
0016 arguments = parser.parse_args()
0017 
0018 output = {}
0019 output['type'] = 'FeatureCollection'
0020 output['name'] = 'GBFS Feeds'
0021 output['features'] = []
0022 
0023 inFile = open(arguments.feeds, 'r')
0024 inJson = json.load(inFile)
0025 
0026 for feed in inJson:
0027     properties = {}
0028     properties['name'] = feed['systemId']
0029     properties['url'] = feed['discoveryUrl']
0030     feature = {}
0031     feature['type'] = 'Feature'
0032     feature['properties'] = properties
0033 
0034     geometry = {}
0035     geometry['type'] = 'Polygon'
0036     bb = feed['boudingBox']
0037     coords = [[bb['x1'], bb['y1']], [bb['x2'], bb['y1']], [bb['x2'], bb['y2']], [bb['x1'], bb['y2']], [bb['x1'], bb['y1']]]
0038     geometry['coordinates'] = [coords]
0039     feature['geometry'] = geometry
0040 
0041     output['features'].append(feature)
0042 
0043 print(json.dumps(output))
0044