]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/template/address-geojson.php
force use of geometry index for reverse polygon lookup
[nominatim.git] / lib-php / template / address-geojson.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10
11 $aFilteredPlaces = array();
12
13 if (empty($aPlace)) {
14     if (isset($sError)) {
15         $aFilteredPlaces['error'] = $sError;
16     } else {
17         $aFilteredPlaces['error'] = 'Unable to geocode';
18     }
19     javascript_renderData($aFilteredPlaces);
20 } else {
21     $aFilteredPlaces = array(
22                         'type' => 'Feature',
23                         'properties' => array()
24                        );
25
26     if (isset($aPlace['place_id'])) {
27         $aFilteredPlaces['properties']['place_id'] = $aPlace['place_id'];
28     }
29     $sOSMType = formatOSMType($aPlace['osm_type']);
30     if ($sOSMType) {
31         $aFilteredPlaces['properties']['osm_type'] = $sOSMType;
32         $aFilteredPlaces['properties']['osm_id'] = $aPlace['osm_id'];
33     }
34
35     $aFilteredPlaces['properties']['place_rank'] = $aPlace['rank_search'];
36
37     $aFilteredPlaces['properties']['category'] = $aPlace['class'];
38     $aFilteredPlaces['properties']['type'] = $aPlace['type'];
39
40     $aFilteredPlaces['properties']['importance'] = $aPlace['importance'];
41
42     $aFilteredPlaces['properties']['addresstype'] = strtolower($aPlace['addresstype']);
43
44     $aFilteredPlaces['properties']['name'] = $aPlace['placename'];
45
46     $aFilteredPlaces['properties']['display_name'] = $aPlace['langaddress'];
47
48     if (isset($aPlace['address'])) {
49         $aFilteredPlaces['properties']['address'] = $aPlace['address']->getAddressNames();
50     }
51     if (isset($aPlace['sExtraTags'])) {
52         $aFilteredPlaces['properties']['extratags'] = $aPlace['sExtraTags'];
53     }
54     if (isset($aPlace['sNameDetails'])) {
55         $aFilteredPlaces['properties']['namedetails'] = $aPlace['sNameDetails'];
56     }
57
58     if (isset($aPlace['aBoundingBox'])) {
59         $aFilteredPlaces['bbox'] = array(
60                                     (float) $aPlace['aBoundingBox'][2], // minlon
61                                     (float) $aPlace['aBoundingBox'][0], // minlat
62                                     (float) $aPlace['aBoundingBox'][3], // maxlon
63                                     (float) $aPlace['aBoundingBox'][1]  // maxlat
64                                    );
65     }
66
67     if (isset($aPlace['asgeojson'])) {
68         $aFilteredPlaces['geometry'] = json_decode($aPlace['asgeojson'], true);
69     } else {
70         $aFilteredPlaces['geometry'] = array(
71                                         'type' => 'Point',
72                                         'coordinates' => array(
73                                                           (float) $aPlace['lon'],
74                                                           (float) $aPlace['lat']
75                                                          )
76                                        );
77     }
78
79
80     javascript_renderData(array(
81                            'type' => 'FeatureCollection',
82                            'licence' => 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
83                            'features' => array($aFilteredPlaces)
84                           ));
85 }