使用OSMnx graph_from_bbox提取路网图遇类型错误求助
提取路网图生成距离矩阵时遇到TypeError问题求助
我尝试提取路网图以生成距离矩阵,但不确定是数据问题还是其他原因,希望获得帮助。
原始代码如下:
df = pd.read_csv('mat1.csv') def clean_coordinate(value): try: value = str(value).replace(',', '.') return float(value) except ValueError: return None df['x'] = df['x'].apply(clean_coordinate) df['y'] = df['y'].apply(clean_coordinate) north = df['x'].max() south = df['x'].min() east = df['y'].max() west = df['y'].min() bbox = [north, south, east, west] graph = ox.graph_from_bbox(*bbox, network_type='drive')
最初收到警告:
FutureWarning: Thenorth,south,east, andwestparameters are deprecated and will be removed in the v2.0.0 release. Use thebboxparameter instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123
调整后出现新错误:
TypeError:float()必须是字符串或实数,不能是'NoneType'
我检查变量类型的代码:
print(type(bbox)) print(type(north)) print(type(south)) print(type(east)) print(type(west))
执行结果:
<class 'list'> <class 'numpy.float64'> <class 'numpy.float64'> <class 'numpy.float64'> <class 'numpy.float64'>
即使将numpy.float64转换为普通float:
north1 = north.item() south1 = south.item() east1 = east.item() west1 = west.item() bbox = [north1, south1, east1, west1]
仍出现相同错误。请问是转换方法有误,还是存在其他问题?
内容的提问来源于stack exchange,提问作者Etienne Jolivel
相关产品推荐
相关产品推荐

