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