]> git.openstreetmap.org Git - nominatim.git/blob - website/details.php
remove accidentally committed exit command
[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         $sOutputFormat = 'html';
6 /*
7         $fLoadAvg = getLoadAverage();
8         if ($fLoadAvg > 3)
9         {
10                 echo "Page temporarily blocked due to high server load\n";
11                 exit;
12         }
13 */
14         ini_set('memory_limit', '200M');
15
16         $oDB =& getDB();
17
18         if (isset($_GET['osmtype']) && isset($_GET['osmid']) && (int)$_GET['osmid'] && ($_GET['osmtype'] == 'N' || $_GET['osmtype'] == 'W' || $_GET['osmtype'] == 'R'))
19         {
20                 $_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");
21
22                 // Be nice about our error messages for broken geometry
23                 if (!$_GET['place_id'])
24                 {
25                         $sErrorMessage = $oDB->getOne("select ST_IsValidReason(geometry) from place where osm_type = '".$_GET['osmtype']."' and osm_id = ".(int)$_GET['osmid']." order by type = 'postcode' asc");
26                         if (!PEAR::isError($sErrorMessage) && $sErrorMessage) {
27                                 echo "Problem with geometry: ";
28                                 echo $sErrorMessage;
29                                 exit;
30                         }
31                 }
32         }
33
34         if (!isset($_GET['place_id']))
35         {
36                 echo "Please select a place id";
37                 exit;
38         }
39
40         $iPlaceID = (int)$_GET['place_id'];
41
42         $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID);
43         if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
44         $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID);
45         if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
46
47         $aLangPrefOrder = getPreferredLanguages();
48         $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
49
50         $hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
51
52         // Make sure the point we are reporting on is fully indexed
53         //$sSQL = "UPDATE placex set indexed = true where indexed = false and place_id = $iPlaceID";
54         //$oDB->query($sSQL);
55
56         // Get the details for this point
57         $sSQL = "select place_id, osm_type, osm_id, class, type, name, admin_level, housenumber, street, isin, postcode, country_code, importance, wikipedia,";
58         $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, ";
59         $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 ";
60         $sSQL .= " from placex where place_id = $iPlaceID";
61         $aPointDetails = $oDB->getRow($sSQL);
62         if (PEAR::IsError($aPointDetails))
63         {
64                 failInternalError("Could not get details of place object.", $sSQL, $aPointDetails);
65         }
66
67         $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber'];
68         $fLon = $aPointDetails['lon'];
69         $fLat = $aPointDetails['lat'];
70         $iZoom = 14;
71
72         $aClassType = getClassTypesWithImportance();
73         $aPointDetails['icon'] = $aClassType[$aPointDetails['class'].':'.$aPointDetails['type']]['icon'];
74
75         // Get all alternative names (languages, etc)
76         $sSQL = "select (each(name)).key,(each(name)).value from placex where place_id = $iPlaceID order by (each(name)).key";
77         $aPointDetails['aNames'] = $oDB->getAssoc($sSQL);
78
79         // Extra tags
80         $sSQL = "select (each(extratags)).key,(each(extratags)).value from placex where place_id = $iPlaceID order by (each(extratags)).key";
81         $aPointDetails['aExtraTags'] = $oDB->getAssoc($sSQL);
82
83         // Get the bounding box and outline polygon
84         $sSQL = "select ST_AsText(geometry) as outlinestring,";
85         $sSQL .= "ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,";
86         $sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon";
87         $sSQL .= " from placex where place_id = $iPlaceID";
88         $aPointPolygon = $oDB->getRow($sSQL);
89         IF (PEAR::IsError($aPointPolygon))
90         {
91                 failInternalError("Could not get bounding box of place object.", $sSQL, $aPointPolygon);
92         }
93         if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch))
94         {
95                 preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
96         }
97         elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch))
98         {
99                 // TODO: this just takes the first ring
100                 preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
101         }
102         elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['outlinestring'],$aMatch))
103         {
104                 $fRadius = 0.01;
105                 if ($aPointDetails['rank_search'] > 20) $fRadius = 0.0001;
106                 $iSteps = min(max(($fRadius * 40000)^2,16),100);
107                 $fStepSize = (2*pi())/$iSteps;
108                 $aPolyPoints = array();
109                 for($f = 0; $f < 2*pi(); $f += $fStepSize)
110                 {
111
112                         $aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
113                 }
114                 $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
115                 $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
116                 $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
117                 $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
118         }
119
120         // Address
121         $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], true);
122
123         // Linked places
124         $sSQL = "select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_distance(geometry, placegeometry) as distance, ";
125         $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
126         $sSQL .= " from placex, (select geometry as placegeometry from placex where place_id = $iPlaceID) as x";
127         $sSQL .= " where linked_place_id = $iPlaceID";
128         $sSQL .= " order by rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber";
129         $aLinkedLines = $oDB->getAll($sSQL);
130
131         // All places this is an imediate parent of
132         $sSQL = "select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_distance(geometry, placegeometry) as distance, ";
133         $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
134         $sSQL .= " from placex, (select geometry as placegeometry from placex where place_id = $iPlaceID) as x";
135         $sSQL .= " where parent_place_id = $iPlaceID";
136         $sSQL .= " order by rank_address asc,rank_search asc,get_name_by_language(name,$sLanguagePrefArraySQL),housenumber";
137         $aParentOfLines = $oDB->getAll($sSQL);
138
139         $aPlaceSearchNameKeywords = false;
140         $aPlaceSearchAddressKeywords = false;
141         if (isset($_GET['keywords']) && $_GET['keywords'])
142         {
143                 $sSQL = "select * from search_name where place_id = $iPlaceID";
144                 $aPlaceSearchName = $oDB->getRow($sSQL);
145                 $sSQL = "select * from word where word_id in (".substr($aPlaceSearchName['name_vector'],1,-1).")";
146                 $aPlaceSearchNameKeywords = $oDB->getAll($sSQL);
147                 $sSQL = "select * from word where word_id in (".substr($aPlaceSearchName['nameaddress_vector'],1,-1).")";
148                 $aPlaceSearchAddressKeywords = $oDB->getAll($sSQL);
149         }
150
151         logEnd($oDB, $hLog, 1);
152
153         include(CONST_BasePath.'/lib/template/details-'.$sOutputFormat.'.php');