admin管理员组文章数量:1122832
I have a list of 2000 names of localities. I Use OSMNX Library with OpenStreetMaps to get the administrative boundaries of these localities.
Here is the link to the File: ;ouid=104811936284098761818&rtpof=true&sd=true
The thing is, that in OpenStreetMaps, some of the localities are marked as points, not polygons, so i can not use the features_from_place option (because it can find only polygons)
Then I tried to use the ox.geocoder.geocode_to_gdf(thelist, which_result=1, by_osmid=False)
, where "thelist" contains my 2k locality names.
The same - i get Insufficient Response Error for the first Locality that cannot be found from the list.
Are there any ideas, how to make the OSMNX ignore the elements, that it could not find?
I Tried Googling, no results for this one... Actually this is really frustrating, because it looks more of like a bug to me, rather a meaningful behaviour
UPDATE: I have tried to find my localities by using the features_from_place, and I have some very strange results. The documentation says that the features_from_place gives us any result only if there is a Polygon (or multipol) type of object.
So, I tried to use 2 types of query: the code looks like:
dat = pd.read_excel('oren.xlsx')
lists = dat['Населённый пункт'][dat['Сроки'] =="-"].unique()
thelist=lists.tolist()
tags = {"name": thelist}
gdf = ox.features_from_place("Оренбургская Область", tags)
gdf2 = ox.features_from_place(thelist, {'addr:region':'Оренбургская Область'})
In this case, we find text "Оренбургская Область", for any element that has the tag 'Name' in it according to the given List (thelist) And you know what? It found a lot of data, and also it found POINTs, Lines, and other types of objects, not just the Polygons or MPolygons
The second way to try this code:
gdf2 = ox.features_from_place(thelist, {'addr:region':'Оренбургская Область'})
And here, we try data, that has a tag "addr:region" equal to "Оренбургская Область" to check all of the elements in this region, that has the text from the list in it.
and this one gave the error. Here is the full error text:
C:\Users\SSulyan\AppData\Local\anaconda3\Lib\site-packages\osmnx_overpass.py:254: UserWarning: This area is 81 times your configured Overpass max query area size. It will automatically be divided up into multiple sub-queries accordingly. This may take a long time. multi_poly_proj = utils_geo._consolidate_subdivide_geometry(poly_proj) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[191], line 3 1 tags = {"name": thelist} 2 gdf = ox.features_from_place("Оренбургская Область", tags) ----> 3 gdf2 = ox.features_from_place(thelist, {'addr:region':'Оренбургская Область'})
File ~\AppData\Local\anaconda3\Lib\site-packages\osmnx\features.py:294, in features_from_place(query, tags, which_result, buffer_dist) 289 gdf_place = geocoder.geocode_to_gdf( 290 query, which_result=which_result, buffer_dist=buffer_dist 291 ) 292 elif isinstance(query, list): 293 # if it is a list, it contains multiple places to get --> 294 gdf_place = geocoder.geocode_to_gdf(query, buffer_dist=buffer_dist) 295 else: # pragma: no cover 296 msg = "query must be dict, string, or list of strings"
File ~\AppData\Local\anaconda3\Lib\site-packages\osmnx\geocoder.py:139, in geocode_to_gdf(query, which_result, by_osmid, buffer_dist) 137 gdf = gpd.GeoDataFrame() 138 for q, wr in zip(query, which_result): --> 139 gdf = pd.concat([gdf, _geocode_query_to_gdf(q, wr, by_osmid)]) 141 # reset GeoDataFrame index and set its CRS 142 gdf = gdf.reset_index(drop=True)
File ~\AppData\Local\anaconda3\Lib\site-packages\osmnx\geocoder.py:194, in _geocode_query_to_gdf(query, which_result, by_osmid) 190 result = results[0] 192 elif which_result is None: 193 # else, if which_result=None, auto-select the first (Multi)Polygon --> 194 result = _get_first_polygon(results, query) 196 elif len(results) >= which_result: 197 # else, if we got at least which_result results, choose that one 198 result = results[which_result - 1]
File ~\AppData\Local\anaconda3\Lib\site-packages\osmnx\geocoder.py:259, in _get_first_polygon(results, query) 257 # if we never found a polygon, throw an error 258 msg = f"Nominatim could not geocode query {query!r} to a geometry of type (Multi)Polygon" --> 259 raise TypeError(msg)
TypeError: Nominatim could not geocode query 'Чабла' to a geometry of type (Multi)Polygon
The WHOLE CODE looks like this:
dat = pd.read_excel('oren.xlsx')
lists = dat['Населённый пункт'][dat['Сроки'] =="-"].unique()
thelist=lists.tolist()
tags = {"name": thelist}
gdf = ox.features_from_place("Оренбургская Область", tags)
gdf2 = ox.features_from_place(thelist, {'addr:region':'Оренбургская Область'})
UPDATE2: I try This code:
ox.geocoder.geocode_to_gdf('W366775538', which_result=1, by_osmid=True)
So it gives me an error, that Nominatim can't find this ID, bit this ID is present in the OpenstreetMap (website)
Error
本文标签: pythonIgnoring InsufficientResponseError in OSMNXStack Overflow
版权声明:本文标题:python - Ignoring InsufficientResponseError in OSMNX - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311262a1934674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论