Skip to content

Commit

Permalink
restrict geometry size for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Oct 23, 2023
1 parent 84d6b48 commit a9ac68a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nominatim/tools/convert_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ def select_from(self, table: str) -> SaSelect:
"""
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))

Expand Down

0 comments on commit a9ac68a

Please sign in to comment.