]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/tools/convert_sqlite.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / tools / convert_sqlite.py
index afae0d6b87e7b545c94bdbe06a9c8e895f1d1010..0702e5d8c045185cbcfea0a0fd18e328de2cd8b2 100644 (file)
@@ -113,6 +113,7 @@ class SqliteWriter:
         await self.create_spatial_index('osmline', 'linegeo')
         await self.create_spatial_index('tiger', 'linegeo')
         await self.create_index('placex', 'place_id')
+        await self.create_index('placex', 'parent_place_id')
         await self.create_index('placex', 'rank_address')
         await self.create_index('addressline', 'place_id')
 
@@ -137,6 +138,18 @@ class SqliteWriter:
         """
         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))