]> git.openstreetmap.org Git - nominatim.git/blob - docs/api/Output.md
Merge pull request #4163 from Itz-Agasta/category-support
[nominatim.git] / docs / api / Output.md
1 # Place Output
2
3 The [/reverse](Reverse.md), [/search](Search.md) and [/lookup](Lookup.md)
4 API calls produce very similar output which is explained in this section.
5 There is one section for each format. The format correspond to what was
6 selected via the `format` parameter.
7
8 ## JSON
9
10 The JSON format returns an array of places (for search and lookup) or
11 a single place (for reverse) of the following format:
12
13 ```
14   {
15     "place_id": 100149,
16     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
17     "osm_type": "node",
18     "osm_id": "107775",
19     "boundingbox": ["51.3473219", "51.6673219", "-0.2876474", "0.0323526"],
20     "lat": "51.5073219",
21     "lon": "-0.1276474",
22     "display_name": "London, Greater London, England, SW1A 2DU, United Kingdom",
23     "class": "place",
24     "type": "city",
25     "importance": 0.9654895765402,
26     "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png",
27     "address": {
28       "city": "London",
29       "state_district": "Greater London",
30       "state": "England",
31       "ISO3166-2-lvl4": "GB-ENG",
32       "postcode": "SW1A 2DU",
33       "country": "United Kingdom",
34       "country_code": "gb"
35     },
36     "extratags": {
37       "capital": "yes",
38       "website": "http://www.london.gov.uk",
39       "wikidata": "Q84",
40       "wikipedia": "en:London",
41       "population": "8416535"
42     }
43   }
44 ```
45
46 The possible fields are:
47
48  * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id))
49  * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference))
50  * `boundingbox` - area of corner coordinates ([see notes](#boundingbox))
51  * `lat`, `lon` - latitude and longitude of the centroid of the object
52  * `display_name` - full comma-separated address
53  * `class`, `type` - key and value of the main OSM tag
54  * `importance` - computed importance rank
55  * `icon` - link to class icon (if available)
56  * `address` - dictionary of address details (only with `addressdetails=1`,
57    [see notes](#addressdetails))
58  * `extratags` - dictionary with additional useful tags like website or maxspeed
59    (only with `extratags=1`)
60  * `namedetails` - dictionary with full list of available names including ref etc.
61  * `geojson`, `svg`, `geotext`, `geokml` - full geometry
62    (only with the appropriate `polygon_*` parameter)
63  * `entrances` - array of objects representing tagged entrances for the object, or
64    null if none are found (only with `entrances=1`)
65
66 ## JSONv2
67
68 This is the same as the JSON format with two changes:
69
70  * `class` renamed to `category`
71  * additional field `place_rank` with the search rank of the object
72
73 ## GeoJSON
74
75 This format follows the [RFC7946](https://geojson.org). Every feature includes
76 a bounding box (`bbox`).
77
78 The properties object has the following fields:
79
80  * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id))
81  * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference))
82  * `category`, `type` - key and value of the main OSM tag
83  * `display_name` - full comma-separated address
84  * `place_rank` - class search rank
85  * `importance` - computed importance rank
86  * `icon` - link to class icon (if available)
87  * `address` - dictionary of address details (only with `addressdetails=1`,
88    [see notes](#addressdetails))
89  * `extratags` - dictionary with additional useful tags like `website` or `maxspeed`
90    (only with `extratags=1`)
91  * `namedetails` - dictionary with full list of available names including ref etc.
92  * `entrances` - array of objects representing tagged entrances for the object, or
93    null if none are found (only with `entrances=1`)
94
95 Use `polygon_geojson` to output the full geometry of the object instead
96 of the centroid.
97
98 ## GeocodeJSON
99
100 The GeocodeJSON format follows the
101 [GeocodeJSON spec 0.1.0](https://github.com/geocoders/geocodejson-spec).
102 The following feature attributes are implemented:
103
104  * `osm_type`, `osm_id` - reference to the OSM object (unofficial extension, [see notes](#osm-reference))
105  * `type` - the 'address level' of the object ('house', 'street', `district`, `city`,
106             `county`, `state`, `country`, `locality`)
107  * `osm_key`- key of the main tag of the OSM object (e.g. boundary, highway, amenity)
108  * `osm_value` - value of the main tag of the OSM object (e.g. residential, restaurant)
109  * `label` - full comma-separated address
110  * `name` - localised name of the place
111  * `housenumber`, `street`, `locality`, `district`, `postcode`, `city`,
112    `county`, `state`, `country` -
113    provided when it can be determined from the address (only with `addressdetails=1`)
114  * `admin` - list of localised names of administrative boundaries (only with `addressdetails=1`)
115  * `extra` - dictionary with additional useful tags like `website` or `maxspeed`
116    (only with `extratags=1`)
117  * `entrances` - array of objects representing tagged entrances for the object, or
118    null if none are found (only with `entrances=1`)
119
120
121 Use `polygon_geojson` to output the full geometry of the object instead
122 of the centroid.
123
124 ## XML
125
126 The XML response returns one or more place objects in slightly different
127 formats depending on the API call.
128
129 ### Reverse
130
131 ```
132 <reversegeocode timestamp="Sat, 11 Aug 18 11:53:21 +0000"
133                 attribution="Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright"
134                 querystring="lat=48.400381&lon=11.745876&zoom=5&format=xml">
135   <result place_id="179509537" osm_type="relation" osm_id="2145268" ref="BY" place_rank="15" address_rank="15"
136           lat="48.9467562" lon="11.4038717"
137           boundingbox="47.2701114,50.5647142,8.9763497,13.8396373">
138        Bavaria, Germany
139   </result>
140   <addressparts>
141      <state>Bavaria</state>
142      <ISO3166-2-lvl4>DE-BY</ISO3166-2-lvl4>
143      <country>Germany</country>
144      <country_code>de</country_code>
145   </addressparts>
146   <extratags>
147     <tag key="place" value="state"/>
148     <tag key="wikidata" value="Q980"/>
149     <tag key="wikipedia" value="de:Bayern"/>
150     <tag key="population" value="12520000"/>
151     <tag key="name:prefix" value="Freistaat"/>
152   </extratags>
153 </reversegeocode>
154 ```
155
156 The attributes of the outer `reversegeocode` element return generic information
157 about the query, including the time when the response was sent (in UTC),
158 attribution to OSM and the original querystring.
159
160 The place information can be found in the `result` element. The attributes of that element contain:
161
162  * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id))
163  * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference))
164  * `ref` - content of `ref` tag if it exists
165  * `lat`, `lon` - latitude and longitude of the centroid of the object
166  * `boundingbox` - comma-separated list of corner coordinates ([see notes](#boundingbox))
167
168 The full address of the result can be found in the content of the
169 `result` element as a comma-separated list.
170
171 Additional information requested with `addressdetails=1`, `extratags=1`,
172 `namedetails=1`, and `entrances=1` can be found in extra elements.
173
174 ### Search and Lookup
175
176 ```
177 <searchresults timestamp="Sat, 11 Aug 18 11:55:35 +0000"
178                attribution="Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright"
179                querystring="london" polygon="false" exclude_place_ids="N107775"
180                more_url="https://nominatim.openstreetmap.org/search?q=london&addressdetails=1&extratags=1&exclude_place_ids=N107775&format=xml&accept-language=en-US%2Cen%3Bq%3D0.7%2Cde%3Bq%3D0.3">
181   <place place_id="100149" osm_type="node" osm_id="107775" place_rank="15" address_rank="15"
182          boundingbox="51.3473219,51.6673219,-0.2876474,0.0323526" lat="51.5073219" lon="-0.1276474"
183          display_name="London, Greater London, England, SW1A 2DU, United Kingdom"
184          class="place" type="city" importance="0.9654895765402"
185          icon="https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png">
186     <extratags>
187       <tag key="capital" value="yes"/>
188       <tag key="website" value="http://www.london.gov.uk"/>
189       <tag key="wikidata" value="Q84"/>
190       <tag key="wikipedia" value="en:London"/>
191       <tag key="population" value="8416535"/>
192     </extratags>
193     <city>London</city>
194     <state_district>Greater London</state_district>
195     <state>England</state>
196     <ISO3166-2-lvl4>GB-ENG</ISO3166-2-lvl4>
197     <postcode>SW1A 2DU</postcode>
198     <country>United Kingdom</country>
199     <country_code>gb</country_code>
200   </place>
201 </searchresults>
202 ```
203
204 The attributes of the outer `searchresults` or `lookupresults` element return
205 generic information about the query:
206
207  * `timestamp` - UTC time when the response was sent
208  * `attribution` - OSM licensing information
209  * `querystring` - original query
210  * `polygon` - true when extra geometry information was requested
211  * `exclude_place_ids` - IDs of places that should be ignored in a follow-up request (OSM IDs where possible, otherwise `place_id`s)
212  * `more_url` - search call that will yield additional results for the query
213    just sent
214
215 The place information can be found in the `place` elements, of which there may
216 be more than one. The attributes of that element contain:
217
218  * `place_id` - reference to the Nominatim internal database ID ([see notes](#place_id-is-not-a-persistent-id))
219  * `osm_type`, `osm_id` - reference to the OSM object ([see notes](#osm-reference))
220  * `ref` - content of `ref` tag if it exists
221  * `lat`, `lon` - latitude and longitude of the centroid of the object
222  * `boundingbox` - comma-separated list of corner coordinates ([see notes](#boundingbox))
223  * `place_rank` - class [search rank](../customize/Ranking.md#search-rank)
224  * `address_rank` - place [address rank](../customize/Ranking.md#address-rank)
225  * `display_name` - full comma-separated address
226  * `class`, `type` - key and value of the main OSM tag
227  * `importance` - computed importance rank
228  * `icon` - link to class icon (if available)
229
230 When `addressdetails=1` is requested, the localised address parts appear
231 as subelements with the type of the address part.
232
233 Additional information requested with `extratags=1`, `namedetails=1`, and
234 `entrances=1` can be found in extra elements as sub-element of `extratags`,
235 `namedetails`, and `entrances` respectively.
236
237
238 ## Debug output
239
240 | Parameter | Value  | Default |
241 |-----------| -----  | ------- |
242 | debug     | 0 or 1 | 0       |
243
244 Adding `debug=1` to a query to the [/search](Search.md), [/reverse](Reverse.md),
245 [/lookup](Lookup.md) or [/details](Details.md) endpoint switches the output to
246 an HTML page with assorted developer debug information: how Nominatim parsed,
247 understood and executed its database searches.
248
249 Debug output is disabled by default. It is only available when the server
250 administrator has enabled
251 [`NOMINATIM_SERVE_DEBUG_OUTPUT`](../customize/Settings.md#nominatim_serve_debug_output).
252
253
254 ## Notes on field values
255
256 ### place_id is not a persistent id
257
258 The `place_id` is an internal identifier that is assigned data is imported
259 into a Nominatim database. The same OSM object will have a different value
260 on another server. It may even change its ID on the same server when it is
261 removed and reimported while updating the database with fresh OSM data.
262 It is thus not useful to treat it as permanent for later use.
263
264 The combination `osm_type`+`osm_id` is slightly better but remember in
265 OpenStreetMap mappers can delete, split, recreate places (and those
266 get a new `osm_id`), there is no link between those old and new ids.
267 Places can also change their meaning without changing their `osm_id`,
268 e.g. when a restaurant is retagged as supermarket. For a more in-depth
269 discussion see [Permanent ID](https://wiki.openstreetmap.org/wiki/Permanent_ID).
270
271 If you need an ID that is consistent over multiple installations of Nominatim,
272 then you should use the combination of `osm_type`+`osm_id`+`class`.
273
274 ### OSM reference
275
276 Nominatim may sometimes return special objects that do not correspond directly
277 to an object in OpenStreetMap. These are:
278
279 * **Postcodes**. Nominatim returns an postcode point created from all mapped
280   postcodes of the same name. The class and type of these object is `place=postcdode`.
281   No `osm_type` and `osm_id` are included in the result.
282 * **Housenumber interpolations**. Nominatim returns a single interpolated
283   housenumber from the interpolation way. The class and type are `place=house`
284   and `osm_type` and `osm_id` correspond to the interpolation way in OSM.
285 * **TIGER housenumber.** Nominatim returns a single interpolated housenumber
286   from the TIGER data. The class and type are `place=house`
287   and `osm_type` and `osm_id` correspond to the street mentioned in the result.
288
289 Please note that the `osm_type` and `osm_id` returned may be changed in the
290 future. You should not expect to only find `node`, `way` and `relation` for
291 the type.
292
293 ### boundingbox
294
295 Comma separated list of min latitude, max latitude, min longitude, max longitude.
296 The whole planet would be `-90,90,-180,180`.
297
298 Can be used to pan and center the map on the result, for example with leafletjs
299 mapping library
300 `map.fitBounds([[bbox[0],bbox[2]],[bbox[1],bbox[3]]], {padding: [20, 20], maxzoom: 16});`
301
302 Bounds crossing the antimeridian have a min latitude -180 and max latitude 180,
303 essentially covering the entire planet
304 (see [issue 184](https://github.com/openstreetmap/Nominatim/issues/184)).
305
306 ### addressdetails
307
308 Address details in the xml and json formats return a list of names together
309 with a designation label. Per default the following labels may appear:
310
311  * continent
312  * country, country_code
313  * region, state, state_district, county, ISO3166-2-lvl<admin_level>
314  * municipality, city, town, village
315  * city_district, district, borough, suburb, subdivision
316  * hamlet, croft, isolated_dwelling
317  * neighbourhood, allotments, quarter
318  * city_block, residential, farm, farmyard, industrial, commercial, retail
319  * road
320  * house_number, house_name
321  * emergency, historic, military, natural, landuse, place, railway,
322    man_made, aerialway, boundary, amenity, aeroway, club, craft, leisure,
323    office, mountain_pass, shop, tourism, bridge, tunnel, waterway
324  * postcode
325
326 They roughly correspond to the classification of the OpenStreetMap data
327 according to either the `place` tag or the main key of the object.
328
329 ### entrances
330
331 Entrance details in the xml and json formats return the latitude and longitude
332 of the entrance, the osm node ID, the [type of
333 entrance](https://wiki.openstreetmap.org/wiki/Key:entrance), and any extra tags
334 associated with the entrance node.
335
336  * osm_id
337  * type
338  * lat
339  * lon
340  * extratags
341
342 They roughly correspond to the classification of the OpenStreetMap data
343 according to either the `place` tag or the main key of the object.
344
345 #### Example
346
347 ##### JSON
348
349 [https://nominatim.openstreetmap.org/details?osmtype=W&osmid=32619803&entrances=1&format=json](https://nominatim.openstreetmap.org/details?osmtype=W&osmid=32619803&entrances=1&format=json)
350
351
352 ```json
353 {
354   "place_id": 124325848,
355   "parent_place_id": 123936289,
356   "osm_type": "W",
357   "osm_id": 32619803,
358   "category": "shop",
359   "type": "supermarket",
360   "admin_level": 15,
361   "localname": "PENNY",
362   ...
363   "entrances": [
364     {
365       "osm_id": 1733488238,
366       "type": "yes",
367       "lat": "51.0466704",
368       "lon": "12.8077106",
369       "extratags": {
370         "foot": "yes"
371       }
372     },
373     {
374       "osm_id": 1733488256,
375       "type": "main",
376       "lat": "51.0467197",
377       "lon": "12.8078448",
378       "extratags": {
379         "foot": "yes"
380       }
381     },
382     {
383       "osm_id": 1733498087,
384       "type": "exit",
385       "lat": "51.0467081",
386       "lon": "12.8078131",
387       "extratags": {
388         "foot": "yes"
389       }
390     },
391     {
392       "osm_id": 7914950851,
393       "type": "service",
394       "lat": "51.0468487",
395       "lon": "12.8075876",
396       "extratags": {
397         "access": "delivery"
398       }
399     }
400   ]
401 }
402 ```