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/PlaceLookup.php');
9 $sOutputFormat = 'html';
10 if (isset($_GET['format']) && ($_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
12 $sOutputFormat = $_GET['format'];
15 ini_set('memory_limit', '200M');
19 $aLangPrefOrder = getPreferredLanguages();
20 $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$aLangPrefOrder))."]";
22 if (isset($_GET['osmtype']) && isset($_GET['osmid']) && (int)$_GET['osmid'] && ($_GET['osmtype'] == 'N' || $_GET['osmtype'] == 'W' || $_GET['osmtype'] == 'R'))
24 $_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");
26 // Be nice about our error messages for broken geometry
27 if (!$_GET['place_id'])
29 $aPointDetails = $oDB->getRow("select osm_type, osm_id, errormessage, class, type, get_name_by_language(name,$sLanguagePrefArraySQL) as localname, ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom from import_polygon_error where osm_type = '".$_GET['osmtype']."' and osm_id = ".(int)$_GET['osmid']." order by updated desc limit 1");
30 if (!PEAR::isError($aPointDetails) && $aPointDetails) {
31 if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches))
33 $aPointDetails['error_x'] = $aMatches[1];
34 $aPointDetails['error_y'] = $aMatches[2];
36 include(CONST_BasePath.'/lib/template/details-error-'.$sOutputFormat.'.php');
42 if (!isset($_GET['place_id']))
44 echo "Please select a place id";
48 $iPlaceID = (int)$_GET['place_id'];
50 if (CONST_Use_US_Tiger_Data)
52 $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_tiger where place_id = '.$iPlaceID);
53 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
56 if (CONST_Use_Aux_Location_data)
58 $iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_aux where place_id = '.$iPlaceID);
59 if ($iParentPlaceID) $iPlaceID = $iParentPlaceID;
62 $oPlaceLookup = new PlaceLookup($oDB);
63 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
64 $oPlaceLookup->setIncludeAddressDetails(true);
65 $oPlaceLookup->setPlaceId($iPlaceID);
67 $aPlaceAddress = array_reverse($oPlaceLookup->getAddressDetails());
69 if (!sizeof($aPlaceAddress))
71 echo "Unknown place id.";
75 $aBreadcrums = array();
76 foreach($aPlaceAddress as $i => $aPlace)
78 if (!$aPlace['place_id']) continue;
79 $aBreadcrums[] = array('placeId'=>$aPlace['place_id'], 'osmType'=>$aPlace['osm_type'], 'osmId'=>$aPlace['osm_id'], 'localName'=>$aPlace['localname']);
80 $sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id'];
81 $sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation':'')));
82 $sOSMUrl = 'http://www.openstreetmap.org/browse/'.$sOSMType.'/'.$aPlace['osm_id'];
83 if ($sOutputFormat == 'html') if ($i) echo " > ";
84 if ($sOutputFormat == 'html') echo '<a href="'.$sPlaceUrl.'">'.$aPlace['localname'].'</a> (<a href="'.$sOSMUrl.'">osm</a>)';
88 $aDetails['breadcrumbs'] = $aBreadcrums;
90 if ($sOutputFormat == 'json')
92 header("content-type: application/json; charset=UTF-8");
93 javascript_renderData($aDetails);
97 $aRelatedPlaceIDs = $oDB->getCol($sSQL = "select place_id from placex where linked_place_id = $iPlaceID or place_id = $iPlaceID");
99 $sSQL = "select obj.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_area(geometry) as area, ";
100 $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength ";
101 $sSQL .= " from (select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name from placex ";
102 $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";
103 $sSQL .= " order by rank_address asc,rank_search asc,localname,class, type,housenumber";
104 $aParentOfLines = $oDB->getAll($sSQL);
106 if (sizeof($aParentOfLines))
108 echo '<h2>Parent Of:</h2>';
109 $aClassType = getClassTypesWithImportance();
110 $aGroupedAddressLines = array();
111 foreach($aParentOfLines as $aAddressLine)
113 if (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'])
114 && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'])
116 $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type'].':'.$aAddressLine['admin_level']]['label'];
118 elseif (isset($aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'])
119 && $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'])
121 $aAddressLine['label'] = $aClassType[$aAddressLine['class'].':'.$aAddressLine['type']]['label'];
123 else $aAddressLine['label'] = ucwords($aAddressLine['type']);
125 if (!isset($aGroupedAddressLines[$aAddressLine['label']])) $aGroupedAddressLines[$aAddressLine['label']] = array();
126 $aGroupedAddressLines[$aAddressLine['label']][] = $aAddressLine;
128 foreach($aGroupedAddressLines as $sGroupHeading => $aParentOfLines)
130 echo "<h3>$sGroupHeading</h3>";
131 foreach($aParentOfLines as $aAddressLine)
133 $aAddressLine['localname'] = $aAddressLine['localname']?$aAddressLine['localname']:$aAddressLine['housenumber'];
134 $sOSMType = ($aAddressLine['osm_type'] == 'N'?'node':($aAddressLine['osm_type'] == 'W'?'way':($aAddressLine['osm_type'] == 'R'?'relation':'')));
136 echo '<div class="line">';
137 echo '<span class="name">'.(trim($aAddressLine['localname'])?$aAddressLine['localname']:'<span class="noname">No Name</span>').'</span>';
139 echo '<span class="area">'.($aAddressLine['isarea']=='t'?'Polygon':'Point').'</span>';
140 if ($sOSMType) echo ', <span class="osm"><span class="label"></span>'.$sOSMType.' <a href="http://www.openstreetmap.org/browse/'.$sOSMType.'/'.$aAddressLine['osm_id'].'">'.$aAddressLine['osm_id'].'</a></span>';
141 echo ', <a href="hierarchy.php?place_id='.$aAddressLine['place_id'].'">GOTO</a>';
142 echo ', '.$aAddressLine['area'];
147 if (sizeof($aParentOfLines) >= 500) {
148 echo '<p>There are more child objects which are not shown.</p>';