Transport for London (TfL) CID Conflation Scripts

From OpenStreetMap Wiki
Jump to navigation Jump to search

It is proposed that there are instances where OSM's APIs are an appropriate mechanism to enable conflation. This page lays out the proposed use of the APIs in line with the rules and guidance laid out for the use of the OSM API:

Conflation

There are certain assets and certain scenarios, where it has been determined that JOSM is not the most appropriate mechanism of conflation. It is intended that the proposal to use the following scripts are reviewed by the OSM community. This page will be updated based on any feedback through correspondence on mailing lists. The following scripts have been created to enable conflation through the OSM API. All scripts have been tested in the sandbox environment to confirm they perform as expected.

cycle_parking

The following script is used to import a pre-filtered list of cycle_parking assets into OSM

for i in id_list:
    subset = selected_parking[selected_parking.id == i]
    ward = subset.NAME.unique()[0]
    number_of_assets = len(subset)
    changeset_comment =  str(number_of_assets) + ' parking assets from TfL CID inside ' + ward
    with MyApi.Changeset({u"comment": changeset_comment}) as changeset_id:
        for row in subset.iterrows():
            tag = row[1].drop(['X','Y','id','NAME'])
            #select not null attribute
            tag = tag[-tag.isnull()]
            #convert capacity to data type string from int
            tag['capacity'] = str(tag['capacity'])
            #convert object data type to dictionary
            tag = dict(tag)
            MyApi.NodeCreate({"lat":row[1]['Y'],"lon":row[1]['X'],u"tag":tag})
        #MyApi.ChangesetClose()

traffic_calming: humps

The following code snippet extracts (traffic calming: hump) assets existing is OSM which have not been updated since the TfL asset survey date of May 2018. These are the assets where tags benefit from information from with the survey.

with MyApi.Changeset({u"comment": changeset_comment, 'source':'tfl_cycle_database'}) as changeset_id:
        for row in selected_bumps.iterrows():
            osm_id = row[1]['osm_id']
            tag = row[1].drop(['X','Y','osm_id','id','NAME'])
            #select not null attribute
            tag = tag[-tag.isnull()]
            #convert tag to dictionary
            tag = dict(tag)
            
            #get osm tags
            item = MyApi.NodeGet(osm_id)
            osm_tag = item['tag']
            
            #update the osm tag by comparing with tfl cid
            for key in tag.keys():
                osm_tag[key] = tag[key]
                
            MyApi.NodeUpdate({u"id":item['id'], "version": item['version'], "lat":item['lat'],"lon":item['lon'],"tag":osm_tag})