X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/36b1660121a9261998a2b36cff741587ce5b3c5b..40b87bbadf2f6eabdc94a125b83a83cdc7fecc4e:/lib-sql/functions/utils.sql?ds=sidebyside

diff --git a/lib-sql/functions/utils.sql b/lib-sql/functions/utils.sql
index a8ebcc41..f8b365c5 100644
--- a/lib-sql/functions/utils.sql
+++ b/lib-sql/functions/utils.sql
@@ -436,6 +436,20 @@ END;
 $$
 LANGUAGE plpgsql IMMUTABLE;
 
+CREATE OR REPLACE FUNCTION simplify_large_polygons(geometry GEOMETRY)
+  RETURNS GEOMETRY
+  AS $$
+BEGIN
+  IF ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon')
+     and ST_MemSize(geometry) > 3000000
+  THEN
+    geometry := ST_SimplifyPreserveTopology(geometry, 0.0001);
+  END IF;
+  RETURN geometry;
+END;
+$$
+LANGUAGE plpgsql IMMUTABLE;
+
 
 CREATE OR REPLACE FUNCTION place_force_delete(placeid BIGINT)
   RETURNS BOOLEAN
