]> git.openstreetmap.org Git - nominatim.git/blob - website/reverse.php
second argument of array_merge can be empty
[nominatim.git] / website / reverse.php
1 <?php
2         @define('CONST_ConnectionBucket_PageType', 'Reverse');
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
5         require_once(CONST_BasePath.'/lib/log.php');
6         require_once(CONST_BasePath.'/lib/PlaceLookup.php');
7         require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
8
9         $bAsPoints = false;
10         $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
11         $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
12         $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
13         $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
14         if ( ( ($bAsGeoJSON?1:0)
15                          + ($bAsKML?1:0)
16                          + ($bAsSVG?1:0)
17                          + ($bAsText?1:0)
18                          + ($bAsPoints?1:0)
19                          ) > CONST_PolygonOutput_MaximumTypes)
20         {
21                 if (CONST_PolygonOutput_MaximumTypes)
22                 {
23                         userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
24                 }
25                 else
26                 {
27                         userError("Polygon output is disabled");
28                 }
29                 exit;
30         }
31
32
33         // Polygon simplification threshold (optional)
34         $fThreshold = 0.0;
35         if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold'];
36
37
38         $oDB =& getDB();
39         ini_set('memory_limit', '200M');
40
41         // Format for output
42         $sOutputFormat = 'xml';
43         if (isset($_GET['format']) && ( $_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
44         {
45                 $sOutputFormat = $_GET['format'];
46         }
47
48         // Preferred language
49         $aLangPrefOrder = getPreferredLanguages();
50
51         $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
52
53
54         if (isset($_GET['osm_type']) && isset($_GET['osm_id']) && (int)$_GET['osm_id'] && ($_GET['osm_type'] == 'N' || $_GET['osm_type'] == 'W' || $_GET['osm_type'] == 'R'))
55         {
56                 $aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
57         }
58         else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
59         {
60                 $oReverseGeocode = new ReverseGeocode($oDB);
61                 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
62
63                 $oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
64                 $oReverseGeocode->setZoom(@$_GET['zoom']);
65
66                 $aLookup = $oReverseGeocode->lookup();
67                 if (CONST_Debug) var_dump($aLookup);
68         }
69         else
70         {
71                 $aLookup = null;
72         }
73
74         if ($aLookup)
75         {
76                 $oPlaceLookup = new PlaceLookup($oDB);
77                 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
78                 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
79                 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
80                 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
81
82                 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
83
84                 $oPlaceLookup->setIncludePolygonAsPoints($bAsPoints);
85                 $oPlaceLookup->setIncludePolygonAsText($bAsText);
86                 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
87                 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
88                 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
89                 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
90
91                 $fRadius = $fDiameter = getResultDiameter($aPlace);
92                 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'], $aPlace['lon'], $aPlace['lat'], $fRadius);
93
94                 if ($aOutlineResult)
95                 {
96                         $aPlace = array_merge($aPlace, $aOutlineResult);
97                 }
98         }
99         else
100         {
101                 $aPlace = null;
102         }
103
104         logEnd($oDB, $hLog, sizeof($aPlace)?1:0);
105
106         if (CONST_Debug)
107         {
108                 var_dump($aPlace);
109                 exit;
110         }
111
112         if ($sOutputFormat=='html')
113         {
114                 $sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
115                 $sTileURL = CONST_Map_Tile_URL;
116                 $sTileAttribution = CONST_Map_Tile_Attribution;
117         }
118         include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');