3 require_once(CONST_BasePath.'/lib/init-website.php');
4 require_once(CONST_BasePath.'/lib/log.php');
5 require_once(CONST_BasePath.'/lib/AddressDetails.php');
6 require_once(CONST_BasePath.'/lib/output.php');
7 ini_set('memory_limit', '200M');
9 $oParams = new Nominatim\ParameterParser();
11 $sOutputFormat = $oParams->getSet('format', array('html', 'json'), 'html');
12 $aLangPrefOrder = $oParams->getPreferredLanguages();
15 $sPlaceId = $oParams->getString('place_id');
16 $sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R'));
17 $iOsmId = $oParams->getInt('osmid', -1);
19 $oDB = new Nominatim\DB();
22 $sLanguagePrefArraySQL = $oDB->getArraySQL($oDB->getDBQuotedList($aLangPrefOrder));
24 if ($sOsmType && $iOsmId > 0) {
25 $sPlaceId = $oDB->getOne("select place_id from placex where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by type = 'postcode' asc");
27 // Be nice about our error messages for broken geometry
29 $sSQL = 'select osm_type, osm_id, errormessage, class, type,';
30 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname,";
31 $sSQL .= ' ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom';
32 $sSQL .= " from import_polygon_error where osm_type = '".$sOsmType;
33 $sSQL .= "' and osm_id = ".$iOsmId.' order by updated desc limit 1';
34 $aPointDetails = $oDB->getRow($sSQL);
36 if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) {
37 $aPointDetails['error_x'] = $aMatches[1];
38 $aPointDetails['error_y'] = $aMatches[2];
40 include(CONST_BasePath.'/lib/template/details-error-'.$sOutputFormat.'.php');
46 if (!$sPlaceId) userError('Please select a place id');
48 $iPlaceID = (int)$sPlaceId;
50 if (CONST_Use_US_Tiger_Data) {
51 $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID);
52 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
55 if (CONST_Use_Aux_Location_data) {
56 $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID);
57 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
61 $oAddressLookup = new AddressDetails($oDB, $iPlaceID, -1, $aLangPrefOrder);
62 $aPlaceAddress = array_reverse($oAddressLookup->getAddressDetails());
64 if (empty($aPlaceAddress)) userError('Unknown place id.');
66 $aBreadcrums = array();
67 foreach ($aPlaceAddress as $i => $aPlace) {
68 if (!$aPlace['place_id']) continue;
69 $aBreadcrums[] = array(
70 'placeId' => $aPlace['place_id'],
71 'osmType' => $aPlace['osm_type'],
72 'osmId' => $aPlace['osm_id'],
73 'localName' => $aPlace['localname']
76 if ($sOutputFormat == 'html') {
77 $sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id'];
78 if ($i) echo ' > ';
79 echo '<a href="'.$sPlaceUrl.'">'.$aPlace['localname'].'</a> ('.osmLink($aPlace).')';
84 if ($sOutputFormat == 'json') {
85 header('content-type: application/json; charset=UTF-8');
87 $aDetails['breadcrumbs'] = $aBreadcrums;
88 javascript_renderData($aDetails);
92 $aRelatedPlaceIDs = $oDB->getCol("select place_id from placex where linked_place_id = $iPlaceID or place_id = $iPlaceID");
94 $sSQL = 'select obj.place_id, osm_type, osm_id, class, type, housenumber, admin_level,';
95 $sSQL .= " rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_area(geometry) as area, ";
96 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
97 $sSQL .= ' from (select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name from placex ';
98 $sSQL .= ' where parent_place_id in ('.join(',', $aRelatedPlaceIDs).') and name is not null order by rank_address asc,rank_search asc limit 500) as obj';
99 $sSQL .= ' order by rank_address asc,rank_search asc,localname,class, type,housenumber';
100 $aParentOfLines = $oDB->getAll($sSQL);
102 if (!empty($aParentOfLines)) {
103 echo '<h2>Parent Of:</h2>';
104 $aGroupedAddressLines = array();
105 foreach ($aParentOfLines as $aAddressLine) {
106 $aAddressLine['label'] = Nominatim\ClassTypes\getProperty($aAddressLine, 'label');
107 if (!$aAddressLine['label']) {
108 $aAddressLine['label'] = ucwords($aAddressLine['type']);
111 if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array();
112 $aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine;
115 foreach ($aGroupedAddressLines as $sGroupHeading => $aParentOfLines) {
116 echo "<h3>$sGroupHeading</h3>";
117 foreach ($aParentOfLines as $aAddressLine) {
118 $aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber'];
119 $sOSMType = formatOSMType($aAddressLine['osm_type'], false);
121 echo '<div class="line">';
122 echo '<span class="name">'.(trim($aAddressLine['localname'])?$aAddressLine['localname']:'<span class="noname">No Name</span>').'</span>';
124 echo '<span class="area">'.($aAddressLine['isarea']?'Polygon':'Point').'</span>';
125 if ($sOSMType) echo ', <span class="osm"><span class="label"></span>'.$sOSMType.' '.osmLink($aAddressLine).'</span>';
126 echo ', <a href="hierarchy.php?place_id='.$aAddressLine['place_id'].'">GOTO</a>';
127 echo ', '.$aAddressLine['area'];
132 if (count($aParentOfLines) >= 500) {
133 echo '<p>There are more child objects which are not shown.</p>';