JOSM/Search function

From OpenStreetMap Wiki
Jump to navigation Jump to search

broom

This article or section may contain out-of-date information: The search functionality listed on this page is incomplete and needs to be updated to reflect the current implementation. The documentation on this page is still accurate, but is missing some newer functionality. See here for a more up-to-date list.
If you know about the current state of affairs, please help keep everyone informed by updating this information. (Discussion)

JOSM search is a fairly advanced system which first takes your string, compiles it into a tree structure and runs that over the data. At the base level there are matching tokens, which can then be combined to form complex searches. To access the search dialog, press Ctrl+F, or click the Edit menu, then Search.

There is provision for case-sensitive matches, directly activated from the search dialog.

The Filter window is closely related to the search function.

Tokens

This is a list of the base tokens in, as far as I can see, from the source:

Token Meaning
selected Matches only objects which are currently selected
modified Matches only objects which have been modified. This is essentially anything that would be uploaded if you hit the upload button, thus it includes newly created objects.
incomplete Matches any objects which are incomplete (e.g., referenced by a relation but not returned by the server)
untagged Matches any objects which are not tagged (with exception of Discardable tags like created_by=*, etc ...)
child Matches the objects which are children of other objects, e.g., the nodes of a way.
type:node type:way type:relation Matches a specific type of object
user:name Matches objects that were last edited by user name (exact match). Note that this reflects the information JOSM gets from the server, even if you modified the object locally in JOSM. If the username contains spaces your search must include them. For example: user:"OSMF Redaction Account"
nodes:number
nodes:number1-number2
Matches ways that contain exactly number nodes or nodes in a range (inclusive)
id:value Matches the object with the server id value. (Objects that have not been uploaded to the server yet have the id 0.)
key:value Matches objects with the key key and the value value. The key is an exact match, but the value is a substring match. Both the key and the value may be double quoted strings (you have to use them if the key contains a colon).
key: Matches objects with the key key no matter the value.
value Matches the given value as a substring match on either the key or the value or the username. If value has a colon in it, you must use double-quotes to protect it.

Modifiers

There is currently one modifer, the minus sign (-) which is used to invert selections. Note that the actual effect in JOSM may not be what you'd expect, since it selects everything, including nodes. See the examples below.

Example Description
-selection Anything that is not selected
-id:value Everything except objects with the given ID
-key:value Everything except objects with the given key (exact match) and the given value (substring match). Note that it will select any objects that don't have the key at all.
key:-value Everything with the given key (exact match) which doesn't match the given value (substring).

There seem to be some more modifiers:

First character is the mode:

Character Description
R Replace
A Add
D Remove
S In selection

Flags: The second character until a " " are flags:

Character Description
C Case sensitive
R Regexp
A All elements

Combiners

There are two ways to combine tokens, via AND or OR. There is no explicit AND symbol, so simply listing multiple search terms means that all of them must match. OR has a higher precedence than AND, so that "a b OR c" and "b OR c a" mean the same thing.

Combiner Description
token token Matches if both tokens match
token OR token Matches if either token matches

Examples

broom

This page is being considered for cleanup. Please discuss this page.
JOSM search is now well described in JOSM itself, reduce duplication. See also [1]

In case the above is gobbledygook to you, here are some working examples, including some tricks:

highway unclassified Returns any objects that have both the words 'highway' and 'unclassified' as a substring in either the key or the value fields
highway:unclass Returns any object where the key 'highway' has a value with the substring 'unclass'.
-highway:unclassified This appears to match everything. You may be wondering why since most roads aren't unclassified. The reason is that this matches everything that does not contain the 'unclassified' substring in the 'highway' tag (e.g., everything that doesn't have a 'highway' tag).
-highway:unclassified type:way This is better, now all the highways are unselected, but the waterway still is. For that you need:
-highway:unclassified type:way highway: Now you get just those ways which have a 'highway' tag.
-selected Select everything except current selection, -- i.e., "invert selection"
untagged type:way Use this query instead of manually clicking each of 10s, 100s of new road segments
untagged type:way inview You can additionally restrict your view to avoid oversights
highway=* -name=* -highway=no unnamed highways, paths and cycleways
selected -type:node Removes all nodes from the current selection.
selected OR type:node Adds all nodes to the current selection
selected OR type:node place:London Here the counter-intuitive choice of precedence rears its ugly head. You'd be tempted to interpret it as selected OR (type:node place:London) whereas it is actually interpreted as (selected OR type:node) place:London. What you need to do is...
selected OR (type:node place:London) This does what you expect, though you can achieve the same result by selecting "add to selection" in the search dialog box.
foo bar OR baz zap Beware: Juxtaposition (AND) has a lower precedence than OR. This will be interpreted as foo (bar OR baz) zap.
(foo bar) OR (baz zap) You can use parens to override default precedence. This will select the objects that match foo and bar, and objects that match baz and zap.
"name:secret":"Foo \"the Baz\" Bar" If either the search key or value contain any special characters (like (, ), :, space) it needs to be enclosed in double quotes. The double quote character itself (") can be included in a quoted string by escaping it with a backslash (\). If a literal backslash needs to be included in the string it in turn needs to be escaped by another backslash. See an use case.
type:node untagged -child Add nodes (type:node), without tags (untagged), not used (-child) in ways or relations (useful for cleaning up old GPS traces)
area=yes tags:1 Selects only objects which are tagged with "area=yes", nothing else

Time-dependent

timestamp:2014-06-01/ Will find any object that was modified after date
timestamp:2014-06-01/2014-07-01 Will find any object that was modified after date but before other date

Good luck searching!

See also