JOSM tagging preset: rename key?

Is it possible, in a JOSM tagging preset, to rename a key?

Old situation:

New situation:

Obviously, I know key1 and key2, but I don’t know value.

I’ve looked at the documentation, and I’ve written the odd preset or two. I couldn’t figure out how to do this, though. Can it be done at all?

This is to modify objects (buildings) that have previously been imported from an official database. When they’re deleted from the database, this mostly means they’ve been demolished; in that case we delete the building from OSM. If they’re not demolished, however, we keep it on OSM and rename the key

ref:bag

into

ref:bag:old

. This isn’t terribly hard to do manually, but I’d love to save a mouse click or two by using an easy preset. If that’s possible.

This isn’t directly possible with JOSM, you can reference a Java method in the preset, but as you can’t pass it arguments (and would need to write a plugin to add it to JOSM itself) that doesn’t really help. So probably writing a simple plugin to do it is the only way, or maybe https://wiki.openstreetmap.org/wiki/JOSM/Plugins/ExtTools .

You -can- do that with Vespucci BTW as we support inline JavaScript in the presets (as an extension to the JOSM format). For example https://github.com/simonpoole/beautified-JOSM-preset/blob/master/master_preset.xml#L12428 changes the main key of an object to disused:key.

Thanks a lot, SimonPoole! Not the answer I wanted to hear, obviously. But if that’s what it is, that’s what it is.
Pretty cool that Vespucci can do this. I wonder how easy or hard it would be to add that capability to JOSM…

Actually on 2nd thought you might be able to do this with value_template see https://josm.openstreetmap.de/wiki/TaggingPresets which is a very new and rather controversial addition (it isn’t quite clear if it still works or not, but it is worth a try).

Simon

Excellent keyword! I got my tag-renamer template to work, in a clunky way, using value_template like so:


<item name="step1" type="closedway">
 <text key="newTag" text="Leave me alone, please" value_template="{oldTag}" />
</item>
<item name="step2" type="closedway">
 <key key="oldTag" />
</item>

It would be much nicer if I could do the following:


<item name="rename" type="closedway">
 <key key="newTag" value_template="{oldTag}" />
 <key key="oldTag" />
</item>

That doesn’t work, as of JOSM 18193, for two reasons

  • value_templates appear to be forbidden in ‘key’ statements; only value appears to be supported
  • If I insert the value_template into a ‘text’ statement like in the clunky working example above, it first populates “newTag” with the value of oldTag as needed. But then it deletes “oldTag” in the second statement and dynamically updates the value_template above, i.e., it deletes the value… That’s why I currently need two steps.

Am I doing something stupid, or do I need to raise a feature request “allow value_template in key”?

I don’t think using a field would do anything different, the problem is likely simply the point in time the template is evaluated, but there might be a way around this (as with all such things banking on a specific undocumented implementation detail is not good practice :-)).

So just tested my hunch:

<item name="rename" type="closedway">     
     <text key="newTag" value_template="{oldTag}" />
     <text key="oldTag" value_template="" />
</item>

as expected this seems to work.

Ich halte Validator für geeigneter. Beispiele gibt es genug in deprecated.mapcss, z.B. Zeile 468ff.

Größte Vorteile sind Suche durch Validator und Autofix (auch für alle Objekte auf einmal).

Oh, sorry, mixed up language:

I think that validator is the better alternative. There are many examples in deprecated.mapcss line 468 and following.

Biggest advantages are the search by validator and the autofix (even for all objects at once).

It’s about replacing a key on soecific individual objects, as far as I can see there is no way for the validator to know which objects these are.

Excellent, that does work. Thanks a lot!
Funnily enough, the simpler

<item name="rename" type="closedway">     
     <text key="newTag" value_template="{oldTag}" />
     <text key="oldTag"  />
</item>

or, equivalently,

<item name="rename" type="closedway">     
     <text key="newTag" value_template="{oldTag}" />
     <text key="oldTag" value="" />
</item>

do not work. They appear to blank oldTag before executing the value_template; I guess you’re right about time of execution. Your solution with the two value_templates works.

True. This is for re-tagging objects after visual inspection by a human. Not something the validator can do. (but note my other question, which is about the validator: https://forum.openstreetmap.org/viewtopic.php?id=73802 )