2 require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
3 require_once(CONST_BasePath.'/lib/log.php');
5 $fLoadAvg = getLoadAverage();
8 echo "Page temporarily blocked due to high server load\n";
12 ini_set('memory_limit', '200M');
16 if (isset($_GET['osmtype']) && isset($_GET['osmid']) && (int)$_GET['osmid'] && ($_GET['osmtype'] == 'N' || $_GET['osmtype'] == 'W' || $_GET['osmtype'] == 'R'))
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");
21 if (!isset($_GET['place_id']))
23 echo "Please select a place id";
27 $iPlaceID = (int)$_GET['place_id'];
29 $aLangPrefOrder = getPrefferedLangauges();
30 $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
32 $hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
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";
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))
46 var_dump($aPointDetails);
49 $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber'];
50 $fLon = $aPointDetails['lon'];
51 $fLat = $aPointDetails['lat'];
54 $aClassType = getClassTypesWithImportance();
55 $aPointDetails['icon'] = $aClassType[$aPointDetails['class'].':'.$aPointDetails['type']]['icon'];
57 // Get all alternative names (languages, etc)
58 $aPointDetails['aNames'] = array();
60 for($i = 1; $i <= $aPointDetails['numnames']; $i++)
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'];
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))
73 var_dump($aPointPolygon);
76 if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch))
78 preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
80 elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['outlinestring'],$aMatch))
83 $iSteps = ($fRadius * 40000)^2;
84 $fStepSize = (2*pi())/$iSteps;
85 $aPolyPoints = array();
86 for($f = 0; $f < 2*pi(); $f += $fStepSize)
89 $aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
91 $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
92 $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
93 $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
94 $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
97 // If it is a road then force all nearby buildings to be indexed (so we can show then in the list)
99 if ($aPointDetails['rank_address'] == 26)
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";
107 $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], true);
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'])
116 $sSQL .= " and (placex.country_code IS NULL OR placex.country_code = '".$aPointDetails['country_code']."' OR rank_address < 4)";
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))
122 var_dump($aAddressLines);
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);
136 logEnd($oDB, $hLog, 1);
138 include('.htlib/output/details-html.php');