Skip to content

No error handler for no data response #47

Open
@LeonDeTur

Description

Describe the bug
Geocoder fals when other geo objects functions get empty data from osm (that's just my assumption). In the following case seems railways request caused problem.

Full error outout

EmptyOverpassResponse Traceback (most recent call last)
Cell In[11], line 1
----> 1 result = Geocoder(osm_city_name='Камчатский край', osm_city_level=5).run(osm_id = 4139922, tags = {"admin_level": ["5"]}, date = "2024-04-22T00:00:00Z", df=df, text_column='text', group_column = "group_name")

File C:\Projects\ITMO\sloyka\sloyka\src\geocoder.py:1157, in Geocoder.run(self, osm_id, tags, date, df, text_column, group_column)
1155 df[text_column] = df[text_column].str.replace('\n', ' ')
1156 df[text_column] = df[text_column].apply(str)
-> 1157 df_obj = OtherGeoObjects.run(self.osm_city_name, df, text_column)
1158 street_names = Streets.run(self.osm_city_name, self.osm_city_level)
1160 df = self.get_street(df, text_column)

File C:\Projects\ITMO\sloyka\sloyka\src\geocoder.py:583, in OtherGeoObjects.run(osm_city_name, df, text_column)
581 df_obj = df.copy()
582 df_obj['Numbers'] = np.nan
--> 583 osm_combined_df = OtherGeoObjects.run_OSM_dfs(osm_city_name)
584 logger.info('find_other_geo_obj started')
585 df_obj['other_geo_obj'] = df_obj[text_column].apply(OtherGeoObjects.extract_geo_obj)

File C:\Projects\ITMO\sloyka\sloyka\src\geocoder.py:445, in OtherGeoObjects.run_OSM_dfs(osm_city_name)
433 logger.info('run_OSM_dfs started')
435 osm_functions = [
436 OtherGeoObjects.get_OSM_green_obj,
437 OtherGeoObjects.get_OSM_num_obj,
(...)
442 OtherGeoObjects.get_OSM_historic
443 ]
--> 445 osm_dfs = [OtherGeoObjects.get_and_process_osm_data(osm_city_name, func) for func in osm_functions]
446 osm_combined_df = pd.concat(osm_dfs, axis=0)
448 return osm_combined_df

File C:\Projects\ITMO\sloyka\sloyka\src\geocoder.py:445, in (.0)
433 logger.info('run_OSM_dfs started')
435 osm_functions = [
436 OtherGeoObjects.get_OSM_green_obj,
437 OtherGeoObjects.get_OSM_num_obj,
(...)
442 OtherGeoObjects.get_OSM_historic
443 ]
--> 445 osm_dfs = [OtherGeoObjects.get_and_process_osm_data(osm_city_name, func) for func in osm_functions]
446 osm_combined_df = pd.concat(osm_dfs, axis=0)
448 return osm_combined_df

File C:\Projects\ITMO\sloyka\sloyka\src\geocoder.py:424, in OtherGeoObjects.get_and_process_osm_data(osm_city_name, get_data_function)
420 def get_and_process_osm_data(osm_city_name, get_data_function) -> pd.DataFrame:
421 """
422 This function allows you to build an OSM array for different urban objects.
423 """
--> 424 df = get_data_function(osm_city_name)
425 df['geometry'] = df['geometry'].apply(OtherGeoObjects.calculate_centroid)
426 df.rename(columns={df.columns[2]: 'geo_obj_tag'}, inplace=True)

File C:\Projects\ITMO\sloyka\sloyka\src\geocoder.py:366, in OtherGeoObjects.get_OSM_railway(osm_city_name)
362 """
363 This function sets spatial data from OSM about railway obj.
364 """
365 tags = {'railway': ['station', 'subway']}
--> 366 osm_railway = ox.geometries_from_place(osm_city_name, tags)
367 osm_railway_df = pd.DataFrame(osm_railway)
368 osm_railway_df = osm_railway_df.dropna(subset=['name'])

File c:\Users\thebe\AppData\Local\pypoetry\Cache\virtualenvs\sloyka-B5Yiy4FA-py3.11\Lib\site-packages\osmnx\geometries.py:127, in geometries_from_place(query, tags, which_result, buffer_dist)
103 """
104 Do not use: deprecated.
105
(...)
124 gdf : geopandas.GeoDataFrame
125 """
126 warn(DEP_MSG, stacklevel=2)
--> 127 return features.features_from_place(query, tags, which_result, buffer_dist)

File c:\Users\thebe\AppData\Local\pypoetry\Cache\virtualenvs\sloyka-B5Yiy4FA-py3.11\Lib\site-packages\osmnx\features.py:279, in features_from_place(query, tags, which_result, buffer_dist)
276 utils.log("Constructed place geometry polygon(s) to query API")
278 # create GeoDataFrame using this polygon(s) geometry
--> 279 gdf = features_from_polygon(polygon, tags)
281 return gdf

File c:\Users\thebe\AppData\Local\pypoetry\Cache\virtualenvs\sloyka-B5Yiy4FA-py3.11\Lib\site-packages\osmnx\features.py:330, in features_from_polygon(polygon, tags)
327 response_jsons = _downloader._osm_features_download(polygon, tags)
329 # create GeoDataFrame from the downloaded data
--> 330 gdf = _create_gdf(response_jsons, polygon, tags)
332 return gdf

File c:\Users\thebe\AppData\Local\pypoetry\Cache\virtualenvs\sloyka-B5Yiy4FA-py3.11\Lib\site-packages\osmnx\features.py:410, in _create_gdf(response_jsons, polygon, tags)
406 if elements_count == 0:
407 msg = (
408 "There are no data elements in the server response. Check log and query location/tags."
409 )
--> 410 raise EmptyOverpassResponse(msg)
412 # begin processing the elements retrieved from the server
413 utils.log(f"Converting {elements_count} elements in JSON responses to features")

EmptyOverpassResponse: There are no data elements in the server response. Check log and query location/tags.

To Reproduce

  1. Go to the feat/group_names
  2. import geocoder
  3. load the attached data to pd.DataFrame object (sep = ',') Don't ask me why, I though we were done with commas as separators. Just in case link to csv: https://niuitmo-my.sharepoint.com/:x:/g/personal/412499_niuitmo_ru/EZfm9rXpYPlFi4gS8b1nLW8BPQfqxxOjIVdQDwMn91ED-w?e=KGb82S
  4. Use the run function with following parameters: result = Geocoder(osm_city_name='Камчатский край', osm_city_level=5).run(osm_id = 4139922, tags = {"admin_level": ["5"]}, date = "2024-04-22T00:00:00Z", df=df, text_column='text', group_column = "group_name")
    Expected behavior
    Function should return gpd.GeoDataFrame object and handle osm server exceptions.

Desktop (please complete the following information):

  • OS: Windows 11
  • VSCode 1.90
  • Python 3.11.8
  • feat/group_names

kamchatrip.csv

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions