-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkommuner.py
62 lines (59 loc) · 6.25 KB
/
kommuner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from os import path
from OsmApi import OsmApi
osmtoolsrc = open(path.expanduser("~/.osmtoolsrc"))
username = False
password = False
for line in osmtoolsrc:
key, val = line.split("=", 1)
if key == 'username':
username = val.strip()
if key == 'password':
password = val.strip()
api = OsmApi.OsmApi(username=username, password=password, debug=True, dryrun=True)
# All muncipalities outside Stockholms lan
#kommuner = [935506,935547,935435,935684,935652,935425,935667,935465,935513,312618,935491,935633,935607,935478,935421,935565,296291,935406,307850,935544,935594,935659,935457,935642,935399,935404,935498,935438,935657,935636,935598,308557,935569,935571,935417,935504,935411,935600,300963,935619,935444,935683,935539,935431,307849,935604,935602,935543,1125739,935612,935415,935470,935446,278620,935611,935419,935405,935638,935572,935590,935442,1076755,935579,305452,300939,935560,935533,935672,289354,398567,935648,935677,935407,308558,935486,935534,935418,935649,935519,935552,935487,935623,935450,935630,935495,935474,935466,935617,935522,935520,935548,935514,935400,935606,935596,935541,935658,397128,935445,935448,935461,935615,935494,935626,935537,935505,935625,935409,935662,935414,935605,935673,307848,935550,935521,935469,935526,935557,935467,935542,935592,935563,935410,57886,935482,935666,935428,935549,935416,935398,935500,935422,935639,935621,935622,935507,304100,935668,935634,935678,935501,935463,935575,935518,935472,307885,935645,935647,935447,935593,935475,935516,935670,278632,935603,290048,935532,935492,935653,368254,935524,935573,935656,935530,935490,935558,935681,935527,300964,369508,278633,935529,935525,935508,935576,935423,935437,935485,307884,935624,935655,935430,935502,935503,935493,935479,398917,935489,935413,935497,935627,935426,935403,935510,935586,935597,300938,935481,296292,935556,398919,935608,935640,935650,935567,305453,935568,935578,1120171 ,935671,935682,935512,935584,935570,935531,935609,935460,935637,935644,935554,935646,305455,935488,935553,935581,935443,57891,935476,935585,935451,935454,935528,935546,935402,935676,935441,935453,935564,935439,935408,935588,935654,935618,935599,935601,935477,935429,935665,935432,935517,935464,935538,935540,289344,935574,935679,1120170,935434,935628,935449,935455,935577,398892,935535,935629,935620]
# All municipalities
kommuner = [935506,935547,935435,935684,935652,935425,935667,935465,935513,312618,935491,935633,935607,935478,935421,935565,296291,935406,307850,935544,398626,935594,935659,935457,935642,935399,935404,398034,935498,935438,935657,398920,935636,935598,308557,935569,935571,935417,935504,935411,935600,300963,935619,935444,935683,935539,935431,307849,935604,935602,935543,1125739,935612,935415,935470,935446,278620,935611,935419,935405,935638,935572,935590,935442,1076755,398625,935579,305452,300939,935560,935533,935672,289354,398567,935648,935677,935407,308558,935486,935534,935418,935649,935519,935552,935487,935623,935450,935630,398022,935495,935474,935466,935617,935522,935520,935548,935514,935400,935606,935596,935541,935658,397128,935445,935448,935461,935615,935494,935626,935537,935505,935625,935409,935662,935414,935605,935673,307848,935550,935521,398035,935469,935526,935557,935467,935542,935592,935563,935410,57886,935482,935666,935428,935549,935416,935398,935500,935422,935639,935621,935622,935507,304100,935668,935634,935678,935501,935463,935575,935518,398038,935472,307885,935645,935647,935447,397159,935593,935475,935473,935516,398627,935670,278632,935603,290048,935532,935492,935653,368254,935524,935573,935656,935530,935490,935558,935681,935527,300964,369508,398918,278633,397127,935529,935525,935508,935576,935423,935437,935485,307884,935624,398023,398040,935655,935430,935502,935503,398021,935493,935479,398917,935489,935413,398039,935497,935627,935426,935403,935510,935586,935597,300938,935481,296292,935556,398919,935608,935640,935650,935567,305453,935568,935578,1120171 ,935671,935682,935512,935584,935570,935531,935609,935460,398575,397194,935637,935644,935554,935646,397187,369474,305455,935488,935553,935581,935443,959462,57891,935476,935585,398036,935451,935454,935528,935546,935402,935676,935441,935453,935564,398649,935439,935408,935588,935654,935618,935599,935601,935477,935429,935665,935432,935517,935464,935538,935540,289344,935574,935679,1120170,935434,935628,935449,935455,935577,398037,398892,935535,935629,935620]
# Test cases
kommuner = [935666, 935410]
api.ChangesetCreate({u"comment": u"Rename municipalities, add short_name and name:sv", u"bot": u"yes", u"type": u"automated"})
for kommun_id in kommuner:
k = api.RelationGet(kommun_id)
update = False
if 'name' in k['tag'] and 'official_name' in k['tag']:
if k['tag']['name'] != k['tag']['official_name']:
if 'short_name' not in k['tag'] and 'kommun' not in k['tag']['name']:
print "%d (%s): set short_name=%s" % (kommun_id, k['tag']['official_name'], k['tag']['name'])
k['tag']['short_name'] = k['tag']['name']
else:
print "%d (%s): short_name already exists, short_name=%s" % (kommun_id, k['tag']['official_name'], k['tag']['short_name'])
print u"%d (%s): set name=%s" % (kommun_id, k['tag']['official_name'], k['tag']['official_name'])
k['tag']['name'] = k['tag']['official_name']
update = True
if 'name:sv' not in k['tag'] or k['tag']['name:sv'] != k['tag']['official_name']:
print u"%d (%s): set name:sv=%s" % (kommun_id, k['tag']['official_name'], k['tag']['official_name'])
k['tag']['name:sv'] = k['tag']['official_name']
update = True
if update:
api.RelationUpdate(k)
api.ChangesetClose()
api.ChangesetCreate({u"comment": u"Copy KNKOD to ref and ref:scb", u"bot": u"yes", u"type": u"automated"})
for kommun_id in kommuner:
k = api.RelationGet(kommun_id)
update = False
if 'KNKOD' in k['tag']:
if 'ref' not in k['tag']:
print u"%d (%s): set ref=%s" % (kommun_id, k['tag']['official_name'], k['tag']['KNKOD'])
k['tag']['ref'] = k['tag']['KNKOD']
update = True
else:
print u"%d (%s): ref=%s already exists" % (kommun_id, k['tag']['official_name'], k['tag']['ref'])
if 'ref:scb' not in k['tag']:
print u"%d (%s): set ref:scb=%s" % (kommun_id, k['tag']['official_name'], k['tag']['KNKOD'])
k['tag']['ref:scb'] = k['tag']['KNKOD']
update = True
else:
print u"%d (%s): ref:scb=%s already exists" % (kommun_id, k['tag']['official_name'], k['tag']['ref:scb'])
if update:
api.RelationUpdate(k)
api.ChangesetClose()