]> git.openstreetmap.org Git - nominatim.git/commitdiff
restrict geometry size for SQLite
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 19 Oct 2023 19:24:53 +0000 (21:24 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 23 Oct 2023 15:19:12 +0000 (17:19 +0200)
nominatim/tools/convert_sqlite.py

index d766c6427c47649cfae6339b31defc22ccd9a63f..0702e5d8c045185cbcfea0a0fd18e328de2cd8b2 100644 (file)
@@ -138,6 +138,18 @@ class SqliteWriter:
         """
         columns = self.src.t.meta.tables[table].c
 
         """
         columns = self.src.t.meta.tables[table].c
 
+        if table == 'placex':
+            # SQLite struggles with Geometries that are larger than 5MB,
+            # so simplify those.
+            return sa.select(*(c for c in columns if not isinstance(c.type, Geometry)),
+                             sa.func.ST_AsText(columns.centroid).label('centroid'),
+                             sa.func.ST_AsText(
+                               sa.case((sa.func.ST_MemSize(columns.geometry) < 5000000,
+                                        columns.geometry),
+                                       else_=sa.func.ST_SimplifyPreserveTopology(
+                                                columns.geometry, 0.0001)
+                                )).label('geometry'))
+
         sql = sa.select(*(sa.func.ST_AsText(c).label(c.name)
                              if isinstance(c.type, Geometry) else c for c in columns))
 
         sql = sa.select(*(sa.func.ST_AsText(c).label(c.name)
                              if isinstance(c.type, Geometry) else c for c in columns))