Hi, I am a newbie here, especially in the GIS related areas. While learning by practicing and digesting your provided Jupyter Examples (which were very helpful) – starting with example “apartment search with openrouteservice” (https://openrouteservice.org/example-apartment-search-with-ors/), I ran into 2 errors and thought you might be interested in knowing (I’m not sure if it was because of my new environment (openrouteservice 2.3.3, python 3.8.8)):
Error #1: TypeError in In[8]**
17 params_poi['filter_category_ids'] = category
18 apt['categories'][typ] = dict()
---> 19 apt['categories'][typ]['geojson']= clnt.places(**params_poi)['features'] # Actual POI request
20 print("\t{}: {}".format(typ, # Print amount POIs
21 len(apt['categories'][typ]['geojson'])))
TypeError: list indices must be integers or slices, not str
Solution:
The error was fixed after I changed line #19 to "clnt.places(**params_poi)[0]['features'] # Actual POI" (by adding a [0] before [features]. This was due to the fact that "clnt.places(**params_poi)" is a list, not a dict.
Error #2: ValueError in In[12]
1 # Sum up the closest POIs to each apartment
2 for name, apt in apt_dict.items():
----> 3 apt['shortest_sum'] = sum([min(cat['durations']) for cat in apt['categories'].values()])
4 print("{} apartments: {} mins".format(name,
5 apt['shortest_sum']/60
in (.0)
1 # Sum up the closest POIs to each apartment
2 for name, apt in apt_dict.items():
----> 3 apt['shortest_sum'] = sum([min(cat['durations']) for cat in apt['categories'].values()])
4 print("{} apartments: {} mins".format(name,
5 apt['shortest_sum']/60
ValueError: min() arg is an empty sequence
Solution:
The error was fixed after I changed line #3 to "sum([min(cat['durations'], default=0) for cat in apt['categories'].values()]) " (by adding default=0 in the min() method to avoid the error when there was an empty cat[‘durations’].