2 @define('CONST_ConnectionBucket_PageType', 'Details');
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/output.php');
8 ini_set('memory_limit', '200M');
10 $oParams = new Nominatim\ParameterParser();
12 $sOutputFormat = 'html';
13 $aLangPrefOrder = $oParams->getPreferredLanguages();
14 $sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $aLangPrefOrder))."]";
16 $sPlaceId = $oParams->getString('place_id');
17 $sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R'));
18 $iOsmId = $oParams->getInt('osmid', -1);
22 if ($sOsmType && $iOsmId > 0) {
24 "SELECT place_id FROM placex WHERE osm_type='%s' AND osm_id=%d ORDER BY type='postcode' ASC",
28 $sPlaceId = chksql($oDB->getOne($sSQL));
30 // Be nice about our error messages for broken geometry
34 $sSQL .= " osm_type, ";
36 $sSQL .= " errormessage, ";
39 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname,";
40 $sSQL .= " ST_AsText(prevgeometry) AS prevgeom, ";
41 $sSQL .= " ST_AsText(newgeometry) AS newgeom";
42 $sSQL .= " FROM import_polygon_error ";
43 $sSQL .= " WHERE osm_type = '".$sOsmType."'";
44 $sSQL .= " AND osm_id = ".$iOsmId;
45 $sSQL .= " ORDER BY updated DESC";
47 $aPointDetails = chksql($oDB->getRow($sSQL));
48 if (!PEAR::isError($aPointDetails) && $aPointDetails) {
49 if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) {
50 $aPointDetails['error_x'] = $aMatches[1];
51 $aPointDetails['error_y'] = $aMatches[2];
53 $aPointDetails['error_x'] = 0;
54 $aPointDetails['error_y'] = 0;
56 include(CONST_BasePath.'/lib/template/details-error-'.$sOutputFormat.'.php');
63 if (!$sPlaceId) userError("Please select a place id");
65 $iPlaceID = (int)$sPlaceId;
67 if (CONST_Use_US_Tiger_Data) {
68 $iParentPlaceID = chksql($oDB->getOne('SELECT parent_place_id FROM location_property_tiger WHERE place_id = '.$iPlaceID));
69 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
72 // interpolated house numbers
73 $iParentPlaceID = chksql($oDB->getOne('SELECT parent_place_id FROM location_property_osmline WHERE place_id = '.$iPlaceID));
74 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
77 if (CONST_Use_Aux_Location_data) {
78 $iParentPlaceID = chksql($oDB->getOne('SELECT parent_place_id FROM location_property_aux WHERE place_id = '.$iPlaceID));
79 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
82 $hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
84 // Get the details for this point
85 $sSQL = "SELECT place_id, osm_type, osm_id, class, type, name, admin_level,";
86 $sSQL .= " housenumber, street, isin, postcode, calculated_country_code AS country_code,";
87 $sSQL .= " importance, wikipedia,";
88 $sSQL .= " to_char(indexed_date, 'YYYY-MM-DD HH24:MI') AS indexed_date,";
89 $sSQL .= " parent_place_id, ";
90 $sSQL .= " rank_address, ";
91 $sSQL .= " rank_search, ";
92 $sSQL .= " get_searchrank_label(rank_search) AS rank_search_label,";
93 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, ";
94 $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea, ";
95 //$sSQL .= " ST_Area(geometry::geography) AS area, ";
96 $sSQL .= " ST_y(centroid) AS lat, ";
97 $sSQL .= " ST_x(centroid) AS lon,";
99 $sSQL .= " WHEN importance = 0 OR importance IS NULL THEN 0.75-(rank_search::float/40) ";
100 $sSQL .= " ELSE importance ";
101 $sSQL .= " END as calculated_importance, ";
102 $sSQL .= " ST_AsGeoJSON(CASE ";
103 $sSQL .= " WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) ";
104 $sSQL .= " ELSE geometry ";
105 $sSQL .= " END) as asgeojson";
106 $sSQL .= " FROM placex ";
107 $sSQL .= " WHERE place_id = $iPlaceID";
109 $aPointDetails = chksql($oDB->getRow($sSQL), "Could not get details of place object.");
111 if (!$aPointDetails) {
112 userError("Unknown place id.");
115 $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber'];
117 $aClassType = getClassTypesWithImportance();
119 $sPointClassType = $aPointDetails['class'].':'.$aPointDetails['type'];
120 if (isset($aClassType[$sPointClassType]) && $aClassType[$sPointClassType]['icon']) {
121 $aPointDetails['icon'] = $aClassType[$sPointClassType]['icon'];
123 $aPointDetails['icon'] = false;
126 // Get all alternative names (languages, etc)
127 $sSQL = "SELECT (each(name)).key,(each(name)).value FROM placex WHERE place_id = $iPlaceID ORDER BY (each(name)).key";
128 $aPointDetails['aNames'] = $oDB->getAssoc($sSQL);
129 if (PEAR::isError($aPointDetails['aNames'])) { // possible timeout
130 $aPointDetails['aNames'] = [];
134 $sSQL = "SELECT (each(extratags)).key,(each(extratags)).value FROM placex WHERE place_id = $iPlaceID ORDER BY (each(extratags)).key";
135 $aPointDetails['aExtraTags'] = $oDB->getAssoc($sSQL);
136 if (PEAR::isError($aPointDetails['aExtraTags'])) { // possible timeout
137 $aPointDetails['aExtraTags'] = [];
141 $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], -1, true);
144 $sSQL = "SELECT placex.place_id, osm_type, osm_id, class, type, housenumber,";
145 $sSQL .= " admin_level, rank_address, ";
146 $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,";
147 $sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, ";
148 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, ";
149 $sSQL .= " length(name::text) AS namelength ";
151 $sSQL .= " placex, ";
153 $sSQL .= " SELECT centroid AS placegeometry ";
154 $sSQL .= " FROM placex ";
155 $sSQL .= " WHERE place_id = $iPlaceID ";
157 $sSQL .= " WHERE linked_place_id = $iPlaceID";
158 $sSQL .= " ORDER BY ";
159 $sSQL .= " rank_address ASC, ";
160 $sSQL .= " rank_search ASC, ";
161 $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL), ";
162 $sSQL .= " housenumber";
163 $aLinkedLines = $oDB->getAll($sSQL);
164 if (PEAR::isError($aLinkedLines)) { // possible timeout
168 // All places this is an imediate parent of
169 $sSQL = "SELECT obj.place_id, osm_type, osm_id, class, type, housenumber,";
170 $sSQL .= " admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,";
171 $sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, ";
172 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, ";
173 $sSQL .= " length(name::text) AS namelength ";
176 $sSQL .= " SELECT placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name ";
177 $sSQL .= " FROM placex ";
178 $sSQL .= " WHERE parent_place_id = $iPlaceID ";
179 $sSQL .= " ORDER BY ";
180 $sSQL .= " rank_address ASC, ";
181 $sSQL .= " rank_search ASC ";
182 $sSQL .= " LIMIT 500 ";
183 $sSQL .= " ) AS obj,";
185 $sSQL .= " SELECT centroid AS placegeometry ";
186 $sSQL .= " FROM placex ";
187 $sSQL .= " WHERE place_id = $iPlaceID ";
189 $sSQL .= " ORDER BY ";
190 $sSQL .= " rank_address ASC, ";
191 $sSQL .= " rank_search ASC, ";
192 $sSQL .= " localname, ";
193 $sSQL .= " housenumber";
194 $aParentOfLines = $oDB->getAll($sSQL);
195 if (PEAR::isError($aParentOfLines)) { // possible timeout
196 $aParentOfLines = [];
199 $aPlaceSearchNameKeywords = false;
200 $aPlaceSearchAddressKeywords = false;
201 if ($oParams->getBool('keywords')) {
202 $sSQL = "SELECT * FROM search_name WHERE place_id = $iPlaceID";
203 $aPlaceSearchName = $oDB->getRow($sSQL);
204 if (PEAR::isError($aPlaceSearchName)) { // possible timeout
205 $aPlaceSearchName = [];
208 $sSQL = "SELECT * FROM word WHERE word_id in (".substr($aPlaceSearchName['name_vector'], 1, -1).")";
209 $aPlaceSearchNameKeywords = $oDB->getAll($sSQL);
210 if (PEAR::isError($aPlaceSearchNameKeywords)) { // possible timeout
211 $aPlaceSearchNameKeywords = [];
214 $sSQL = "SELECT * FROM word WHERE word_id in (".substr($aPlaceSearchName['nameaddress_vector'], 1, -1).")";
215 $aPlaceSearchAddressKeywords = $oDB->getAll($sSQL);
216 if (PEAR::isError($aPlaceSearchAddressKeywords)) { // possible timeout
217 $aPlaceSearchAddressKeywords = [];
221 logEnd($oDB, $hLog, 1);
223 if ($sOutputFormat=='html') {
224 $sSQL = "SELECT TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' FROM import_status LIMIT 1";
225 $sDataDate = chksql($oDB->getOne($sSQL));
226 $sTileURL = CONST_Map_Tile_URL;
227 $sTileAttribution = CONST_Map_Tile_Attribution;
230 include(CONST_BasePath.'/lib/template/details-'.$sOutputFormat.'.php');