You are not logged in.

#1 2020-01-08 22:26:22

jrk
Member
Registered: 2020-01-08
Posts: 2

How to update node in Python osmapi?

Hello. I would like to update OpenStreetMap with Python using osmapi module.

I wanted update name of node 6258337521 from value "Biblioteka Miejska w Łodzi Filia nr 63" to value "Biblioteka Miejska w Łodzi, Filia nr 63" (in English: "City Library in Lodz, Branch No. 63")

Below is IPython session:

In [1]: from osmapi import OsmApi

In [2]: myApi = OsmApi(username="jrk", password="********")

In [3]: myApi.ChangesetCreate({u"comment": u"Dodanie przecinka w nazwie"})

Out[3]: 79355591

In [4]: f63 = myApi.NodeGet('6258337521')

In [5]: f63

Out[5]:
{'id': 6258337521,
 'visible': True,
 'version': 2,
 'changeset': 72857560,
 'timestamp': datetime.datetime(2019, 7, 31, 13, 39, 34),
 'user': 'BMwL',
 'uid': 9655269,
 'lat': 51.7672921,
 'lon': 19.4787142,
 'tag': {'addr:city': 'Łódź',
  'addr:country': 'PL',
  'addr:housenumber': '75',
  'addr:postcode': '90-031',
  'addr:street': 'Tuwima',
  'amenity': 'library',
  'contact:email': 'filia_63@biblioteka.lodz.pl',
  'contact:phone': '+48 42 674 48 73',
  'name': 'Biblioteka Miejska w Łodzi Filia nr 63',
  'operator': 'Biblioteka Miejska w Łodzi',
  'wheelchair': 'no'}}

In [6]: myApi.NodeUpdate({'id': 6258337521, 'lat': f63['lat'], 'lon': f63['lon'], 'version': f63['version'], 'tags': {'name': 'Biblioteka Miejska w Łodzi, Filia nr 63'} })

Out[6]:
{'id': 6258337521,
 'lat': 51.7672921,
 'lon': 19.4787142,
 'version': 3,
 'tags': {'name': 'Biblioteka Miejska w Łodzi, Filia nr 63'},
 'changeset': 79355591}

In [7]: myApi.ChangesetClose()

Out[7]: 79355591

In [8]:

Changeset was saved, but unfortunately without my change. What did I do wrong?

https://www.openstreetmap.org/node/6258337521
https://www.openstreetmap.org/changeset/79355591

Best regards,
jrk

Offline

#2 2020-01-09 01:53:17

jrk
Member
Registered: 2020-01-08
Posts: 2

Re: How to update node in Python osmapi?

OK, I managed to find out how to do it. it was a typo, I wrote "tags" instead of "tag".

Here is the code that works:

from osmapi import OsmApi

myApi = OsmApi(username='jrk', password='********')

myApi.ChangesetCreate({'comment': 'Added opening_hours tag'})

node = myApi.NodeGet('6665468241')

tag = node['tag']
tag['opening_hours'] = 'Mo 11:00-15:00; We 09:00-14:00; Fr 11:00-15:00'
tag['opening_hours:url'] = 'https://www.biblioteka.lodz.pl/znajdz-filie/'

myApi.NodeUpdate({
    'id': 6665468241,
    'lat': node['lat'],
    'lon': node['lon'],
    'version': node['version'],
    'tag': tag })

myApi.ChangesetClose()

Offline

#3 2020-01-15 13:43:51

SimonPoole
Member
Registered: 2010-03-14
Posts: 1,856

Re: How to update node in Python osmapi?

Two remarks:

- when testing new applications -always- use the sandbox API when uploading (https://master.apis.dev.openstreetmap.o … 52/8.40007) or install a rails-port instance locally.
- given there is really only one reason to do what you are doing: https://wiki.openstreetmap.org/wiki/Aut … of_conduct

Offline

Board footer

Powered by FluxBB