Merge pull request #3590 from lonvia/lookup-per-osm-type

Look up different OSM types in placex separately
This commit is contained in:
Sarah Hoffmann 2024-11-15 09:44:16 +01:00 committed by GitHub
commit 689bcbd6ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -201,14 +201,16 @@ async def find_in_placex(conn: SearchConnection, collector: Collector) -> bool:
t.c.geometry.ST_Expand(0).label('bbox'), t.c.geometry.ST_Expand(0).label('bbox'),
t.c.centroid) t.c.centroid)
osm_ids = [{'i': i, 'ot': p.osm_type, 'oi': p.osm_id, 'oc': p.osm_class or ''} for osm_type in ('N', 'W', 'R'):
for i, p in collector.enumerate_free_osm_ids()] osm_ids = [{'i': i, 'oi': p.osm_id, 'oc': p.osm_class or ''}
for i, p in collector.enumerate_free_osm_ids()
if p.osm_type == osm_type]
if osm_ids: if osm_ids:
oid_tab = sa.func.JsonArrayEach(sa.type_coerce(osm_ids, sa.JSON))\ oid_tab = sa.func.JsonArrayEach(sa.type_coerce(osm_ids, sa.JSON))\
.table_valued(sa.column('value', type_=sa.JSON)) .table_valued(sa.column('value', type_=sa.JSON))
psql = sql.add_columns(oid_tab.c.value['i'].as_integer().label('_idx'))\ psql = sql.add_columns(oid_tab.c.value['i'].as_integer().label('_idx'))\
.where(t.c.osm_type == oid_tab.c.value['ot'].as_string())\ .where(t.c.osm_type == osm_type)\
.where(t.c.osm_id == oid_tab.c.value['oi'].as_string().cast(sa.BigInteger))\ .where(t.c.osm_id == oid_tab.c.value['oi'].as_string().cast(sa.BigInteger))\
.where(sa.or_(oid_tab.c.value['oc'].as_string() == '', .where(sa.or_(oid_tab.c.value['oc'].as_string() == '',
oid_tab.c.value['oc'].as_string() == t.c.class_))\ oid_tab.c.value['oc'].as_string() == t.c.class_))\