[Talk-it] Cambiare formato testo in JOSM
Groppo
groppo8 a gmail.com
Sab 28 Set 2013 10:13:56 UTC
Il giorno 27 settembre 2013 23:23, marco bra <marcobra.ubuntu at gmail.com> ha
scritto:
> Groppo, non ho usato il tuo script, ma l'ho provato ed e' potente,
> sarebbero da discriminare alcune liste di parole... che non vanno
> maiuscole... "di", "del" etc.
>
Sì, il mio era un esempio per far vedere cosa si può fare.
Lo si può modificare/migliorare in base alle proprie esigenze.
Ad esempio, con le modifiche qui sotto (vedi "### aggiunta"), tiene conto
di alcune preposizioni ed alla fine stampa sul terminale la lista dei nomi
e le loro conversioni.
#codice script
"""
Capitalize words of "name=*" tags in JOSM
"""
import sys
from javax.swing import JOptionPane
from org.openstreetmap.josm import Main
def getMapView():
if Main.main and Main.main.map:
return Main.main.map.mapView
else:
JOptionPane.showMessageDialog(Main.parent, "Apri dei dati, prima di
eseguire lo script.")
sys.exit(1)
#### aggiunta
prepositions = [" di ", " del ", " della ", " delle "]
mv = getMapView()
if mv and mv.editLayer and mv.editLayer.data:
dataset = mv.editLayer.data
elements = []
elements.extend(dataset.nodes)
elements.extend(dataset.ways)
elements.extend(dataset.relations)
#For each OSM object in the dataset
for element in elements:
tags = element.getKeys()
if len(tags) != 0:
if "name" in tags:
#capitalize words of "name" value
oldName = element.get("name")
newName = oldName.title()
#### aggiunta
for prep in prepositions:
newName = newName.replace(prep.title(), prep.lower())
tags["name"] = newName
#Print names to terminal
print "%s ---> %s" % (oldName, newName)
#Update element tags
element.setKeys(tags)
JOptionPane.showMessageDialog(Main.parent, "Done.")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/talk-it/attachments/20130928/0355ae14/attachment.html>
Maggiori informazioni sulla lista
Talk-it