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