== Disclaimer

This code is being provided without guarantee or warranty. Use at your own risk!

Please make a backup before starting. Please check your files in JOSM before uploading.

I have run this successfully using: Mac OSX 10.9.5, Eclipse Mars.2 Release (4.5.2), and TextWrangler for the name file, which contained Spanish, German, Japanese, Korean and Cyrillic characters.

The program did NOT work on the first try with Korean or Spanish characters under "Windows 7 - Korean Edition" (thank you Luciano for testing.) The character encoding caused issues with the OSM file. A possible fix is included in the instructions for Eclipse, below.

If something odd occurs, please let me know, and I'll see if I can correct the program, or find a way to work around it.

If you have experience with Eclipse or Java (mine is limited) and know a specific fix for any issues, please let me know.

I would also appreciated any suggestion for improvements or additional features that may be helpful.

-- Paxtar

 

== Basic Process

The OSM file is read line by line by a program written in Java.

If a <way> is found the entire way is read (until the close </way>), without adding it to an output text string. If the way is tagged for an update with a changekey, a new name replaces the changekey text. The entire way is then added to the output text string, regardless of whether a change was made.

If no <way> is found on the line, the line is simply added to the output string.

When the entire OSM file has been read and copied to the output text string, the output text string is saved to a new OSM file.

 

== Preparation, JOSM

In JOSM, upload any pending changes, and save the file. *Making a backup, is recommended.*

In JOSM use filters to help select which ways will be named.

Filter Example:

Add to Selection: highway=* & -name=* & -highway=turning_circle & -area=yes

(Select all highways, remove anything named, remove turning circles, remove areas)

Select the ways you want to name and add a tag with a changekey.

name=WayNameNeeded

A different changekey (WayNameNeeded) can be used, but it must be completely unique, and will also need to be updated in the Java code.

DO *NOT* upload the changes. Along with the new 'name' tag, the OSM file now contains tags indicating which items need to be uploaded.

Save and close the JOSM file.

 

== Preparation, Names

The name list file should be in plain text file.    'newnames.txt'    TextWranger works well on Mac for stripping out formatting, or Notepad on Windows.

The street type (street, avenue, lane, etc.) can be included with the name, or the renaming code can determine what the suffix should be based on highway type, or by length of the way.

Each name must be on its own line.

To avoid duplicate names, your list should have one name for each way you want to name. If there are not enough names, the list will repeat from the beginning.

Names are assigned in the order in which they appear on the list, to the ways in the order in which the ways appear in the OSM file. Randomize the list if a completely random placement is needed. Streets/ways that were created at the same time are likely to be next to each other in the OSM file.

A small sample file can be viewed here.

 

== Preparation, Eclipse*

First download the Java naming program 'namer.jar' here. The file is in a .zip archive, and will need to be unzipped.

Eclipse was used to write the program. Eclipse can be downloaded here.

Eclipse requires the Java Development Kit, which if you don't have the latest version, can be downloaded here.

Once you have Eclipse installed...

In Eclipse, File > New > Java Project

Call it 'namer', and then finish.

File > Import > General > Archive File
Next

Browse to downloaded file 'namer.jar'
Open

Check Overwrite existing resources without warning
Finish

In Package Explorer (left side of screen), click arrow to open package, then drag nameWays.java in to src folder.

Click arrow to open src

Click arrow to open (default package)

Double click nameWays.java

The code should open in a window.

Click the green circle with the white right-arrow in the menu bar.

Run as Java Application.

If everything is set up correctly, the program should then run with a bunch of red errors, since the file locations have not yet been set up.

Under Windows, the text files (txt and XML/OSM) may have the wrong text encoding. Non-roman characters (Japanese, Korean, etc.,) as well as characters with accents, umlauts, etc. may show up as boxes, or strange notations. [See examples here.]

The fix seems to be:

Windows / Preferences / General / Content Types / change Text and XML file types on the right to default encoding UTF-8, and then update.

Try that one first, and if it doesn't solve the problem with encoding, try these:

Right click Project (Namer/whatever it was called), select Properties / Resource Text File Encoding select UTF-8

Windows / Preferences / General / Workspace, set "Text file encoding" to "Other : UTF-8".

Menu at the top / Run / Run Configurations / Common tab / Encoding setting for UTF-8.

* You should be able to access the .jar file in another IDE, such as NetBeans, but I've only used Eclipse.

== Update the User Settings

There is additional information in the comments in the Java code.

In the Java code window, scroll down to:

// ---------------------- Start User Settings ---------------------- //

Update the changeKey, if desired.

Update the three file name locations, as needed. Source file, destination file, and name list.

Update the streetTypes, as needed. You can ignore this if complete names will be read from your list.

Update the lengthLimit setting, if needed. These need to be from largest to smallest. Distance settings are in km. You can ignore this if complete names will be read from your list.

Update the highway type settings, if needed. The number for each type should match the number in the street type two sections above. You can ignore this if complete names will be read from your list.

Update the circular way setting, if needed, to the type correct street type. Circular way naming can be turned off below in the Naming Settings. You can ignore this if complete names will be read from your list.

Update the turning circle setting, if needed, to the type correct street type. The distance indicates the maximum length of the way connected to the turning circle in order to qualify for the turning circle specific change. Set the turningCircleLength to 0 to disable. You can ignore this if complete names will be read from your list.

Update naming settings as needed. 'true' or 'false'

dupeNames will check for any names already in the source file, and avoid using the same name again. If the new name file is too short for the number of names that are needed, it will stop checking with the specified limit of duplicates is reached. Processing will stop and the output file will not be written.

If useModifiers = false, then complete names will be read from your list, and subsequent settings will be ignored.

 

==Running the program

In Eclipse, click the green circle with the white right-arrow in the menu bar to run the program.

The program will output status updates in the console window as it process the OSM file.

First will be a list of 'Currently at' updates indicating which line is being processed. Ways appear about halfway through the file, so only line numbers will appear at first.

Currently at line: 1000
Currently at line: 2000
Currently at line: 3000
...

If useModifiers = true, once the ways are reached, you'll see updates for each way that is renamed:

Line: 51696 Way needing new name found.
Total Nodes: 3
Way Length: 0.29907260205273967 KM
Avg. Angle: 59.69061894709314
Way Type: residential
New Name: Greentree Lane
Circular Way: false
Turning Circle: true
...

When the program is complete, a message should be displayed:

File written successfully

Total Time: 1 hours, 10 minutes, 44 seconds. (Or however long it actually took.)

== Process Complete

The updated OSM file should now be saved at the location designated in the settings.

Open the file in JOSM to check the results. If everything looks good, the file can be uploaded.

Good luck!