]> git.openstreetmap.org Git - nominatim.git/blob - website/polygons.php
factor out parameter parsing into its own class
[nominatim.git] / website / polygons.php
1 <?php
2         require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
3         require_once(CONST_BasePath.'/lib/init-website.php');
4         require_once(CONST_BasePath.'/lib/log.php');
5         require_once(CONST_BasePath.'/lib/output.php');
6         ini_set('memory_limit', '200M');
7
8         $oParams = new ParameterParser();
9
10         $sOutputFormat = 'html';
11         $iDays = $oParams->getInt('days', 1);
12         $bReduced = $oParams->getBool('reduced', false);
13         $sClass = $oParams->getString('class', false);
14
15         $oDB =& getDB();
16
17         $iTotalBroken = (int) chksql($oDB->getOne('select count(*) from import_polygon_error'));
18
19         $aPolygons = array();
20         while($iTotalBroken && !sizeof($aPolygons))
21         {
22                 $sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",';
23                 $sSQL .= 'country_code as "country",errormessage as "error message",updated';
24                 $sSQL .= " from import_polygon_error";
25                 $sSQL .= " where updated > 'now'::timestamp - '".$iDays." day'::interval";
26                 $iDays++;
27
28                 if ($bReduced) $sSQL .= " and errormessage like 'Area reduced%'";
29                 if ($sClass) $sSQL .= " and class = '".pg_escape_string($sClass)."'";
30                 $sSQL .= " order by updated desc limit 1000";
31                 $aPolygons = chksql($oDB->getAll($sSQL));
32         }
33
34         if (CONST_Debug)
35         {
36                 var_dump($aPolygons);
37                 exit;
38         }
39 ?>
40 <!DOCTYPE html>
41 <html>
42 <head>
43         <meta charset="utf-8"/>
44         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
45         
46         <title>Nominatim Broken Polygon Data</title>
47         
48         <meta name="description" content="List of broken OSM polygon data by date" lang="en-US" />
49
50 </head>
51
52 <body>
53 <style type="text/css">
54 table {
55         border-width: 1px;
56         border-spacing: 0px;
57         border-style: solid;
58         border-color: gray;
59         border-collapse: collapse;
60         background-color: white;
61         margin: 10px;
62 }
63 table th {
64         border-width: 1px;
65         padding: 2px;
66         border-style: inset;
67         border-color: gray;
68         border-left-color: #ddd;
69         border-right-color: #ddd;
70         background-color: #eee;
71         -moz-border-radius: 0px 0px 0px 0px;
72 }
73 table td {
74         border-width: 1px;
75         padding: 2px;
76         border-style: inset;
77         border-color: gray;
78         border-left-color: #ddd;
79         border-right-color: #ddd;
80         background-color: white;
81         -moz-border-radius: 0px 0px 0px 0px;
82 }
83 </style>
84
85 <?php
86
87         echo "<p>Total number of broken polygons: $iTotalBroken</p>";
88         if (!$aPolygons) exit;
89         echo "<table>";
90         echo "<tr>";
91 //var_dump($aPolygons[0]);
92         foreach($aPolygons[0] as $sCol => $sVal)
93         {
94                 echo "<th>".$sCol."</th>";
95         }
96         echo "<th>&nbsp;</th>";
97         echo "<th>&nbsp;</th>";
98         echo "</tr>";
99         $aSeen = array();
100         foreach($aPolygons as $aRow)
101         {
102                 if (isset($aSeen[$aRow['type'].$aRow['id']])) continue;
103                 $aSeen[$aRow['type'].$aRow['id']] = 1;
104                 echo "<tr>";
105                 foreach($aRow as $sCol => $sVal)
106                 {
107                         switch($sCol)
108                         {
109                         case 'error message':
110                                 if (preg_match('/Self-intersection\\[([0-9.\\-]+) ([0-9.\\-]+)\\]/',$sVal,$aMatch))
111                                 {
112                                         $aRow['lat'] = $aMatch[2];
113                                         $aRow['lon'] = $aMatch[1];
114                                         echo "<td><a href=\"http://www.openstreetmap.org/?lat=".$aMatch[2]."&lon=".$aMatch[1]."&zoom=18&layers=M&".$sOSMType."=".$aRow['id']."\">".($sVal?$sVal:'&nbsp;')."</a></td>";
115                                 }
116                                 else
117                                 {
118                                         echo "<td>".($sVal?$sVal:'&nbsp;')."</td>";
119                                 }
120                                 break;
121                         case 'id':
122                                 echo '<td>'.osmLink($aRow).'</td>';
123                                 break;
124                         default:
125                                 echo "<td>".($sVal?$sVal:'&nbsp;')."</td>";
126                                 break;
127                         }
128                 }
129                 echo "<td><a href=\"http://localhost:8111/import?url=http://www.openstreetmap.org/api/0.6/".$sOSMType.'/'.$aRow['id']."/full\" target=\"josm\">josm</a></td>";
130                 if (isset($aRow['lat']))
131                 {
132                         echo "<td><a href=\"http://open.mapquestapi.com/dataedit/index_flash.html?lat=".$aRow['lat']."&lon=".$aRow['lon']."&zoom=18\" target=\"potlatch2\">P2</a></td>";
133                 }
134                 else
135                 {
136                         echo "<td>&nbsp;</td>"; 
137                 }
138                 echo "</tr>";
139         }
140         echo "</table>";
141 ?>
142 </body>
143 </html>