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');
9 require_once(CONST_BasePath.'/lib/output.php');
11 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
13 $fLoadAvg = getLoadAverage();
14 if ($fLoadAvg > 2) sleep(60);
15 if ($fLoadAvg > 4) sleep(120);
18 echo "Bulk User: Temporary block due to high server load\n";
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)) > CONST_PolygonOutput_MaximumTypes)
31 if (CONST_PolygonOutput_MaximumTypes)
33 userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
37 userError("Polygon output is disabled");
43 // Polygon simplification threshold (optional)
44 $fThreshold = getParamFloat('polygon_threshold', 0.0);
48 ini_set('memory_limit', '200M');
51 $sOutputFormat = getParamSet('format', array('html', 'xml', 'json', 'jsonv2'), 'xml');
54 $aLangPrefOrder = getPreferredLanguages();
56 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
59 $sOsmType = getParamSet('osm_type', array('N', 'W', 'R'));
60 $iOsmId = getParamInt('osm_id', -1);
61 $fLat = getParamFloat('lat');
62 $fLon = getParamFloat('lon');
63 if ($sOsmType && $iOsmId > 0)
65 $aLookup = array('osm_type' => $sOsmType, 'osm_id' => $iOsmId);
67 else if ($fLat !== false && $fLon !==false)
69 $oReverseGeocode = new ReverseGeocode($oDB);
70 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
72 $oReverseGeocode->setLatLon($fLat, $fLon);
73 $oReverseGeocode->setZoom(getParamInt('zoom', 18));
75 $aLookup = $oReverseGeocode->lookup();
76 if (CONST_Debug) var_dump($aLookup);
78 else if ($sOutputFormat != 'html')
80 userError("Need coordinates or OSM object to lookup.");
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));
91 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
93 $oPlaceLookup->setIncludePolygonAsPoints(false);
94 $oPlaceLookup->setIncludePolygonAsText($bAsText);
95 $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
96 $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
97 $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
98 $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
100 $fRadius = $fDiameter = getResultDiameter($aPlace);
101 $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'], $aPlace['lon'], $aPlace['lat'], $fRadius);
105 $aPlace = array_merge($aPlace, $aOutlineResult);
120 if ($sOutputFormat=='html')
122 $sDataDate = chksql($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;
126 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');