]> git.openstreetmap.org Git - nominatim.git/blob - website/details.php
more partitioning work, os open data postcodes, country list fixes
[nominatim.git] / website / details.php
1 <?php
2         require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
3         require_once(CONST_BasePath.'/lib/log.php');
4
5         $fLoadAvg = getLoadAverage();
6         if ($fLoadAvg > 3)
7         {
8                 echo "Page temporarily blocked due to high server load\n";
9                 exit;
10         }
11
12         ini_set('memory_limit', '200M');
13
14         $oDB =& getDB();
15
16         if (isset($_GET['osmtype']) && isset($_GET['osmid']) && (int)$_GET['osmid'] && ($_GET['osmtype'] == 'N' || $_GET['osmtype'] == 'W' || $_GET['osmtype'] == 'R'))
17         {
18                 $_GET['place_id'] = $oDB->getOne("select place_id from placex where osm_type = '".$_GET['osmtype']."' and osm_id = ".(int)$_GET['osmid']." order by type = 'postcode' asc");
19         }
20
21         if (!isset($_GET['place_id']))
22         {
23                 echo "Please select a place id";
24                 exit;
25         }
26
27         $iPlaceID = (int)$_GET['place_id'];
28
29         $aLangPrefOrder = getPrefferedLangauges();
30         $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
31
32         $hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
33
34         // Make sure the point we are reporting on is fully indexed
35         //$sSQL = "UPDATE placex set indexed = true where indexed = false and place_id = $iPlaceID";
36         //$oDB->query($sSQL);
37
38         // Get the details for this point
39         $sSQL = "select place_id, osm_type, osm_id, class, type, name, admin_level, housenumber, street, isin, postcode, country_code, ";
40         $sSQL .= " parent_place_id, rank_address, rank_search, get_searchrank_label(rank_search) as rank_search_label, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ";
41         $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea,ST_GeometryType(geometry) as geotype, ST_Y(ST_Centroid(geometry)) as lat,ST_X(ST_Centroid(geometry)) as lon ";
42         $sSQL .= " from placex where place_id = $iPlaceID";
43         $aPointDetails = $oDB->getRow($sSQL);
44         IF (PEAR::IsError($aPointDetails))
45         {
46                 var_dump($aPointDetails);
47                 exit;
48         }
49         $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber'];
50         $fLon = $aPointDetails['lon'];
51         $fLat = $aPointDetails['lat'];
52         $iZoom = 14;
53
54         $aClassType = getClassTypesWithImportance();
55         $aPointDetails['icon'] = $aClassType[$aPointDetails['class'].':'.$aPointDetails['type']]['icon'];
56
57         // Get all alternative names (languages, etc)
58         $aPointDetails['aNames'] = array();
59 /*
60         for($i = 1; $i <= $aPointDetails['numnames']; $i++)
61         {
62                 $sSQL = "select name[$i].key, name[$i].value from placex where place_id = $iPlaceID limit 1";
63                 $aNameItem = $oDB->getRow($sSQL);
64                 if (substr($aNameItem['key'],0,5) == 'name:') $aNameItem['key'] = substr($aNameItem['key'],5);
65                 $aPointDetails['aNames'][$aNameItem['key']] = $aNameItem['value'];
66         }
67 */
68         // Get the bounding box and outline polygon
69         $sSQL = "select *,ST_AsText(outline) as outlinestring from get_place_boundingbox($iPlaceID)";
70         $aPointPolygon = $oDB->getRow($sSQL);
71         IF (PEAR::IsError($aPointPolygon))
72         {
73                 var_dump($aPointPolygon);
74                 exit;
75         }
76         if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch))
77         {
78                 preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
79         }
80         elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['outlinestring'],$aMatch))
81         {
82                 $fRadius = 0.01;
83                 $iSteps = ($fRadius * 40000)^2;
84                 $fStepSize = (2*pi())/$iSteps;
85                 $aPolyPoints = array();
86                 for($f = 0; $f < 2*pi(); $f += $fStepSize)
87                 {
88
89                         $aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
90                 }
91                 $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
92                 $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
93                 $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
94                 $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
95         }
96
97         // If it is a road then force all nearby buildings to be indexed (so we can show then in the list)
98 /*
99         if ($aPointDetails['rank_address'] == 26)
100         {
101                 $sSQL = "UPDATE placex set indexed = true from placex as srcplace where placex.indexed = false";
102                 $sSQL .= " and ST_DWithin(placex.geometry, srcplace.geometry, 0.0005) and srcplace.place_id = $iPlaceID";
103                 $oDB->query($sSQL);
104         }
105 */
106         // Address
107         $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], true);
108 /*
109         $sSQL = "select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, ";
110         $sSQL .= "get_searchrank_label(rank_search) as rank_search_label, fromarea, distance, ";
111         $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
112         $sSQL .= " from place_addressline join placex on (address_place_id = placex.place_id)";
113         $sSQL .= " where place_addressline.place_id = $iPlaceID and ((rank_address > 0 AND rank_address < ".$aPointDetails['rank_address'].") OR address_place_id = $iPlaceID) and placex.place_id != $iPlaceID";
114         if ($aPointDetails['country_code'])
115         {
116                 $sSQL .= " and (placex.country_code IS NULL OR placex.country_code = '".$aPointDetails['country_code']."' OR rank_address < 4)";
117         }
118         $sSQL .= " order by cached_rank_address desc,rank_search desc,fromarea desc,distance asc,namelength desc";
119         $aAddressLines = $oDB->getAll($sSQL);
120         IF (PEAR::IsError($aAddressLines))
121         {
122                 var_dump($aAddressLines);
123                 exit;
124         }
125 */
126         // All places this is a parent of
127         $iMaxRankAddress = $aPointDetails['rank_address']+13;
128         $sSQL = "select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, cached_rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, distance, ";
129         $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
130         $sSQL .= " from (select * from place_addressline where address_place_id = $iPlaceID and cached_rank_address < $iMaxRankAddress) as place_addressline join placex on (place_addressline.place_id = placex.place_id)";
131         $sSQL .= " where place_addressline.address_place_id = $iPlaceID and placex.rank_address < $iMaxRankAddress and cached_rank_address > 0 and placex.place_id != $iPlaceID";
132         $sSQL .= " and type != 'postcode'";
133         $sSQL .= " order by cached_rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber limit 1000";
134         $aParentOfLines = $oDB->getAll($sSQL);
135
136         logEnd($oDB, $hLog, 1);
137
138         include('.htlib/output/details-html.php');