Created
November 26, 2014 03:10
-
-
Save Rub21/cc055320c925c855926e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function current_layer() { | |
var layers = require("josm/layers"); | |
return layers.activeLayer; | |
} | |
function rename_highways() { | |
var layer = current_layer(); | |
if (layer == null) return; | |
var util = require("josm/util"); | |
var command = require("josm/command"); | |
var console = require("josm/scriptingconsole"); | |
var abbr = ["ca.", "ca", "psj.", "psj", "pje.", "pje", "jr .", "jr.", "jr", "av.", "av", "jiron", "Psje.", "prol."]; | |
var full = ["Calle", "Calle", "Pasaje", "Pasaje", "Pasaje", "Pasaje", "Jirón", "Jirón", "Jirón", "Avenida", "Avenida", "Jirón", "Pasaje", "Prolongación"]; | |
var dataset = layer.data; | |
var result = dataset.query("type:way"); | |
var renames = 0; | |
console.println("number of ways: " + result.length); | |
for (j = 0; j < result.length; j++) { | |
var way = result[j]; | |
var name = way.get("name"); | |
if (name == null) continue; | |
if (name.length() < 4) continue; | |
var words = name.split(" "); | |
if (words.length < 2) continue; | |
var word = words[0].toLowerCase(); | |
var found = -1; | |
for (var a = 0; a < abbr.length; a++) { | |
if (abbr[a] == word) found = a; | |
} | |
if (found == -1) continue; | |
var newname = ""; | |
for (var w = 0; w < words.length; w++) { | |
if (w == 0) { | |
newname += full[found]; | |
} else { | |
newname += words[w]; | |
} | |
newname += " "; | |
} | |
console.println(" rename [" + name + "] to [" + newname + "]"); | |
layer.apply(command.change(dataset.way(way.id), { | |
tags: { | |
name: newname | |
} | |
})); | |
renames++; | |
way.setModified(true); | |
} | |
console.println("renames:" + renames); | |
} | |
rename_highways(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment