X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/70f6f9a711727150532a9b958f279435901d4805..104722a56a4773eae275b25987b4d340f19d35bb:/nominatim/api/lookup.py?ds=sidebyside diff --git a/nominatim/api/lookup.py b/nominatim/api/lookup.py index cb9f9839..56a41310 100644 --- a/nominatim/api/lookup.py +++ b/nominatim/api/lookup.py @@ -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)