X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/879f818d810d9418183f62fe2f991347aae78569..fd85483ce3b68fa65c7fae82ef65b035fb4c94fb:/docs/api/Search.md diff --git a/docs/api/Search.md b/docs/api/Search.md index e2c55fa5..b54c5302 100644 --- a/docs/api/Search.md +++ b/docs/api/Search.md @@ -1,231 +1,309 @@ +# Search queries -## Search -Nominatim indexes named (or numbered) features with the OSM data set and a subset of other unnamed features (pubs, hotels, churches, etc) +The search API allows you to look up a location from a textual description +or address. Nominatim supports structured and free-form search queries. -Search terms are processed first left to right and then right to left if that fails. +The search query may also contain +[special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases) +which are translated into specific OpenStreetMap (OSM) tags (e.g. Pub => `amenity=pub`). +This can be used to narrow down the kind of objects to be returned. -Both searches will work: [pilkington avenue, birmingham](//nominatim.openstreetmap.org/search?q=pilkington+avenue,birmingham), [birmingham, pilkington avenue](//nominatim.openstreetmap.org/search?q=birmingham,+pilkington+avenue) +!!! warning + Special phrases are not suitable to query all objects of a certain type in an + area. Nominatim will always just return a collection of the best matches. To + download OSM data by object type, use the [Overpass API](https://overpass-api.de/). -(Commas are optional, but improve performance by reducing the complexity of the search.) +## Parameters -Where house numbers have been defined for an area they should be used: [135 pilkington avenue, birmingham](//nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham) - -### Special Keywords -Various keywords are translated into searches for specific osm tags (e.g. Pub => amenity=pub). A current list of [special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases) processed is available. - -### Parameters +The search API has the following format: ``` https://nominatim.openstreetmap.org/search? - https://nominatim.openstreetmap.org/search/? ``` -* `format=[html|xml|json|jsonv2|geojson|geocodejson]` +The search term may be specified with two different sets of parameters: + +* `q=` + + Free-form query string to search for. + Free-form queries are processed first left-to-right and then right-to-left if that fails. So you may search for + [pilkington avenue, birmingham](https://nominatim.openstreetmap.org/search?q=pilkington+avenue,birmingham) as well as for + [birmingham, pilkington avenue](https://nominatim.openstreetmap.org/search?q=birmingham,+pilkington+avenue). + Commas are optional, but improve performance by reducing the complexity of the search. + +* `amenity=` +* `street= ` +* `city=` +* `county=` +* `state=` +* `country=` +* `postalcode=` + + Alternative query string format split into several parameters for structured requests. + Structured requests are faster but are less robust against alternative + OSM tagging schemas. **Do not combine with** `q=` **parameter**. + +Both query forms accept the additional parameters listed below. - * Output format - * defaults to `html` +### Output format +* `format=[xml|json|jsonv2|geojson|geocodejson]` + +See [Place Output Formats](Output.md) for details on each format. (Default: jsonv2) + +!!! note + The Nominatim service at + [https://nominatim.openstreetmap.org](https://nominatim.openstreetmap.org) + has a different default behaviour for historical reasons. When the + `format` parameter is omitted, the request will be forwarded to the Web UI. * `json_callback=` - * Wrap json output in a callback function (JSONP) i.e. `()` +Wrap JSON output in a callback function ([JSONP](https://en.wikipedia.org/wiki/JSONP)) i.e. `()`. +Only has an effect for JSON output formats. -* `accept-language=` +### Output details - * Preferred language order for showing search results, overrides the value specified in the "Accept-Language" HTTP header. - * Either uses standard rfc2616 accept-language string or a simple comma separated list of language codes. +* `addressdetails=[0|1]` -* `q=` +Include a breakdown of the address into elements. (Default: 0) - * Query string to search for. - * Alternatively can be entered as: - * `street= ` - * `city=` - * `county=` - * `state=` - * `country=` - * `postalcode=` - - **(experimental)** Alternative query string format for structured requests. -Structured requests are faster and require fewer server resources. **Do not combine with `q=` parameter**. +* `extratags=[0|1]` -* `countrycodes=[,][,]...` +Include additional information in the result if available, +e.g. wikipedia link, opening hours. (Default: 0) - * Limit search results to a specific country (or a list of countries). - * `` should be the ISO 3166-1alpha2 code, e.g. `gb` for the United Kingdom, `de` for Germany, etc. -* `viewbox=,,,` - * The preferred area to find search results. Any two corner points of the box are accepted in any order as long as they span a real box. +* `namedetails=[0|1]` -* `bounded=[0|1]` - * defaults to 0 - * Restrict the results to only items contained with the viewbox (see above). - * Restricting the results to the bounding box also enables searching by amenity only. - * For example a search query of just `"[pub]"` would normally be rejected but with `bounded=1` will result in a list of items matching within the bounding box. +Include a list of alternative names in the results. These may include +language variants, references, operator and brand. (Default: 0) -* `polygon=[0|1]` - * defaults to 0 - * Output polygon outlines for items found **(deprecated, use one of the polygon_* parameters instead)** -* `addressdetails=[0|1]` - * defaults to 0 - * Include a breakdown of the address into elements +### Language of results -* `email=` +* `accept-language=` + +Preferred language order for showing search results, overrides the value +specified in the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language). +Either use a standard RFC2616 accept-language string or a simple +comma-separated list of language codes. + +### Result limitation + +* `countrycodes=[,][,]...` + +Limit search results to one or more countries. `` must be the +[ISO 3166-1alpha2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code, +e.g. `gb` for the United Kingdom, `de` for Germany. - * If you are making large numbers of request please include a valid email address or alternatively include your email address as part of the User-Agent string. - * This information will be kept confidential and only used to contact you in the event of a problem, see [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details. +Each place in Nominatim is assigned to one country code based +on OSM country boundaries. In rare cases a place may not be in any country +at all, for example, in international waters. * `exclude_place_ids=` - * defaults to 10 - * Limit the number of returned results. -* `dedupe=[0|1]` - * defaults to 1 - * Sometimes you have several objects in OSM identifying the same place or object in reality. The simplest case is a street being split in many different OSM ways due to different characteristics. - * Nominatim will attempt to detect such duplicates and only return one match; this is controlled by the dedupe parameter which defaults to 1. Since the limit is, for reasons of efficiency, enforced before and not after de-duplicating, it is possible that de-duplicating leaves you with less results than requested. +Limit the number of returned results. (Default: 10, Maximum: 50) -* `debug=[0|1]` - * defaults to 0 - * Output assorted developer debug information. Data on internals of nominatim "Search Loop" logic, and SQL queries. The output is (rough) HTML format. This overrides the specified machine readable format. -* `polygon_geojson=1` - * Output geometry of results in geojson format. +* `viewbox=,,,` -* `polygon_kml=1` - * Output geometry of results in kml format. +The preferred area to find search results. Any two corner points of the box +are accepted as long as they span a real box. `x` is longitude, +`y` is latitude. -* `polygon_svg=1` - * Output geometry of results in svg format. +* `bounded=[0|1]` + +When a viewbox is given, restrict the result to items contained within that +viewbox (see above). When `viewbox` and `bounded=1` are given, an amenity +only search is allowed. Give the special keyword for the amenity in square +brackets, e.g. `[pub]` and a selection of objects of this type is returned. +There is no guarantee that the result is complete. (Default: 0) + + +### Polygon output + +* `polygon_geojson=1` +* `polygon_kml=1` +* `polygon_svg=1` * `polygon_text=1` - * Output geometry of results as a WKT. + +Output geometry of results as a GeoJSON, KML, SVG or WKT. Only one of these +options can be used at a time. (Default: 0) * `polygon_threshold=0.0` - * defaults to 0.0 - * Simplify the output geometry before returning. The parameter is the - tolerance in degrees with which the geometry may differ from the original - geometry. Topology is preserved in the result. -* `extratags=1` - * Include additional information in the result if available, e.g. wikipedia link, opening hours. +Return a simplified version of the output geometry. The parameter is the +tolerance in degrees with which the geometry may differ from the original +geometry. Topology is preserved in the result. (Default: 0.0) + +### Other + +* `email=` + +If you are making large numbers of request please include an appropriate email +address to identify your requests. See Nominatim's [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details. + +* `dedupe=[0|1]` + +Sometimes you have several objects in OSM identifying the same place or +object in reality. The simplest case is a street being split into many +different OSM ways due to different characteristics. Nominatim will +attempt to detect such duplicates and only return one match unless +this parameter is set to 0. (Default: 1) + +* `debug=[0|1]` + +Output assorted developer debug information. Data on internals of Nominatim's +"Search Loop" logic, and SQL queries. The output is (rough) HTML format. +This overrides the specified machine readable format. (Default: 0) -* `namedetails=1` - * Include a list of alternative names in the results. - * These may include language variants, references, operator and brand. -### Examples +## Examples -##### XML with polygon points -* [https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon=1&addressdetails=1](https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon=1&addressdetails=1) -* [https://nominatim.openstreetmap.org/search/gb/birmingham/pilkington%20avenue/135?format=xml&polygon=1&addressdetails=1](https://nominatim.openstreetmap.org/search/gb/birmingham/pilkington%20avenue/135?format=xml&polygon=1&addressdetails=1) -* [https://nominatim.openstreetmap.org/search/135%20pilkington%20avenue,%20birmingham?format=xml&polygon=1&addressdetails=1](https://nominatim.openstreetmap.org/search/135%20pilkington%20avenue,%20birmingham?format=xml&polygon=1&addressdetails=1) +##### XML with KML polygon + +* [https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1](https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1) ```xml - - - 135 - Pilkington Avenue - Wylde Green - Sutton Coldfield - City of Birmingham - West Midlands (county) - B72 - United Kingdom - gb - - + + + + + + + + -1.816513,52.5487566 -1.816434,52.5487473 -1.816429,52.5487629 -1.8163717,52.5487561 -1.8163464,52.5488346 -1.8164599,52.5488481 -1.8164685,52.5488213 -1.8164913,52.548824 -1.816513,52.5487566 + + + + + 135 + Pilkington Avenue + Maney + Sutton Coldfield + Wylde Green + Birmingham + GB-BIR + West Midlands Combined Authority + England + GB-ENG + B72 1LH + United Kingdom + gb + + ``` ##### JSON with SVG polygon -[https://nominatim.openstreetmap.org/search/Unter%20den%20Linden%201%20Berlin?format=json&addressdetails=1&limit=1&polygon_svg=1](https://nominatim.openstreetmap.org/search/Unter%20den%20Linden%201%20Berlin?format=json&addressdetails=1&limit=1&polygon_svg=1) +[https://nominatim.openstreetmap.org/search?q=Unter%20den%20Linden%201%20Berlin&format=json&addressdetails=1&limit=1&polygon_svg=1](https://nominatim.openstreetmap.org/search?q=Unter%20den%20Linden%201%20Berlin&format=json&addressdetails=1&limit=1&polygon_svg=1) ```json - { - "address": { - "city": "Berlin", - "city_district": "Mitte", - "construction": "Unter den Linden", - "continent": "European Union", - "country": "Deutschland", - "country_code": "de", - "house_number": "1", - "neighbourhood": "Scheunenviertel", - "postcode": "10117", - "public_building": "Kommandantenhaus", - "state": "Berlin", - "suburb": "Mitte" - }, - "boundingbox": [ - "52.5170783996582", - "52.5173187255859", - "13.3975105285645", - "13.3981599807739" - ], - "class": "amenity", - "display_name": "Kommandantenhaus, 1, Unter den Linden, Scheunenviertel, Mitte, Berlin, 10117, Deutschland, European Union", - "importance": 0.73606775332943, - "lat": "52.51719785", - "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright", - "lon": "13.3978352028938", - "osm_id": "15976890", - "osm_type": "way", - "place_id": "30848715", - "svg": "M 13.397511 -52.517283599999999 L 13.397829400000001 -52.517299800000004 13.398131599999999 -52.517315099999998 13.398159400000001 -52.517112099999999 13.3975388 -52.517080700000001 Z", - "type": "public_building" - } +[ + { + "address": { + "ISO3166-2-lvl4": "DE-BE", + "borough": "Mitte", + "city": "Berlin", + "country": "Deutschland", + "country_code": "de", + "historic": "Kommandantenhaus", + "house_number": "1", + "neighbourhood": "Friedrichswerder", + "postcode": "10117", + "road": "Unter den Linden", + "suburb": "Mitte" + }, + "boundingbox": [ + "52.5170798", + "52.5173311", + "13.3975116", + "13.3981577" + ], + "class": "historic", + "display_name": "Kommandantenhaus, 1, Unter den Linden, Friedrichswerder, Mitte, Berlin, 10117, Deutschland", + "importance": 0.8135042058306902, + "lat": "52.51720765", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", + "lon": "13.397834399325466", + "osm_id": 15976890, + "osm_type": "way", + "place_id": 108681845, + "svg": "M 13.3975116 -52.5172905 L 13.397549 -52.5170798 13.397715 -52.5170906 13.3977122 -52.5171064 13.3977392 -52.5171086 13.3977417 -52.5170924 13.3979655 -52.5171069 13.3979623 -52.5171233 13.3979893 -52.5171248 13.3979922 -52.5171093 13.3981577 -52.5171203 13.398121 -52.5173311 13.3978115 -52.5173103 Z", + "type": "house" + } +] ``` ##### JSON with address details -[https://nominatim.openstreetmap.org/?format=json&addressdetails=1&q=bakery+in+berlin+wedding&format=json&limit=1](https://nominatim.openstreetmap.org/?format=json&addressdetails=1&q=bakery+in+berlin+wedding&format=json&limit=1) +[https://nominatim.openstreetmap.org/search?addressdetails=1&q=bakery+in+berlin+wedding&format=jsonv2&limit=1](https://nominatim.openstreetmap.org/search?addressdetails=1&q=bakery+in+berlin+wedding&format=jsonv2&limit=1) ```json - { - "address": { - "bakery": "B\u00e4cker Kamps", - "city_district": "Mitte", - "continent": "European Union", - "country": "Deutschland", - "country_code": "de", - "footway": "Bahnsteig U6", - "neighbourhood": "Sprengelkiez", - "postcode": "13353", - "state": "Berlin", - "suburb": "Wedding" - }, - "boundingbox": [ - "52.5460929870605", - "52.5460968017578", - "13.3591794967651", - "13.3591804504395" - ], - "class": "shop", - "display_name": "B\u00e4cker Kamps, Bahnsteig U6, Sprengelkiez, Wedding, Mitte, Berlin, 13353, Deutschland, European Union", - "icon": "https://nominatim.openstreetmap.org/images/mapicons/shopping_bakery.p.20.png", - "importance": 0.201, - "lat": "52.5460941", - "licence": "Data \u00a9 OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright", - "lon": "13.35918", - "osm_id": "317179427", - "osm_type": "node", - "place_id": "1453068", - "type": "bakery" - } +[ + { + "address": { + "ISO3166-2-lvl4": "DE-BE", + "borough": "Mitte", + "city": "Berlin", + "country": "Deutschland", + "country_code": "de", + "neighbourhood": "Sprengelkiez", + "postcode": "13347", + "road": "Lindower Straße", + "shop": "Ditsch", + "suburb": "Wedding" + }, + "addresstype": "shop", + "boundingbox": [ + "52.5427201", + "52.5427654", + "13.3668619", + "13.3669442" + ], + "category": "shop", + "display_name": "Ditsch, Lindower Straße, Sprengelkiez, Wedding, Mitte, Berlin, 13347, Deutschland", + "importance": 9.99999999995449e-06, + "lat": "52.54274275", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "lon": "13.36690305710228", + "name": "Ditsch", + "osm_id": 437595031, + "osm_type": "way", + "place_id": 204751033, + "place_rank": 30, + "type": "bakery" + } +] ``` ##### GeoJSON @@ -301,4 +379,4 @@ Structured requests are faster and require fewer server resources. **Do not comb } ] } -``` \ No newline at end of file +```