-
Notifications
You must be signed in to change notification settings - Fork 1
/
replace.js
78 lines (68 loc) · 2.04 KB
/
replace.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Script page: https://wiki.openstreetmap.org/wiki/User:SafwatHalaby/scripts/russianImportFix
Last update: 17 Dec 2017
Typical node fetching query (Overpass API):
[out:xml][timeout:500][bbox:{{bbox}}];
(area(3601473946); area(3603791785);)->.a;
(
node["name:ru"];
way["name:ru"];
relation["name:ru"];
);
out meta;
*/
var gReplaceTag = "name:ru"
var gReplaceTable = {
"Наси Бен-Цви Avenue": "проспект Наси Бен-Цви",
"ХаНамаль": "ХаНамель",
"Заменхоф": "Заменгоф"};
var print = require("josm/util").println;
function main()
{
var cntModifiedFullMatch = 0;
// var cntModifiedPartialMatch = 0;
var cntAll = 0;
for (key in gReplaceTable)
{
if (key.indexOf("Xa ") != -1)
{
gReplaceTable[key.replace("Xa ", "Xa")] = gReplaceTable[key];
print(key.replace("Xa ", "Xa") + ">" + gReplaceTable[key.replace("Xa ", "Xa")]);
}
}
print("");
print("### Running script script");
var layer = josm.layers.get("auto.osm");
var ds = layer.data;
ds.each(function(p){ // foreach element
// if (p.tags["ignore_this_bot"] !== undefined) return;
var originalName = p.tags[gReplaceTag];
if (originalName === undefined) return;
var newName = gReplaceTable[originalName];
if ((newName !== undefined) && (originalName != newName))
{
p.tags[gReplaceTag] = gReplaceTable[originalName];
cntModifiedFullMatch++;
return;
}
/* for (key in gReplaceTable)
{
if (originalName.indexOf(key) != -1)
{
p.tags[gReplaceTag] = originalName.replace(key, gReplaceTable[key]);
originalName = p.tags[gReplaceTag];
cntModifiedPartialMatch++;
}
} */
cntAll++;
});
print("Total full match modifications: " + cntModifiedFullMatch);
// print("Total partial match modifications: " + cntModifiedPartialMatch);
print("Total scanned: " + cntAll);
// print("Total unmodified: " + (cntAll - cntModifiedFullMatch - cntModifiedPartialMatch));
print("Total unmodified: " + (cntAll - cntModifiedFullMatch));
print("");
print("### Script finished");
// josm.commands.undo(1000);
}
main();