You are not logged in.

#1 2021-09-09 22:50:10

smootheFiets
Member
Registered: 2019-12-09
Posts: 448

JOSM tagging preset: rename key?

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

Old situation:

key1=value

New situation:

key2=value

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.

Offline

#2 2021-09-10 08:16:18

SimonPoole
Member
Registered: 2010-03-14
Posts: 2,075

Re: JOSM tagging preset: rename key?

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/JOS … s/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/beautifie … xml#L12428 changes the main key of an object to disused:key.

Offline

#3 2021-09-11 08:03:24

smootheFiets
Member
Registered: 2019-12-09
Posts: 448

Re: JOSM tagging preset: rename 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...

Offline

#4 2021-09-11 09:00:55

SimonPoole
Member
Registered: 2010-03-14
Posts: 2,075

Re: JOSM tagging preset: rename key?

smootheFiets wrote:

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

Last edited by SimonPoole (2021-09-11 09:01:16)

Offline

#5 2021-09-11 14:47:37

smootheFiets
Member
Registered: 2019-12-09
Posts: 448

Re: JOSM tagging preset: rename key?

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"?

Offline

#6 2021-09-12 11:56:03

SimonPoole
Member
Registered: 2010-03-14
Posts: 2,075

Re: JOSM tagging preset: rename key?

smootheFiets wrote:

...
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 <key /> 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.

Last edited by SimonPoole (2021-09-12 12:14:35)

Offline

#7 2021-09-12 15:24:12

skyper
Member
Registered: 2020-06-08
Posts: 322

Re: JOSM tagging preset: rename key?

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).

Offline

#8 2021-09-12 16:08:53

skyper
Member
Registered: 2020-06-08
Posts: 322

Re: JOSM tagging preset: rename key?

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).

Last edited by skyper (2021-09-12 16:09:16)

Offline

#9 2021-09-12 19:40:59

SimonPoole
Member
Registered: 2010-03-14
Posts: 2,075

Re: JOSM tagging preset: rename key?

skyper wrote:

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.

Last edited by SimonPoole (2021-09-12 19:41:21)

Offline

#10 2021-09-12 21:22:36

smootheFiets
Member
Registered: 2019-12-09
Posts: 448

Re: JOSM tagging preset: rename key?

SimonPoole wrote:
smootheFiets wrote:

...
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 <key /> 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.

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.


SimonPoole wrote:
skyper wrote:

I think that validator is the better alternative.

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.

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 )

Offline

Board footer

Powered by FluxBB