From 93ddd4623133f1f7b721ea432873865d6e79ddc9 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Fri, 10 Apr 2020 03:21:52 +0200 Subject: [PATCH] Add JSON output for /deletable.php and /polygons.php --- lib/template/deletable-html.php | 48 ++++++++++++++ lib/template/polygons-html.php | 71 +++++++++++++++++++++ website/deletable.php | 90 +++----------------------- website/polygons.php | 108 ++++---------------------------- 4 files changed, 138 insertions(+), 179 deletions(-) create mode 100644 lib/template/deletable-html.php create mode 100644 lib/template/polygons-html.php diff --git a/lib/template/deletable-html.php b/lib/template/deletable-html.php new file mode 100644 index 00000000..8cc53e84 --- /dev/null +++ b/lib/template/deletable-html.php @@ -0,0 +1,48 @@ + + Nominatim Deleted Data + + + + +
+

Deletable

+

+ objects have been deleted in OSM but are still in the Nominatim database. + Also available in JSON format. +

+ + +'; + foreach (array_keys($aPolygons[0]) as $sCol) { + echo ''; + } + echo ''; + foreach ($aPolygons as $aRow) { + echo ''; + foreach ($aRow as $sCol => $sVal) { + switch ($sCol) { + case 'osm_id': + echo ''; + break; + case 'place_id': + echo ''; + break; + default: + echo ''; + break; + } + } + echo ''; + } +} +?> +
'.$sCol.'
'.osmLink($aRow).''.detailsLink($aRow).''.($sVal?$sVal:' ').'
+
+ + diff --git a/lib/template/polygons-html.php b/lib/template/polygons-html.php new file mode 100644 index 00000000..7d485d9c --- /dev/null +++ b/lib/template/polygons-html.php @@ -0,0 +1,71 @@ + + Nominatim Broken Polygon Data + + + + + +
+

Broken polygons

+ +

+ Total number of broken polygons: . + Also available in JSON format. +

+ + + +'; + //var_dump($aPolygons[0]); + foreach (array_keys($aPolygons[0]) as $sCol) { + echo ''; + } + echo ''; + echo ''; + $aSeen = array(); + foreach ($aPolygons as $aRow) { + if (isset($aSeen[$aRow['osm_type'].$aRow['osm_id']])) continue; + $aSeen[$aRow['osm_type'].$aRow['osm_id']] = 1; + + echo ''; + $sOSMType = formatOSMType($aRow['osm_type']); + foreach ($aRow as $sCol => $sVal) { + switch ($sCol) { + case 'errormessage': + if (preg_match('/Self-intersection\\[([0-9.\\-]+) ([0-9.\\-]+)\\]/', $sVal, $aMatch)) { + $aRow['lat'] = $aMatch[2]; + $aRow['lon'] = $aMatch[1]; + $sUrl = sprintf('https://www.openstreetmap.org/?lat=%f&lon=%f&zoom=18&layers=M&%s=%d', + $aRow['lat'], + $aRow['lon'], + $sOSMType, + $aRow['osm_id']); + echo ''; + } else { + echo ''; + } + break; + case 'osm_id': + echo ''; + break; + default: + echo ''; + break; + } + } + $sJosmUrl = 'http://localhost:8111/import?url=https://www.openstreetmap.org/api/0.6/'.$sOSMType.'/'.$aRow['osm_id'].'/full'; + echo ''; + echo ''; + } + echo '
'.$sCol.' 
'.($sVal?$sVal:' ').''.($sVal?$sVal:' ').''.osmLink(array('osm_type' => $aRow['osm_type'], 'osm_id' => $aRow['osm_id'])).''.($sVal?$sVal:' ').'josm
'; +} +?> +
+ + \ No newline at end of file diff --git a/website/deletable.php b/website/deletable.php index ac4294ba..2d7ee7e9 100644 --- a/website/deletable.php +++ b/website/deletable.php @@ -5,7 +5,9 @@ require_once(CONST_BasePath.'/lib/log.php'); require_once(CONST_BasePath.'/lib/output.php'); ini_set('memory_limit', '200M'); -$sOutputFormat = 'html'; +$oParams = new Nominatim\ParameterParser(); +$sOutputFormat = $oParams->getSet('format', array('html', 'json'), 'html'); +set_exception_handler_by_format($sOutputFormat); $oDB = new Nominatim\DB(); $oDB->connect(); @@ -21,86 +23,8 @@ if (CONST_Debug) { exit; } -?> - - - - - - - Nominatim Deleted Data - - - - - - - - -

Objects in this table have been deleted in OSM but are still in the Nominatim database.

- - -'; -// var_dump($aPolygons[0]); -foreach ($aPolygons[0] as $sCol => $sVal) { - echo ''; +if ($sOutputFormat == 'json') { + echo javascript_renderData($aPolygons); +} else { + include(CONST_BasePath.'/lib/template/deletable-html.php'); } -echo ''; -foreach ($aPolygons as $aRow) { - echo ''; - foreach ($aRow as $sCol => $sVal) { - switch ($sCol) { - case 'osm_id': - echo ''; - break; - case 'place_id': - echo ''; - break; - default: - echo ''; - break; - } - } - echo ''; -} - -?> -
'.$sCol.'
'.osmLink($aRow).''.detailsLink($aRow).''.($sVal?$sVal:' ').'
- - - - - diff --git a/website/polygons.php b/website/polygons.php index 29fc5c27..c5fbafc2 100644 --- a/website/polygons.php +++ b/website/polygons.php @@ -6,8 +6,9 @@ require_once(CONST_BasePath.'/lib/output.php'); ini_set('memory_limit', '200M'); $oParams = new Nominatim\ParameterParser(); +$sOutputFormat = $oParams->getSet('format', array('html', 'json'), 'html'); +set_exception_handler_by_format($sOutputFormat); -$sOutputFormat = 'html'; $iDays = $oParams->getInt('days', false); $bReduced = $oParams->getBool('reduced', false); $sClass = $oParams->getString('class', false); @@ -15,13 +16,13 @@ $sClass = $oParams->getString('class', false); $oDB = new Nominatim\DB(); $oDB->connect(); -$iTotalBroken = (int) $oDB->getOne('select count(*) from import_polygon_error'); +$iTotalBroken = (int) $oDB->getOne('SELECT count(*) FROM import_polygon_error'); $aPolygons = array(); while ($iTotalBroken && empty($aPolygons)) { - $sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",'; - $sSQL .= 'country_code as "country",errormessage as "error message",updated'; - $sSQL .= ' from import_polygon_error'; + $sSQL = 'SELECT osm_type, osm_id, class, type, name->\'name\' as "name",'; + $sSQL .= 'country_code, errormessage, updated'; + $sSQL .= ' FROM import_polygon_error'; $aWhere = array(); if ($iDays) { @@ -33,10 +34,10 @@ while ($iTotalBroken && empty($aPolygons)) { if ($sClass) $sWhere[] = "class = '".pg_escape_string($sClass)."'"; if (!empty($aWhere)) { - $sSQL .= ' where '.join(' and ', $aWhere); + $sSQL .= ' WHERE '.join(' and ', $aWhere); } - $sSQL .= ' order by updated desc limit 1000'; + $sSQL .= ' ORDER BY updated desc LIMIT 1000'; $aPolygons = $oDB->getAll($sSQL); } @@ -45,93 +46,8 @@ if (CONST_Debug) { exit; } -?> - - - - - - - Nominatim Broken Polygon Data - - - - - - - - -Total number of broken polygons: $iTotalBroken

"; -if (!$aPolygons) exit; -echo ''; -echo ''; -//var_dump($aPolygons[0]); -foreach ($aPolygons[0] as $sCol => $sVal) { - echo ''; -} -echo ''; -echo ''; -$aSeen = array(); -foreach ($aPolygons as $aRow) { - if (isset($aSeen[$aRow['type'].$aRow['id']])) continue; - $aSeen[$aRow['type'].$aRow['id']] = 1; - echo ''; - foreach ($aRow as $sCol => $sVal) { - switch ($sCol) { - case 'error message': - if (preg_match('/Self-intersection\\[([0-9.\\-]+) ([0-9.\\-]+)\\]/', $sVal, $aMatch)) { - $aRow['lat'] = $aMatch[2]; - $aRow['lon'] = $aMatch[1]; - echo ''; - } else { - echo ''; - } - break; - case 'id': - echo ''; - break; - default: - echo ''; - break; - } - } - echo ''; - echo ''; -} -echo '
'.$sCol.' 
'.($sVal?$sVal:' ').''.($sVal?$sVal:' ').''.osmLink(array('osm_type' => $aRow['type'], 'osm_id' => $aRow['id'])).''.($sVal?$sVal:' ').'josm
'; - -?> - - -- 2.39.5