Re: [josm-dev] Scripting plugin

2011-04-14 Thread Paul Hartmann

Jo wrote:

I'm back on track with the scripting plugin. I created a Jython script that
helps to find probable spelling errors in street names. It's quite specific
in that it supports the bilingual status of Brussels.

#!/bin/jython

#
# Spell checking.py  - Helps to locate probable spell errors
#
from javax.swing import JOptionPane
from org.openstreetmap.josm import Main
import org.openstreetmap.josm.command as Command
import org.openstreetmap.josm.data.osm.Node as Node
import org.openstreetmap.josm.data.osm.Way as Way
import org.openstreetmap.josm.data.osm.TagCollection as TagCollection
import org.openstreetmap.josm.data.osm.DataSet as DataSet

corrections = {'fr': [('Dr. ', 'Docteur '),('R. ', 'Rue '), ('Av. ',
'Avenue '), ('Bd. ', 'Boulevard '),
  ('Sq.', 'Square'), ('Pl.', 'Place'),
  (' De ', ' de '), (' Le ', ' le '), (' La ', ' la '),
(' Du ', ' du '), (' Des ', ' des '), (' Les ', ' les '),
  (' Au ', ' au '),(' Aux ', ' aux '),('À', 'à'),(' Den
',' den '), ( Sur ,  sur ),
  ( D', d'), ( L', l'), (' ,'),
  (Ecole ,École ), (Eglise, Église),
(Chateau, Château), (Cable, Câble), (General, Général)],
   'nl': [( Voor ,  voor ), ( Op ,  op ), ( Pour , 
pour ), ( Naar ,  naar ), ( Ter ,  ter ), ( En ,  en ), ( Van
,  van ),
  ('T , 't ), ('S , 's ), (-Ter-, -ter-),
( Het ,  het ),
  ( Straat, straat), ( Weg, weg), ( Laan,
laan), ( Steenweg, steenweg),
  ( Baan, baan), (Oudebaan, Oude Baan),
(Grotebaan, Grote Baan),
  (de Lijn, De Lijn)]}

commandsList = []
streetnames = {}

def getMapView():
if Main.main and Main.main.map:
return Main.main.map.mapView
else:
return None

def myOwnCapitalize(word):
# JOptionPane.showMessageDialog(Main.parent, word.decode('utf-8'))
if word:
return word[0].upper() + word[1:]
else:
return u

mv = getMapView()

if mv and mv.editLayer and mv.editLayer.data:
selectedNodes = mv.editLayer.data.getSelectedNodes()
selectedWays = mv.editLayer.data.getWays()
selectedRelations = mv.editLayer.data.getSelectedRelations()

if not(selectedNodes or selectedWays or selectedRelations):
JOptionPane.showMessageDialog(Main.parent, Please select
something)
else:
for way in selectedWays:
for isoLang in ['nl', 'fr', '']:
correctedName = result = u''
if isoLang:
nameColonIso = 'name:' + isoLang
else:
nameColonIso = 'name'
if way.hasKey(nameColonIso):
name=str(way.get(nameColonIso).encode('utf-8'))
if name in streetnames:
if streetnames[name] == 'ignore':
continue
else:
correctedName = streetnames[name]
else:
Main.main.getCurrentDataSet().setSelected(way)
# dummy = mv.editLayer.data.getSelected()
#
mv.zoomTo(Main.main.getEditLayer().data.getSelected())
# JOptionPane.showMessageDialog(Main.parent,
name.decode('utf-8'))
for subname in name.split(;):
for word in subname.split( ):
if word:
if - in word and len(word)1:
dashes = word.split(-)

correctedName +=
myOwnCapitalize(dashes[0])
for dash in dashes[1:]:
# if dash[0] == ' ':
# correctedName += u- +
myOwnCapitalize(dash[1:])
# else:
correctedName += u- +
myOwnCapitalize(dash.strip())
elif ' in word and not(. in word):
apo=word.split(')
if apo[0]: correctedName +=
myOwnCapitalize(apo[0])
correctedName += '
if apo[1]: correctedName +=
myOwnCapitalize(apo[1])
elif . in word or len(word)1 and
word[1]==word[1].upper() or len(word)2 and word[2]==word[2].upper():
correctedName += word
else:
correctedName +=
myOwnCapitalize(word)
correctedName += ' '
correctedName = correctedName.strip() + ';'
if correctedName and correctedName[-1] == ';':
correctedName = 

Re: [josm-dev] Scripting plugin

2011-04-14 Thread Jo
I will add it myself, but I'm still working on it, that's why I didn't do it
yet.

Cheers,

Polyglot

2011/4/14 Karl Guggisberg karl.guggisb...@guggis.ch

 A russian user created another script in JavaScript and announced it on the
 OSM blog. I've added a link to the ScriptingPlugin page,
 http://wiki.openstreetmap.org/wiki/JOSM/Plugins/Scripting. I'd like to add
 yours too, please let me know about an URL, if you publish it somewhere. Of
 course, you can add it to the Wiki yourself, if you want to.

 Regards
 Karl


 2011/4/14 Paul Hartmann phaau...@googlemail.com

 Jo wrote:

 I'm back on track with the scripting plugin. I created a Jython script
 that
 helps to find probable spelling errors in street names. It's quite
 specific
 in that it supports the bilingual status of Brussels.

 #!/bin/jython

 #
 # Spell checking.py  - Helps to locate probable spell errors
 #
 from javax.swing import JOptionPane
 from org.openstreetmap.josm import Main
 import org.openstreetmap.josm.command as Command
 import org.openstreetmap.josm.data.osm.Node as Node
 import org.openstreetmap.josm.data.osm.Way as Way
 import org.openstreetmap.josm.data.osm.TagCollection as TagCollection
 import org.openstreetmap.josm.data.osm.DataSet as DataSet

 corrections = {'fr': [('Dr. ', 'Docteur '),('R. ', 'Rue '), ('Av. ',
 'Avenue '), ('Bd. ', 'Boulevard '),
  ('Sq.', 'Square'), ('Pl.', 'Place'),
  (' De ', ' de '), (' Le ', ' le '), (' La ', ' la
 '),
 (' Du ', ' du '), (' Des ', ' des '), (' Les ', ' les '),
  (' Au ', ' au '),(' Aux ', ' aux '),('À', 'à'),('
 Den
 ',' den '), ( Sur ,  sur ),
  ( D', d'), ( L', l'), (' ,'),
  (Ecole ,École ), (Eglise, Église),
 (Chateau, Château), (Cable, Câble), (General, Général)],
   'nl': [( Voor ,  voor ), ( Op ,  op ), ( Pour ,
 
 pour ), ( Naar ,  naar ), ( Ter ,  ter ), ( En ,  en ), (
 Van
 ,  van ),
  ('T , 't ), ('S , 's ), (-Ter-, -ter-),
 ( Het ,  het ),
  ( Straat, straat), ( Weg, weg), ( Laan,
 laan), ( Steenweg, steenweg),
  ( Baan, baan), (Oudebaan, Oude Baan),
 (Grotebaan, Grote Baan),
  (de Lijn, De Lijn)]}

 commandsList = []
 streetnames = {}

 def getMapView():
if Main.main and Main.main.map:
return Main.main.map.mapView
else:
return None

 def myOwnCapitalize(word):
# JOptionPane.showMessageDialog(Main.parent, word.decode('utf-8'))
if word:
return word[0].upper() + word[1:]
else:
return u

 mv = getMapView()

 if mv and mv.editLayer and mv.editLayer.data:
selectedNodes = mv.editLayer.data.getSelectedNodes()
selectedWays = mv.editLayer.data.getWays()
selectedRelations = mv.editLayer.data.getSelectedRelations()

if not(selectedNodes or selectedWays or selectedRelations):
JOptionPane.showMessageDialog(Main.parent, Please select
 something)
else:
for way in selectedWays:
for isoLang in ['nl', 'fr', '']:
correctedName = result = u''
if isoLang:
nameColonIso = 'name:' + isoLang
else:
nameColonIso = 'name'
if way.hasKey(nameColonIso):
name=str(way.get(nameColonIso).encode('utf-8'))
if name in streetnames:
if streetnames[name] == 'ignore':
continue
else:
correctedName = streetnames[name]
else:
Main.main.getCurrentDataSet().setSelected(way)
# dummy = mv.editLayer.data.getSelected()
#
 mv.zoomTo(Main.main.getEditLayer().data.getSelected())
# JOptionPane.showMessageDialog(Main.parent,
 name.decode('utf-8'))
for subname in name.split(;):
for word in subname.split( ):
if word:
if - in word and len(word)1:
dashes = word.split(-)

correctedName +=
 myOwnCapitalize(dashes[0])
for dash in dashes[1:]:
# if dash[0] == ' ':
# correctedName += u- +
 myOwnCapitalize(dash[1:])
# else:
correctedName += u- +
 myOwnCapitalize(dash.strip())
elif ' in word and not(. in
 word):
apo=word.split(')
if apo[0]: correctedName +=
 myOwnCapitalize(apo[0])
correctedName += '

Re: [josm-dev] Scripting plugin

2011-04-11 Thread Jo
I'm back on track with the scripting plugin. I created a Jython script that
helps to find probable spelling errors in street names. It's quite specific
in that it supports the bilingual status of Brussels.

#!/bin/jython
 #
 # Spell checking.py  - Helps to locate probable spell errors
 #
 from javax.swing import JOptionPane
 from org.openstreetmap.josm import Main
 import org.openstreetmap.josm.command as Command
 import org.openstreetmap.josm.data.osm.Node as Node
 import org.openstreetmap.josm.data.osm.Way as Way
 import org.openstreetmap.josm.data.osm.TagCollection as TagCollection
 import org.openstreetmap.josm.data.osm.DataSet as DataSet

 corrections = {'fr': [('Dr. ', 'Docteur '),('R. ', 'Rue '), ('Av. ',
 'Avenue '), ('Bd. ', 'Boulevard '),
   ('Sq.', 'Square'), ('Pl.', 'Place'),
   (' De ', ' de '), (' Le ', ' le '), (' La ', ' la '),
 (' Du ', ' du '), (' Des ', ' des '), (' Les ', ' les '),
   (' Au ', ' au '),(' Aux ', ' aux '),('À', 'à'),(' Den
 ',' den '), ( Sur ,  sur ),
   ( D', d'), ( L', l'), (' ,'),
   (Ecole ,École ), (Eglise, Église),
 (Chateau, Château), (Cable, Câble), (General, Général)],
'nl': [( Voor ,  voor ), ( Op ,  op ), ( Pour , 
 pour ), ( Naar ,  naar ), ( Ter ,  ter ), ( En ,  en ), ( Van
 ,  van ),
   ('T , 't ), ('S , 's ), (-Ter-, -ter-),
 ( Het ,  het ),
   ( Straat, straat), ( Weg, weg), ( Laan,
 laan), ( Steenweg, steenweg),
   ( Baan, baan), (Oudebaan, Oude Baan),
 (Grotebaan, Grote Baan),
   (de Lijn, De Lijn)]}

 commandsList = []
 streetnames = {}

 def getMapView():
 if Main.main and Main.main.map:
 return Main.main.map.mapView
 else:
 return None

 def myOwnCapitalize(word):
 # JOptionPane.showMessageDialog(Main.parent, word.decode('utf-8'))
 if word:
 return word[0].upper() + word[1:]
 else:
 return u

 mv = getMapView()

 if mv and mv.editLayer and mv.editLayer.data:
 selectedNodes = mv.editLayer.data.getSelectedNodes()
 selectedWays = mv.editLayer.data.getWays()
 selectedRelations = mv.editLayer.data.getSelectedRelations()

 if not(selectedNodes or selectedWays or selectedRelations):
 JOptionPane.showMessageDialog(Main.parent, Please select
 something)
 else:
 for way in selectedWays:
 for isoLang in ['nl', 'fr', '']:
 correctedName = result = u''
 if isoLang:
 nameColonIso = 'name:' + isoLang
 else:
 nameColonIso = 'name'
 if way.hasKey(nameColonIso):
 name=str(way.get(nameColonIso).encode('utf-8'))
 if name in streetnames:
 if streetnames[name] == 'ignore':
 continue
 else:
 correctedName = streetnames[name]
 else:
 Main.main.getCurrentDataSet().setSelected(way)
 # dummy = mv.editLayer.data.getSelected()
 #
 mv.zoomTo(Main.main.getEditLayer().data.getSelected())
 # JOptionPane.showMessageDialog(Main.parent,
 name.decode('utf-8'))
 for subname in name.split(;):
 for word in subname.split( ):
 if word:
 if - in word and len(word)1:
 dashes = word.split(-)

 correctedName +=
 myOwnCapitalize(dashes[0])
 for dash in dashes[1:]:
 # if dash[0] == ' ':
 # correctedName += u- +
 myOwnCapitalize(dash[1:])
 # else:
 correctedName += u- +
 myOwnCapitalize(dash.strip())
 elif ' in word and not(. in word):
 apo=word.split(')
 if apo[0]: correctedName +=
 myOwnCapitalize(apo[0])
 correctedName += '
 if apo[1]: correctedName +=
 myOwnCapitalize(apo[1])
 elif . in word or len(word)1 and
 word[1]==word[1].upper() or len(word)2 and word[2]==word[2].upper():
 correctedName += word
 else:
 correctedName +=
 myOwnCapitalize(word)
 correctedName += ' '
 correctedName = correctedName.strip() + ';'
  

Re: [josm-dev] Scripting plugin

2011-03-20 Thread Jo
Thanks for the hit Martin, unfortunately I gave up on it. I managed to
convert the one line to get the selected nodes and other primitives. But now
I'm stuck at the creation of a Cmd-structure to pass to the UndoRedo
function/class.

Anyway, I found that the terracer plugin already has the functionality I was
looking for. Alt-Shift-P does the trick!

I also created a Youtube video explaining how to convert an address
interpolation vector to a terrace of buildings:

http://www.youtube.com/watch?v=4XzEc2YG75I

This combines the addressinterpolation plugin with the terracer plugin.

Really sweet!

Jo

2011/3/19 M∡rtin Koppenhoefer dieterdre...@gmail.com

 2011/3/19 Jo winfi...@gmail.com:
  - User selects two primitives: a node with housenumber information and a
  closedway representing a building.
  - Jython script copies all the properties from the node and merges the
 node
  with one of the nodes of the building
  - Then all the properties from the node are copied to the building
 closedway


 Don't forget to remove in a following step the tags from the node
 which you have copied to the closed way.

 cheers,
 Martin

___
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev


Re: [josm-dev] Scripting plugin

2011-03-19 Thread M∡rtin Koppenhoefer
2011/3/19 Jo winfi...@gmail.com:
 - User selects two primitives: a node with housenumber information and a
 closedway representing a building.
 - Jython script copies all the properties from the node and merges the node
 with one of the nodes of the building
 - Then all the properties from the node are copied to the building closedway


Don't forget to remove in a following step the tags from the node
which you have copied to the closed way.

cheers,
Martin

___
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev


[josm-dev] Scripting plugin

2011-03-18 Thread Jo
Hi guys,

Maybe this is not the right list for my question. If so, I'm sorry.
I'm more of a Python programmer than a Java programmer, this is why the
scripting plugin peeked my interest.

The one example showing how to show the number of layers is not enough to
get me started with what I want to accomplish though.

Is there somebody who can assist me with the following task?

- User selects two primitives: a node with housenumber information and a
closedway representing a building.
- Jython script copies all the properties from the node and merges the node
with one of the nodes of the building
- Then all the properties from the node are copied to the building closedway

So what I need to know is: how to determine what the user selected.

the properties of the node; probably as a Python dictionary
how to assign these properties to the building closedway

how to merge the selected node with the northmost node of the selected
closedway

Tia,

Jo
___
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev