Mechanical Edits/starsep-bot/retag parcel locker

From OpenStreetMap Wiki
Jump to navigation Jump to search

Page content created as advised on Automated_Edits_code_of_conduct#Document_and_discuss_your_plans.

There are two tagging schemes for parcel lockers:

  1. old with amenity=vending_machine vending=parcel_pickup and/or vending=parcel_mail_in
  2. new scheme with amenity=parcel_locker parcel_mail_in=* parcel_pickup=*

Parcel lockers mapped using both schemes are present in Poland. This automated edit changes old tagging scheme to new scheme within Poland.

Who

I, User:starsep using my bot account

contact

message via OSM I will respond also to PMs to the bot account, though messaging my main account is preferable.

English and Polish languages are preferable, for other I need to use an automatic translator.

What

Changing amenity=vending_machine to amenity=parcel_locker if vending=* has appropriate value.
1. vending=parcel_pickup;parcel_mail_in, vending=parcel_pickup; parcel_mail_in, or vending=parcel_mail_in;parcel_pickup => remove vending tag and set parcel_mail_in=yes.
2. vending=parcel_pickup => remove vending tag.

Editing is restricted to Poland.

Why

New scheme has been approved https://wiki.openstreetmap.org/wiki/Proposed_features/amenity%3Dparcel_locker
Number of elements modified is too large for manual retagging.

How

A theoretical example:
state before a mechanical edit:

state after a mechanical edit:

Changeset would be described and tagged with tags that mark it as automatic, provide link to discussion approving edit etc

Discussion

Discussed by Polish OSM community at https://forum.openstreetmap.org/viewtopic.php?id=74790 There were no votes against automatic retagging. Only concern was that it might take some time to implement new scheme in 3rd party software (data consumers). As 3 months have passed I believe anybody concerned had a chance to upgrade.

Repetition

This is one-time edit. It is expected that tricky cases, especially vending values not listed here, will be handled manually. Further tagging of parcel lockers using old scheme will be handled manually as well.

Opt-out

Please write at https://forum.openstreetmap.org/viewtopic.php?id=74790 .

Source code

I license this code as GNU AGPLv3. It is also available at https://github.com/starsep/osm-automated-edits/blob/main/retag-parcel-lockers.py It is using https://github.com/matkoniecz/osm_bot_abstraction_layer library.

#!/usr/bin/env python3
from osm_bot_abstraction_layer.generic_bot_retagging import run_simple_retagging_task


OVERPASS_QUERY = """
[out:xml][timeout:25000];
area[name='Polska']->.searchArea;
(
  nwr["amenity"="vending_machine"]["vending"~"(parcel_pickup|parcel_mail_in)"](area.searchArea);
);
out body;
"""


def edit_element(tags):
    if tags["amenity"] != "vending_machine":
        return tags
    vending = tags["vending"]
    if not ("parcel_pickup" in vending or "parcel_mail_in" in vending):
        return tags
    if vending in {
        "parcel_pickup;parcel_mail_in",
        "parcel_pickup; parcel_mail_in",
        "parcel_mail_in;parcel_pickup",
    }:
        tags["amenity"] = "parcel_locker"
        del tags["vending"]
        tags["parcel_mail_in"] = "yes"
    elif vending == "parcel_pickup":
        tags["amenity"] = "parcel_locker"
        del tags["vending"]
    else:
        print(f"Unexpected vending={vending}")
    return tags


def main():
    run_simple_retagging_task(
        max_count_of_elements_in_one_changeset=500,
        objects_to_consider_query=OVERPASS_QUERY,
        objects_to_consider_query_storage_file="parcel_lockers.osm",
        is_in_manual_mode=False,
        changeset_comment="Zmiana tagowania paczkomatów z amenity=vending_machine na amenity=parcel_locker",
        discussion_url="https://forum.openstreetmap.org/viewtopic.php?id=74790",
        osm_wiki_documentation_page="https://wiki.openstreetmap.org/wiki/Mechanical_Edits/starsep-bot/retag_parcel_locker",
        edit_element_function=edit_element,
    )


if __name__ == "__main__":
    main()