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