Smart OSM


The latest version of Smart OSM has an advanced query language. You can search for anything you need with it. This page aims to provide some simple examples so you can make use of this feature.


The basic idea

  •  Openstreetmap data is stored in the form of tags. A tag has a key and a value.  e.g.  highway = true   (key = value) or building = yes, etc. 
  • Each way is defined by a combination of these tags. These tags are what you search for with a query. 
  • You can include multiple searches. Think of it like a filter set. e.g. if you want to find all buildings that have a height value use [building][height] this first gets all buildings, and then kicks out any results without a height value. You could also just write [height] as it is unlikely that any other way would have a height tag, if it where not a building. There are many ways to to do the same thing.



You can copy paste these query's into the smart OSM query box. (select the bold text then copy past into the  Smart OSM query box)


[building]["addr:housenumber"]     //get all buildings that have an addr tag


[admin_level]                    //gets you any kind of lines with an admin borders  (they are not connected, so you might want to use the poly object for this purpose)


[tourism=hotel]                // gets you any outlines with amenity = hotel. these are usuallybuildings.

[amenity=pub] 


[name ~ "s$"]                    // get any  way that has a name tag that starts with "s"  (not case sensitive)

[name ~ "s$i"]                   // get any  way that has a name tag that starts with "s"  case sensitive


[amenity ~ "pub|cafe|bar|restaurant|fast_food"] 

 

[highway~"footway"]                                   //gets you any way that has the key "highway" value"footway"

[highway!~"footway"]                                  //gets you any way that has the key "highway" excluding those  with key value "footway" (a lot of stuff)

[highway!~"footway|walkway|pathway"]   //all highways but we don't want footway, walkway or pathway, etc.


[highway~"motorway"]                                //gets you any way that has the key "highway" with value "motorway"

[highway] [name = "6th Avenue"]               // makes sense



e.g.  for London , this would get you the m25 and all connecting motorways within your area of interest. 


*Be careful not to search for too large of an area. The server might refuse, or time out on your search.


maybe you want primary roads? 

no problem

[highway~"primary"]    //gets you any way that has the key "highway" and value = "primary "


maybe you want to combine a search?


[highway~"trunk|secondary"]                  //gets you ways  with key "highway" that have a value of  trunk or secondary. 

[highway~"^(primary|secondary|tertiary|residential)$"]


the ref tag can be uses to find anything such as the A1,B3,A212,B25,etc,etc


[highway][ref]                //gets you anything with a ref tag

[highway][ref~"A3"]      // gets you any highway with the ref  A3


that was 2 filters.

1.[highway]     // get all highways

2.[ref~"A3"]    // took the first result threw out anything that did not have a ref key, named A3


[highway][ref ~ "^A.*"]              // gets you all A roads


[highway][maxspeed]  

[highway]["maxspeed"~"."] 

[highway][maxspeed ~"30"]  



it can get complicated, but its very powerful, and there is no limit to what you can extract once you figure it out. (replace "Foo" with what your looking for)


  [~"^addr:.*$"~"^Foo$"]          /* finds addr:* tags with value exactly "Foo" */

  [~"^addr:.*$"~"^Foo"]               /* finds addr:* tags with value starting with "Foo" */

  [~"^addr:.*$"~"Foo$"]                /* finds addr:* tags with value ending with "Foo" */

  [~"^addr:.*$"~"Foo"]                  /* finds addr:* tags with value containing the substring "Foo" */

  [~"^addr:.*$"~"."]                       /* finds addr:* tags with any value */

  [~"^name(:.*)?$"~"."]                 /* finds anything with a name or name:lang tag, and with any value */

  [~"^name(:ar|:he)?$"~"."]           /* finds anything with name, name:ar, or name:he tag, and with any value*/


etc,etc.


typical highway tags are :


check out the most commonly used way tags : https://taginfo.openstreetmap.org/tags 


NOTE: There is no guarantee that ways with a specific tag either exist in an area, or are tagged correctly. you can check what kind of tags are in an area by making an openstreetmap.org account and having a look at whatever is available in your area of interest, to see what tags are available.


TIP:  you easily use a DEM Earth poly object to find an admin border, to contain your smart OSM search results.