[GIS] Importing Data from API-Website into QGIS

apiimportqgis

I am trying to use the map data, found on this website

https://fixmyberlin.de/planungen

and import it to QGIS. Specifically I am looking for the bike paths shown there. I have contacted them and they sent me a link to the API version of their website:

https://api.fixmyberlin.de/api/projects?page_size=200

Since I am new to QGIS and that whole topic, I really don't know what to do further.

Best Answer

You can run the following in the QGIS Python console to write a GeoJSON

from urllib.request import urlopen
import json

url = "https://api.fixmyberlin.de/api/projects?page_size=200"
html = urlopen(url)
data = json.load(html)

geojson = {
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "properties": {
        "id": bike_path['id'],
        "url": bike_path['url'],
        "project_key": bike_path['project_key'],
        "title": bike_path['title'],
        "description": bike_path['description'],
        "short_description": bike_path['short_description'],
        "category": bike_path['category'],
        "street_name": bike_path['street_name'],
        "borough": bike_path['borough'],
        "side": bike_path['side'],
        "costs": bike_path['costs'],
        "draft_submitted": bike_path['draft_submitted'],
        "construction_started": bike_path['construction_started'],
        "construction_completed": bike_path['construction_completed'],
        "phase": bike_path['phase'],
        "responsible": bike_path['responsible'],
        "external_url": bike_path['external_url'],
        "cross_section": bike_path['cross_section'],
        "faq": bike_path['faq'],
        "length": bike_path['length'],
        "photos": bike_path['photos'],
        "likes": bike_path['likes'],
        "liked_by_user": bike_path['liked_by_user']
      },
      "geometry": bike_path["geometry"]
    } for bike_path in data['results']]
}

with open('/tmp/my_geojson.geojson', 'w', encoding='utf-8') as outfile:
    json.dump(geojson, outfile)

PS: I do not manage the pagination here

You can change the path /tmp/my_geojson.geojson according to your need. Then, open the file as a vector layer in QGIS and it works.

An overview below with OSM background

Berlin Bike paths overview

Related Question