]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge branch 'master' of github.com:twain47/Nominatim
authorBrian Quinion <openstreetmap@brian.quinion.co.uk>
Mon, 3 Dec 2012 14:14:40 +0000 (14:14 +0000)
committerBrian Quinion <openstreetmap@brian.quinion.co.uk>
Mon, 3 Dec 2012 14:14:40 +0000 (14:14 +0000)
sql/functions.sql
sql/tables.sql
website/deletable.php [new file with mode: 0755]

index 4d05d79b8111454d18ef7fb35df9f189df201d51..03104dd5a9f32fdf3ea51928af3b1f15189c944f 100644 (file)
@@ -2903,3 +2903,70 @@ BEGIN
 END;
 $$
 LANGUAGE plpgsql;
+
+
+CREATE OR REPLACE FUNCTION place_force_delete(placeid BIGINT) RETURNS BOOLEAN
+  AS $$
+DECLARE
+    osmid BIGINT;
+    osmtype character(1);
+    pclass text;
+    ptype text;
+BEGIN
+  SELECT osm_type, osm_id, class, type FROM placex WHERE place_id = placeid INTO osmtype, osmid, pclass, ptype;
+  DELETE FROM import_polygon_delete where osm_type = osmtype and osm_id = osmid and class = pclass and type = ptype;
+  DELETE FROM import_polygon_error where osm_type = osmtype and osm_id = osmid and class = pclass and type = ptype;
+  -- force delete from place/placex by making it a very small geometry
+  UPDATE place set geometry = ST_SetSRID(ST_Point(0,0), 4326) where osm_type = osmtype and osm_id = osmid and class = pclass and type = ptype;
+  DELETE FROM place where osm_type = osmtype and osm_id = osmid and class = pclass and type = ptype;
+
+  RETURN TRUE;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION place_force_update(placeid BIGINT) RETURNS BOOLEAN
+  AS $$
+DECLARE
+  placegeom GEOMETRY;
+  geom GEOMETRY;
+  diameter FLOAT;
+  rank INTEGER;
+BEGIN
+  SELECT geometry, rank_search FROM placex WHERE place_id = placeid INTO placegeom, rank;
+  IF placegeom IS NOT NULL AND ST_IsValid(placegeom) THEN
+    IF ST_GeometryType(placegeom) in ('ST_Polygon','ST_MultiPolygon') THEN
+      FOR geom IN select split_geometry(placegeom) FROM placex WHERE place_id = placeid LOOP
+        update placex set indexed_status = 2 where (st_covers(geom, placex.geometry) OR ST_Intersects(geom, placex.geometry)) 
+        AND rank_search > rank and indexed_status = 0 and ST_geometrytype(placex.geometry) = 'ST_Point' and (rank_search < 28 or name is not null);
+        update placex set indexed_status = 2 where (st_covers(geom, placex.geometry) OR ST_Intersects(geom, placex.geometry)) 
+        AND rank_search > rank and indexed_status = 0 and ST_geometrytype(placex.geometry) != 'ST_Point' and (rank_search < 28 or name is not null);
+      END LOOP;
+    ELSE
+        diameter := 0;
+        IF rank = 11 THEN
+          diameter := 0.05;
+        ELSEIF rank < 18 THEN
+          diameter := 0.1;
+        ELSEIF rank < 20 THEN
+          diameter := 0.05;
+        ELSEIF rank = 21 THEN
+          diameter := 0.001;
+        ELSEIF rank < 24 THEN
+          diameter := 0.02;
+        ELSEIF rank < 26 THEN
+          diameter := 0.002; -- 100 to 200 meters
+        ELSEIF rank < 28 THEN
+          diameter := 0.001; -- 50 to 100 meters
+        END IF;
+        IF diameter > 0 THEN
+          update placex set indexed_status = 2 where indexed_status = 0 and rank_search > rank and ST_DWithin(placex.geometry, placegeom, diameter) and (rank_search < 28 or name is not null);
+        END IF;
+    END IF;
+    RETURN TRUE;
+  END IF;
+
+  RETURN FALSE;
+END;
+$$
+LANGUAGE plpgsql;
index 13954149926f40cda40687537330fef6d5e88ef0..212d78c60752718ea1caf84926ec28ff0a9a4c7c 100644 (file)
@@ -249,17 +249,7 @@ CREATE TRIGGER place_before_delete BEFORE DELETE ON place
 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
     FOR EACH ROW EXECUTE PROCEDURE place_insert();
 
-alter table placex add column geometry_sector INTEGER;
-alter table placex add column indexed_status INTEGER;
-alter table placex add column indexed_date TIMESTAMP;
-
-update placex set geometry_sector = geometry_sector(geometry);
-drop index idx_placex_pendingbylatlon;
-drop index idx_placex_interpolation;
 drop index idx_placex_sector;
-CREATE INDEX idx_placex_pendingbylatlon ON placex USING BTREE (geometry_index(geometry_sector,indexed,name),rank_search) 
-  where geometry_index(geometry_sector,indexed,name) IS NOT NULL;
-CREATE INDEX idx_placex_interpolation ON placex USING BTREE (geometry_sector) where indexed = false and class='place' and type='houses';
 CREATE INDEX idx_placex_sector ON placex USING BTREE (geometry_sector,rank_address,osm_type,osm_id);
 
 DROP SEQUENCE seq_postcodes;
@@ -289,6 +279,7 @@ CREATE TABLE import_polygon_delete (
   type TEXT NOT NULL
   );
 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
+GRANT SELECT ON import_polygon_delete TO "www-data";
 
 drop sequence file;
 CREATE SEQUENCE file start 1;
diff --git a/website/deletable.php b/website/deletable.php
new file mode 100755 (executable)
index 0000000..8d3fa82
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+        require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
+        require_once(CONST_BasePath.'/lib/log.php');
+
+       $sOutputFormat = 'html';
+       ini_set('memory_limit', '200M');
+
+       $oDB =& getDB();
+
+       $sSQL = "select placex.place_id, calculated_country_code as country_code, name->'name' as name, i.* from placex, import_polygon_delete i where placex.osm_id = i.osm_id and placex.osm_type = i.osm_type and placex.class = i.class and placex.type = i.type";
+       $aPolygons = $oDB->getAll($sSQL);
+    if (PEAR::isError($aPolygons))
+    {
+         failInternalError("Could not get small viewbox.", $sSQL, $aPolygons);
+    }
+
+
+//var_dump($aPolygons);
+?>
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8"/>
+    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
+    
+    <title>Nominatim Deleted Data</title>
+    
+    <meta name="description" content="List of OSM data that has been deleted" lang="en-US" />
+
+</head>
+
+<body>
+<style type="text/css">
+table {
+       border-width: 1px;
+       border-spacing: 0px;
+       border-style: solid;
+       border-color: gray;
+       border-collapse: collapse;
+       background-color: white;
+       margin: 10px;
+}
+table th {
+       border-width: 1px;
+       padding: 2px;
+       border-style: inset;
+       border-color: gray;
+       border-left-color: #ddd;
+       border-right-color: #ddd;
+       background-color: #eee;
+       -moz-border-radius: 0px 0px 0px 0px;
+}
+table td {
+       border-width: 1px;
+       padding: 2px;
+       border-style: inset;
+       border-color: gray;
+       border-left-color: #ddd;
+       border-right-color: #ddd;
+       background-color: white;
+       -moz-border-radius: 0px 0px 0px 0px;
+}
+</style>
+
+<p>Objects in this table have been deleted in OSM but are still in the Nominatim database.</p>
+
+<table>
+<?php
+       echo "<tr>";
+//var_dump($aPolygons[0]);
+       foreach($aPolygons[0] as $sCol => $sVal)
+       {
+               echo "<th>".$sCol."</th>";
+       }
+       echo "</tr>";
+       foreach($aPolygons as $aRow)
+       {
+               echo "<tr>";
+               foreach($aRow as $sCol => $sVal)
+               {
+                       switch($sCol)
+                       {
+            case 'osm_id':
+                $sOSMType = ($aRow['osm_type'] == 'N'?'node':($aRow['osm_type'] == 'W'?'way':($aRow['osm_type'] == 'R'?'relation':'')));
+                echo '<td><a href="http://www.openstreetmap.org/browse/'.$sOSMType.'/'.$sVal.'" target="_new">'.$sVal.'</a></td>';
+                                break;
+                       case 'place_id':
+                               echo '<td><a href="'.CONST_Website_BaseURL.'details?place_id='.$sVal.'">'.$sVal.'</a></td>';
+                               break;
+                       default:
+                               echo "<td>".($sVal?$sVal:'&nbsp;')."</td>";
+                               break;
+                       }
+               }
+               echo "</tr>";
+       }
+?>
+</table>
+
+
+
+</body>
+</html>