]> git.openstreetmap.org Git - nominatim.git/blob - website/reverse.php
Merge pull request #819 from mtmail/tiger-2017-import
[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 require_once(CONST_BasePath.'/lib/output.php');
10 ini_set('memory_limit', '200M');
11
12 $oParams = new Nominatim\ParameterParser();
13
14 $bAsGeoJSON = $oParams->getBool('polygon_geojson');
15 $bAsKML = $oParams->getBool('polygon_kml');
16 $bAsSVG = $oParams->getBool('polygon_svg');
17 $bAsText = $oParams->getBool('polygon_text');
18
19 $iWantedTypes = ($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0) + ($bAsText?1:0);
20 if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
21     if (CONST_PolygonOutput_MaximumTypes) {
22         userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
23     } else {
24         userError("Polygon output is disabled");
25     }
26 }
27
28 // Polygon simplification threshold (optional)
29 $fThreshold = $oParams->getFloat('polygon_threshold', 0.0);
30
31 // Format for output
32 $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'xml');
33
34 // Preferred language
35 $aLangPrefOrder = $oParams->getPreferredLanguages();
36
37 $oDB =& getDB();
38
39 $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
40
41
42 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
43 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
44 $oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
45 $oPlaceLookup->setIncludeExtraTags($oParams->getBool('extratags', false));
46 $oPlaceLookup->setIncludeNameDetails($oParams->getBool('namedetails', false));
47
48 $sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R'));
49 $iOsmId = $oParams->getInt('osm_id', -1);
50 $fLat = $oParams->getFloat('lat');
51 $fLon = $oParams->getFloat('lon');
52 $iZoom = $oParams->getInt('zoom');
53 if ($sOsmType && $iOsmId > 0) {
54     $aPlace = $oPlaceLookup->lookupOSMID($sOsmType, $iOsmId);
55 } elseif ($fLat !== false && $fLon !== false) {
56     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
57     $oReverseGeocode->setZoom($iZoom !== false ? $iZoom : 18);
58
59     $aLookup = $oReverseGeocode->lookup($fLat, $fLon);
60     if (CONST_Debug) var_dump($aLookup);
61
62     $aPlace = $oPlaceLookup->lookup(
63         (int)$aLookup['place_id'],
64         $aLookup['type'],
65         $aLookup['fraction']
66     );
67 } elseif ($sOutputFormat != 'html') {
68     userError("Need coordinates or OSM object to lookup.");
69 }
70
71 if (isset($aPlace)) {
72     $oPlaceLookup->setIncludePolygonAsPoints(false);
73     $oPlaceLookup->setIncludePolygonAsText($bAsText);
74     $oPlaceLookup->setIncludePolygonAsGeoJSON($bAsGeoJSON);
75     $oPlaceLookup->setIncludePolygonAsKML($bAsKML);
76     $oPlaceLookup->setIncludePolygonAsSVG($bAsSVG);
77     $oPlaceLookup->setPolygonSimplificationThreshold($fThreshold);
78
79     $fRadius = $fDiameter = getResultDiameter($aPlace);
80     $aOutlineResult = $oPlaceLookup->getOutlines(
81         $aPlace['place_id'],
82         $aPlace['lon'],
83         $aPlace['lat'],
84         $fRadius
85     );
86
87     if ($aOutlineResult) {
88         $aPlace = array_merge($aPlace, $aOutlineResult);
89     }
90 } else {
91     $aPlace = [];
92 }
93
94
95 if (CONST_Debug) {
96     var_dump($aPlace);
97     exit;
98 }
99
100 if ($sOutputFormat == 'html') {
101     $sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
102     $sTileURL = CONST_Map_Tile_URL;
103     $sTileAttribution = CONST_Map_Tile_Attribution;
104 }
105 include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');