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