mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
add lookup of postcdoe data
This commit is contained in:
@@ -95,8 +95,8 @@ async def find_in_osmline(conn: SearchConnection, place: ntyp.PlaceRef,
|
||||
|
||||
async def find_in_tiger(conn: SearchConnection, place: ntyp.PlaceRef,
|
||||
details: ntyp.LookupDetails) -> Optional[SaRow]:
|
||||
""" Search for the given place in table of Tiger addresses and return the
|
||||
base information.
|
||||
""" Search for the given place in the table of Tiger addresses and return
|
||||
the base information. Only lookup by place ID is supported.
|
||||
"""
|
||||
t = conn.t.tiger
|
||||
sql = sa.select(t.c.place_id, t.c.parent_place_id,
|
||||
@@ -114,6 +114,27 @@ async def find_in_tiger(conn: SearchConnection, place: ntyp.PlaceRef,
|
||||
return (await conn.execute(sql)).one_or_none()
|
||||
|
||||
|
||||
async def find_in_postcode(conn: SearchConnection, place: ntyp.PlaceRef,
|
||||
details: ntyp.LookupDetails) -> Optional[SaRow]:
|
||||
""" Search for the given place in the postcode table and return the
|
||||
base information. Only lookup by place ID is supported.
|
||||
"""
|
||||
t = conn.t.postcode
|
||||
sql = sa.select(t.c.place_id, t.c.parent_place_id,
|
||||
t.c.rank_search, t.c.rank_address,
|
||||
t.c.indexed_date, t.c.postcode, t.c.country_code,
|
||||
sa.func.ST_X(t.c.geometry).label('x'),
|
||||
sa.func.ST_Y(t.c.geometry).label('y'),
|
||||
_select_column_geometry(t.c.geometry, details.geometry_output))
|
||||
|
||||
if isinstance(place, ntyp.PlaceID):
|
||||
sql = sql.where(t.c.place_id == place.place_id)
|
||||
else:
|
||||
return None
|
||||
|
||||
return (await conn.execute(sql)).one_or_none()
|
||||
|
||||
|
||||
async def get_place_by_id(conn: SearchConnection, place: ntyp.PlaceRef,
|
||||
details: ntyp.LookupDetails) -> Optional[nres.SearchResult]:
|
||||
""" Retrieve a place with additional details from the database.
|
||||
@@ -133,6 +154,12 @@ async def get_place_by_id(conn: SearchConnection, place: ntyp.PlaceRef,
|
||||
await nres.add_result_details(conn, result, details)
|
||||
return result
|
||||
|
||||
row = await find_in_postcode(conn, place, details)
|
||||
if row is not None:
|
||||
result = nres.create_from_postcode_row(row)
|
||||
await nres.add_result_details(conn, result, details)
|
||||
return result
|
||||
|
||||
row = await find_in_tiger(conn, place, details)
|
||||
if row is not None:
|
||||
result = nres.create_from_tiger_row(row)
|
||||
|
||||
@@ -203,6 +203,23 @@ def create_from_tiger_row(row: SaRow) -> SearchResult:
|
||||
geometry=_filter_geometries(row))
|
||||
|
||||
|
||||
def create_from_postcode_row(row: SaRow) -> SearchResult:
|
||||
""" Construct a new SearchResult and add the data from the result row
|
||||
from the postcode centroid table.
|
||||
"""
|
||||
return SearchResult(source_table=SourceTable.POSTCODE,
|
||||
place_id=row.place_id,
|
||||
parent_place_id=row.parent_place_id,
|
||||
category=('place', 'postcode'),
|
||||
names={'ref': row.postcode},
|
||||
rank_search=row.rank_search,
|
||||
rank_address=row.rank_address,
|
||||
country_code=row.country_code,
|
||||
centroid=Point(row.x, row.y),
|
||||
indexed_date=row.indexed_date,
|
||||
geometry=_filter_geometries(row))
|
||||
|
||||
|
||||
async def add_result_details(conn: SearchConnection, result: SearchResult,
|
||||
details: LookupDetails) -> None:
|
||||
""" Retrieve more details from the database according to the
|
||||
|
||||
Reference in New Issue
Block a user