X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/2613ebfa0143cdd1e3220577d48d9aa8341dbf38..3be797c7595dec10812f16fd0ec778582d811fd4:/docs/api/Search.md diff --git a/docs/api/Search.md b/docs/api/Search.md index e166abaf..4b9d773c 100644 --- a/docs/api/Search.md +++ b/docs/api/Search.md @@ -1,123 +1,177 @@ +# 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 to look up a location from a textual description. +Nominatim supports structured as well as 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`). +Note that this only limits the items to be found, it's not suited to return complete +lists of OSM objects of a specific type. For those use [Overpass API](https://overpass-api.de/). -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) +## Parameters -(Commas are optional, but improve performance by reducing the complexity of the search.) +The search API has the following two formats: -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. +``` + https://nominatim.openstreetmap.org/search/? +``` -### Parameters +This format only accepts a free-form query string where the +parts of the query are separated by slashes. ``` https://nominatim.openstreetmap.org/search? - https://nominatim.openstreetmap.org/search/? ``` -* `format=[html|xml|json|jsonv2]` +In this form, the query may be given through 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](//nominatim.openstreetmap.org/search?q=pilkington+avenue,birmingham) as well as for + [birmingham, pilkington avenue](//nominatim.openstreetmap.org/search?q=birmingham,+pilkington+avenue). + Commas are optional, but improve performance by reducing the complexity of the search. + + +* `street= ` +* `city=` +* `county=` +* `state=` +* `country=` +* `postalcode=` - * Output format - * defaults to `html` + 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**. +All three query forms accept the additional paramters listed below. + +### Output format + +* `format=[html|xml|json|jsonv2|geojson|geocodejson]` + +See [Place Output Formats](Output.md) for details on each format. (Default: html) * `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 + +* `addressdetails=[0|1]` - * 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. +Include a breakdown of the address into elements. (Default: 0) + + +* `extratags=[0|1]` + +Include additional information in the result if available, +e.g. wikipedia link, opening hours. (Default: 0) -* `q=` - * Query string to search for. - * Alternatively can be entered as: +* `namedetails=[0|1]` - * `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**. +Include a list of alternative names in the results. These may include +language variants, references, operator and brand. (Default: 0) + + +### Language of results + +* `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 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. +Limit search results to one or more countries. `` must be the +ISO 3166-1alpha2 code, e.g. `gb` for the United Kingdom, `de` for Germany. + + +* `exclude_place_ids=` + +Limit the number of returned results. (Default: 10, Maximum: 50) + * `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. + +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. + * `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. -* `polygon=[0|1]` - * defaults to 0 - * Output polygon outlines for items found **(deprecated, use one of the polygon_* parameters instead)** +When a viewbox is given, restrict the result to items contained with that +viewbox (see above). When `viewbox` and `bounded=1` are given, an amenity +only search is allowed. In this case, give the special keyword for the +amenity in square brackets, e.g. `[pub]`. (Default: 0) -* `addressdetails=[0|1]` - * defaults to 0 - * Include a breakdown of the address into elements -* `email=` +### Polygon output - * 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. +* `polygon_geojson=1` +* `polygon_kml=1` +* `polygon_svg=1` +* `polygon_text=1` -* `exclude_place_ids=` - * defaults to 10 - * Limit the number of returned results. +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. (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]` - * 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. -* `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. +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 unless +this parameter is set to 0. (Default: 1) -* `polygon_geojson=1` - * Output geometry of results in geojson format. -* `polygon_kml=1` - * Output geometry of results in kml format. -* `polygon_svg=1` - * Output geometry of results in svg format. +* `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) -* `polygon_text=1` - * Output geometry of results as a WKT. -* `extratags=1` - * Include additional information in the result if available, e.g. wikipedia link, opening hours. -* `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/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) * [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 @@ -141,7 +195,9 @@ Structured requests are faster and require fewer server resources. **Do not comb ``` -* [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) +##### 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) ```json { @@ -179,7 +235,9 @@ Structured requests are faster and require fewer server resources. **Do not comb } ``` -* [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) +##### 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) ```json { @@ -213,4 +271,79 @@ Structured requests are faster and require fewer server resources. **Do not comb "place_id": "1453068", "type": "bakery" } -``` \ No newline at end of file +``` + +##### GeoJSON + +[https://nominatim.openstreetmap.org/search?q=17+Strada+Pictor+Alexandru+Romano%2C+Bukarest&format=geojson](https://nominatim.openstreetmap.org/search?q=17+Strada+Pictor+Alexandru+Romano%2C+Bukarest&format=geojson) + +```json +{ + "type": "FeatureCollection", + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", + "features": [ + { + "type": "Feature", + "properties": { + "place_id": "35811445", + "osm_type": "node", + "osm_id": "2846295644", + "display_name": "17, Strada Pictor Alexandru Romano, Bukarest, Bucharest, Sector 2, Bucharest, 023964, Romania", + "place_rank": "30", + "category": "place", + "type": "house", + "importance": 0.62025 + }, + "bbox": [ + 26.1156689, + 44.4354754, + 26.1157689, + 44.4355754 + ], + "geometry": { + "type": "Point", + "coordinates": [ + 26.1157189, + 44.4355254 + ] + } + } + ] +} +``` + +##### GeocodeJSON + +[https://nominatim.openstreetmap.org/search?q=%CE%91%CE%B3%CE%AF%CE%B1+%CE%A4%CF%81%CE%B9%CE%AC%CE%B4%CE%B1%2C+%CE%91%CE%B4%CF%89%CE%BD%CE%B9%CE%B4%CE%BF%CF%82%2C+Athens%2C+Greece&format=geocodejson](https://nominatim.openstreetmap.org/search?q=%CE%91%CE%B3%CE%AF%CE%B1+%CE%A4%CF%81%CE%B9%CE%AC%CE%B4%CE%B1%2C+%CE%91%CE%B4%CF%89%CE%BD%CE%B9%CE%B4%CE%BF%CF%82%2C+Athens%2C+Greece&format=geocodejson) + +```json +{ + "type": "FeatureCollection", + "geocoding": { + "version": "0.1.0", + "attribution": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", + "licence": "ODbL", + "query": "Αγία Τριάδα, Αδωνιδος, Athens, Greece" + }, + "features": [ + { + "type": "Feature", + "properties": { + "geocoding": { + "type": "place_of_worship", + "label": "Αγία Τριάδα, Αδωνιδος, Άγιος Νικόλαος, 5º Δημοτικό Διαμέρισμα Αθηνών, Athens, Municipality of Athens, Regional Unit of Central Athens, Region of Attica, Attica, 11472, Greece", + "name": "Αγία Τριάδα", + "admin": null + } + }, + "geometry": { + "type": "Point", + "coordinates": [ + 23.72949633941, + 38.0051697 + ] + } + } + ] +} +```