Most capitals in the world are using public city bicycle service, which reduces fuel consumption, emissions, and congestion in city centers. Bike-sharing also encourages physical activity and can contribute to the health of city residents [1].

Image for post

Photo by Jasser Gómez on Unsplash

Data Ingestion

Fortunately, it exists an open CityBikes API that can be used to examine in real-time the status of the bike’s stations (for example, we can check the number of free slots in any station). Furthermore, there is a python package python-citybikesfor querying the CityBikes API.

Barcelona is one of these cities that expose data using CytyBikes API. Using the above-mentioned package, Barcelona’s bicycle service (aka bicing) can be queried using the following code:

client = citybikes.Client()
bicing = citybikes.Network(client, uid='bicing')
bicing.stations

The former call returns the station’s data in JSON format:

{
    "company": ["Barcelona de Serveis Municipals, S.A. (BSM)", "CESPA", "PBSC"],
    "href": "/v2/networks/bicing",
    "id": "bicing",
    "location": {
        "city": "Barcelona",
        "country": "ES",
        "latitude": 41.3850639,
        "longitude": 2.1734035
    },
    "name": "Bicing",
    "stations": [
        {
            "empty_slots": 17,
            "extra": {
                "ebikes": 0,
                "has_ebikes": true,
                "normal_bikes": 16,
                "online": true,
                "uid": 361
            },
            "free_bikes": 16,
            "id": "ed25291d0f5edd91615d154f243f82f9",
            "latitude": 41.376433,
            "longitude": 2.17871,
            "name": "PG. DE COLOM (LES RAMBLES)",
            "timestamp": "2020-10-16T18:19:06.097000Z"
        },
        ...
    ]
}

#spatial-analysis #python #data-science #data-visualization #gis

GeoSpatial analysis in Python and Jupyter Notebooks
1.55 GEEK