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();
13 $sLanguagePrefArraySQL = 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
15 $sPlaceId = $oParams->getString('place_id');
16 $sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R'));
17 $iOsmId = $oParams->getInt('osmid', -1);
21 if ($sOsmType && $iOsmId > 0) {
22 $sPlaceId = chksql($oDB->getOne("select place_id from placex where osm_type = '".$sOsmType."' and osm_id = ".$iOsmId." order by type = 'postcode' asc"));
24 // Be nice about our error messages for broken geometry
26 $sSQL = 'select osm_type, osm_id, errormessage, class, type,';
27 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname,";
28 $sSQL .= ' ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom';
29 $sSQL .= " from import_polygon_error where osm_type = '".$sOsmType;
30 $sSQL .= "' and osm_id = ".$iOsmId.' order by updated desc limit 1';
31 $aPointDetails = chksql($oDB->getRow($sSQL));
33 if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) {
34 $aPointDetails['error_x'] = $aMatches[1];
35 $aPointDetails['error_y'] = $aMatches[2];
37 include(CONST_BasePath.'/lib/template/details-error-'.$sOutputFormat.'.php');
43 if (!$sPlaceId) userError('Please select a place id');
45 $iPlaceID = (int)$sPlaceId;
47 if (CONST_Use_US_Tiger_Data) {
48 $iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID));
49 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
52 if (CONST_Use_Aux_Location_data) {
53 $iParentPlaceID = chksql($oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID));
54 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
58 $oAddressLookup = new AddressDetails($oDB, $iPlaceID, -1, $aLangPrefOrder);
59 $aPlaceAddress = array_reverse($oAddressLookup->getAddressDetails());
61 if (empty($aPlaceAddress)) userError('Unknown place id.');
63 $aBreadcrums = array();
64 foreach ($aPlaceAddress as $i => $aPlace) {
65 if (!$aPlace['place_id']) continue;
66 $aBreadcrums[] = array(
67 'placeId' => $aPlace['place_id'],
68 'osmType' => $aPlace['osm_type'],
69 'osmId' => $aPlace['osm_id'],
70 'localName' => $aPlace['localname']
73 if ($sOutputFormat == 'html') {
74 $sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id'];
75 if ($i) echo ' > ';
76 echo '<a href="'.$sPlaceUrl.'">'.$aPlace['localname'].'</a> ('.osmLink($aPlace).')';
81 if ($sOutputFormat == 'json') {
82 header('content-type: application/json; charset=UTF-8');
84 $aDetails['breadcrumbs'] = $aBreadcrums;
85 javascript_renderData($aDetails);
89 $aRelatedPlaceIDs = chksql($oDB->getCol($sSQL = "select place_id from placex where linked_place_id = $iPlaceID or place_id = $iPlaceID"));
91 $sSQL = 'select obj.place_id, osm_type, osm_id, class, type, housenumber, admin_level,';
92 $sSQL .= " rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_area(geometry) as area, ";
93 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
94 $sSQL .= ' from (select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name from placex ';
95 $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';
96 $sSQL .= ' order by rank_address asc,rank_search asc,localname,class, type,housenumber';
97 $aParentOfLines = chksql($oDB->getAll($sSQL));
99 if (!empty($aParentOfLines)) {
100 echo '<h2>Parent Of:</h2>';
101 $aGroupedAddressLines = array();
102 foreach ($aParentOfLines as $aAddressLine) {
103 $aAddressLine['label'] = Nominatim\ClassTypes\getProperty($aAddressLine, 'label');
104 if (!$aAddressLine['label']) {
105 $aAddressLine['label'] = ucwords($aAddressLine['type']);
108 if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array();
109 $aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine;
112 foreach ($aGroupedAddressLines as $sGroupHeading => $aParentOfLines) {
113 echo "<h3>$sGroupHeading</h3>";
114 foreach ($aParentOfLines as $aAddressLine) {
115 $aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber'];
116 $sOSMType = formatOSMType($aAddressLine['osm_type'], false);
118 echo '<div class="line">';
119 echo '<span class="name">'.(trim($aAddressLine['localname'])?$aAddressLine['localname']:'<span class="noname">No Name</span>').'</span>';
121 echo '<span class="area">'.($aAddressLine['isarea']=='t'?'Polygon':'Point').'</span>';
122 if ($sOSMType) echo ', <span class="osm"><span class="label"></span>'.$sOSMType.' '.osmLink($aAddressLine).'</span>';
123 echo ', <a href="hierarchy.php?place_id='.$aAddressLine['place_id'].'">GOTO</a>';
124 echo ', '.$aAddressLine['area'];
129 if (count($aParentOfLines) >= 500) {
130 echo '<p>There are more child objects which are not shown.</p>';