From: Marc Tobias Metten Date: Fri, 9 Mar 2018 01:27:24 +0000 (+0100) Subject: details support json output X-Git-Tag: v3.2.0~91 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/1e28f2478c6b4c3ba7ca566e4a43a7f5c293ce3c?ds=sidebyside details support json output --- diff --git a/lib/template/details-json.php b/lib/template/details-json.php new file mode 100644 index 00000000..2464bc34 --- /dev/null +++ b/lib/template/details-json.php @@ -0,0 +1,41 @@ +.*)"(?P with dups)?') def query_cmd(context, query, dups): """ Query directly via PHP script. @@ -379,7 +383,12 @@ def website_details_request(context, fmt, query): params['place_id'] = query outp, status = send_api_query('details', params, fmt, context) - context.response = DetailsResponse(outp, 'html', status) + if fmt is None: + outfmt = 'html' + else: + outfmt = fmt.strip() + + context.response = DetailsResponse(outp, outfmt, status) @when(u'sending (?P\S+ )?lookup query for (?P.*)') def website_lookup_request(context, fmt, query): diff --git a/website/details.php b/website/details.php index 6989d488..2e56cbd6 100755 --- a/website/details.php +++ b/website/details.php @@ -9,7 +9,8 @@ ini_set('memory_limit', '200M'); $oParams = new Nominatim\ParameterParser(); -$sOutputFormat = 'html'; +$sOutputFormat = $oParams->getSet('format', array('html', 'json'), 'html'); + $aLangPrefOrder = $oParams->getPreferredLanguages(); $sLanguagePrefArraySQL = 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']'; @@ -18,6 +19,12 @@ $sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R')); $iOsmId = $oParams->getInt('osmid', -1); $sClass = $oParams->getString('class'); + +$bIncludeAddressDetails = ($sOutputFormat == 'html') ? 1 : $oParams->getBool('addressdetails'); +$bIncludeLinkedPlaces = ($sOutputFormat == 'html') ? 1 : $oParams->getBool('linkedplaces'); +$bIncludeChildPlaces = ($sOutputFormat == 'html') ? 1 : $oParams->getBool('childplaces'); +$bGroupParents = $oParams->getBool('group_parents', 0); + $oDB =& getDB(); if ($sOsmType && $iOsmId > 0) { @@ -154,62 +161,71 @@ if (PEAR::isError($aPointDetails['aExtraTags'])) { // possible timeout } // Address -$aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], -1, true); +$aAddressLines = false; +if ($bIncludeAddressDetails) { + $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], -1, true); +} // Linked places -$sSQL = 'SELECT placex.place_id, osm_type, osm_id, class, type, housenumber,'; -$sSQL .= ' admin_level, rank_address, '; -$sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,"; -$sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, "; -$sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; -$sSQL .= ' length(name::text) AS namelength '; -$sSQL .= ' FROM '; -$sSQL .= ' placex, '; -$sSQL .= ' ( '; -$sSQL .= ' SELECT centroid AS placegeometry '; -$sSQL .= ' FROM placex '; -$sSQL .= " WHERE place_id = $iPlaceID "; -$sSQL .= ' ) AS x'; -$sSQL .= " WHERE linked_place_id = $iPlaceID"; -$sSQL .= ' ORDER BY '; -$sSQL .= ' rank_address ASC, '; -$sSQL .= ' rank_search ASC, '; -$sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL), "; -$sSQL .= ' housenumber'; -$aLinkedLines = $oDB->getAll($sSQL); -if (PEAR::isError($aLinkedLines)) { // possible timeout - $aLinkedLines = []; +$aLinkedLines = false; +if ($bIncludeLinkedPlaces) { + $sSQL = 'SELECT placex.place_id, osm_type, osm_id, class, type, housenumber,'; + $sSQL .= ' admin_level, rank_address, '; + $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,"; + $sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, "; + $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; + $sSQL .= ' length(name::text) AS namelength '; + $sSQL .= ' FROM '; + $sSQL .= ' placex, '; + $sSQL .= ' ( '; + $sSQL .= ' SELECT centroid AS placegeometry '; + $sSQL .= ' FROM placex '; + $sSQL .= " WHERE place_id = $iPlaceID "; + $sSQL .= ' ) AS x'; + $sSQL .= " WHERE linked_place_id = $iPlaceID"; + $sSQL .= ' ORDER BY '; + $sSQL .= ' rank_address ASC, '; + $sSQL .= ' rank_search ASC, '; + $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL), "; + $sSQL .= ' housenumber'; + $aLinkedLines = $oDB->getAll($sSQL); + if (PEAR::isError($aLinkedLines)) { // possible timeout + $aLinkedLines = []; + } } // All places this is an imediate parent of -$sSQL = 'SELECT obj.place_id, osm_type, osm_id, class, type, housenumber,'; -$sSQL .= " admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,"; -$sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, "; -$sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; -$sSQL .= ' length(name::text) AS namelength '; -$sSQL .= ' FROM '; -$sSQL .= ' ( '; -$sSQL .= ' SELECT placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name '; -$sSQL .= ' FROM placex '; -$sSQL .= " WHERE parent_place_id = $iPlaceID "; -$sSQL .= ' ORDER BY '; -$sSQL .= ' rank_address ASC, '; -$sSQL .= ' rank_search ASC '; -$sSQL .= ' LIMIT 500 '; -$sSQL .= ' ) AS obj,'; -$sSQL .= ' ( '; -$sSQL .= ' SELECT centroid AS placegeometry '; -$sSQL .= ' FROM placex '; -$sSQL .= " WHERE place_id = $iPlaceID "; -$sSQL .= ' ) AS x'; -$sSQL .= ' ORDER BY '; -$sSQL .= ' rank_address ASC, '; -$sSQL .= ' rank_search ASC, '; -$sSQL .= ' localname, '; -$sSQL .= ' housenumber'; -$aParentOfLines = $oDB->getAll($sSQL); -if (PEAR::isError($aParentOfLines)) { // possible timeout - $aParentOfLines = []; +$aParentOfLines = false; +if ($bIncludeChildPlaces) { + $sSQL = 'SELECT obj.place_id, osm_type, osm_id, class, type, housenumber,'; + $sSQL .= " admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,"; + $sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, "; + $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; + $sSQL .= ' length(name::text) AS namelength '; + $sSQL .= ' FROM '; + $sSQL .= ' ( '; + $sSQL .= ' SELECT placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name '; + $sSQL .= ' FROM placex '; + $sSQL .= " WHERE parent_place_id = $iPlaceID "; + $sSQL .= ' ORDER BY '; + $sSQL .= ' rank_address ASC, '; + $sSQL .= ' rank_search ASC '; + $sSQL .= ' LIMIT 500 '; + $sSQL .= ' ) AS obj,'; + $sSQL .= ' ( '; + $sSQL .= ' SELECT centroid AS placegeometry '; + $sSQL .= ' FROM placex '; + $sSQL .= " WHERE place_id = $iPlaceID "; + $sSQL .= ' ) AS x'; + $sSQL .= ' ORDER BY '; + $sSQL .= ' rank_address ASC, '; + $sSQL .= ' rank_search ASC, '; + $sSQL .= ' localname, '; + $sSQL .= ' housenumber'; + $aParentOfLines = $oDB->getAll($sSQL); + if (PEAR::isError($aParentOfLines)) { // possible timeout + $aParentOfLines = []; + } } $aPlaceSearchNameKeywords = false;