2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
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');
10 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
12 $fLoadAvg = getLoadAverage();
13 if ($fLoadAvg > 2) sleep(60);
14 if ($fLoadAvg > 4) sleep(120);
17 echo "Bulk User: Temporary block due to high server load\n";
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)
30 if (CONST_PolygonOutput_MaximumTypes)
32 userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
36 userError("Polygon output is disabled");
42 // Polygon simplification threshold (optional)
43 $fThreshold = getParamFloat('polygon_threshold', 0.0);
47 ini_set('memory_limit', '200M');
50 $sOutputFormat = getParamSet('format', array('html', 'xml', 'json', 'jsonv2'), 'xml');
53 $aLangPrefOrder = getPreferredLanguages();
55 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
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)
64 $aLookup = array('osm_type' => $sOsmType, 'osm_id' => $iOsmId);
66 else if ($fLat !== false && $fLon !==false)
68 $oReverseGeocode = new ReverseGeocode($oDB);
69 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
71 $oReverseGeocode->setLatLon($fLat, $fLon);
72 $oReverseGeocode->setZoom(getParamInt('zoom', 18));
74 $aLookup = $oReverseGeocode->lookup();
75 if (CONST_Debug) var_dump($aLookup);
77 else if ($sOutputFormat != 'html')
79 userError("Need coordinates or OSM object to lookup.");
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));
90 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
92 $oPlaceLookup->setIncludePolygonAsPoints(false);
93 $oPlaceLookup->setIncludePolygonAsText($bAsText);
94 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
95 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
96 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
97 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
99 $fRadius = $fDiameter = getResultDiameter($aPlace);
100 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'], $aPlace['lon'], $aPlace['lat'], $fRadius);
104 $aPlace = array_merge($aPlace, $aOutlineResult);
119 if ($sOutputFormat=='html')
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;
125 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');