32 lines
817 B
Python
32 lines
817 B
Python
from __future__ import annotations
|
|
from typing import Optional, Tuple, Any, List
|
|
|
|
import requests
|
|
import pandas as pd
|
|
import numpy as np
|
|
|
|
GeoTupleType = Tuple[Optional[int], Optional[float], Optional[float]]
|
|
|
|
|
|
def get_building_id(street: str) -> GeoTupleType:
|
|
if pd.isnull(street):
|
|
return None, None, None
|
|
|
|
r = requests.get('https://geocode.gate.petersburg.ru/parse/eas', params={
|
|
'street': street
|
|
}, timeout=10)
|
|
|
|
res = r.json()
|
|
|
|
if 'error' in res:
|
|
return None, None, None
|
|
|
|
return res['Building_ID'], res['Latitude'], res['Longitude']
|
|
|
|
|
|
def fetch_builing_ids(df: pd.DataFrame) -> pd.DataFrame:
|
|
df[['ID здания', 'Широта', 'Долгота']] = df.apply(
|
|
lambda row: get_building_id(row['Улица']), axis=1, result_type='expand')
|
|
|
|
return df
|