I wish to edit the name key of a group of nodes to fix typos and normalize data. For instance, I want to change the first character of names places starting with "El " to "el ".
Currently I have a good filter rule in JOSM, so I can edit each node by hand easilly. But I would be easier selecting all desired nodes and replacing "El " to "el " with a single click. There are many typos in many nodes.
You’ll have to remove a lot for your purpose, but it’s all there; iterating over objects in the selection, regular expressions. I hope it can inspire you.
I used in the past scripting and a javascript or jython script to do that.
Unfortunately I can’t install scripting since at least one year (JOSM under macOS).
Is there a plan to add this basic functionality natively in JOSM ?
If not, is it possible to use MapCSS to do this ?
i.e. by creating a specific validation rule ?
My use case is to replace the wrong separator in start_date start_date=2025/02/11 > start_date=2025-02-11
In my opinion there are several reason why this feature is an addon. Why do you need it in core?
Sure MapCSS can do this with a simple regex and an auto-fix to replace your separator is possible Untested:
*[start_date][start_date =~ /^\d{4}(\/\d\d){2}$/] {
throwWarning: tr("{0} with backslash as separator", "{0.key}");
fixAdd: concat("{0.key}", "=", replace(tag("{0.key}"), "/", "-"));
set start_date_syntax
}
*[start_date][start_date !~ /^\d{4}(-\d\d){2}$/]!.start_date_syntax {
throwWarning: tr("{0} with incomplete or wrong value", "{0.key}");
}
If the values of start_date are an bigger issue a ticket to get it into core might be useful but if above is working and useful, I can add it as external rule.
Like a “basic” text editor for.coders, simply search en replace several patterns.
Currently we must save JOSM data in .osm, search and replace with the text editor, reload the file in JOSM.
The problem is that is an object is modified, we must add action='modify', so this isn’t easy and error prone.
Yes I read the doc in the meantime.
I will test your code, thank you
I will check with taginfo if there is a lot of similar issue with start_date, end_date, check_date, abandoned:date, survey:date…
We could expand CheckDate to check other *date tags and fix them if necessary.
Yes, but as it would be used only by a small group of users, it’s a reason to keep it out of core. By the way, do you know the Comfort0 plugin?
Create a new data layer and switch back to your data
Select the objects in question using JOSM search (maybe with MapCSS syntax and regex
Merge selected objects to previously created new layer
Switch to new layer and add FIXME=search_and_replace to all objects (to get the modified state)
Save layer to file
Search & replace in text editor
Load file
Remove FIXME=search_and_replace if not already done in text editor
Upload or merge layer to original data layer
With comfort0 this list shortens dramatically and it is basically only the JOSM search or filters to get the correct objects selected and exported to your text editor.
Nice find. The regex looks better than my simple approach.
meta {
title: "Check Dates";
version: "0.1";
author: "Pyrog";
link: "";
baselanguage: "en";
}
*[start_date][start_date !~/^\d{4}(-[01]\d(-\d\d([T ]\d\d:\d\d:\d\dZ?)?)?)?$/ ],
*[end_date][end_date !~/^\d{4}(-[01]\d(-\d\d([T ]\d\d:\d\d:\d\dZ?)?)?)?$/ ],
*[check_date][check_date !~/^\d{4}(-[01]\d(-\d\d([T ]\d\d:\d\d:\d\dZ?)?)?)?$/ ],
*["survey:date"]["survey:date" !~/^\d{4}(-[01]\d(-\d\d([T ]\d\d:\d\d:\d\dZ?)?)?)?$/ ]
{
throwWarning: "{0.key} should be a valid ISO 8601 date (YYYY-MM-DD)";
set invalid_ISO_8601_date
}
*[start_date =~ /\//],
*[end_date =~ /\//],
*[check_date =~ /\//],
*["survey:date" =~ /\//]
{
throwWarning: tr("{0} with backslash as separator", "{0.key}");
fixAdd: concat("{0.key}", "=", replace(tag("{0.key}"), "/", "-"));
set start_date_syntax
}
Some common errors in date are i.e. France 31/12/20252025-12-31
… but I didn’t provide a fix.
Must be used carefully with i.e. 01-02-2025. Is it first february or january, 2nd ?
Source, survey, check start and end dates in this order with the following separators .-/\ Overpass query return around 100 000 objects !