python - 循环坐标列表并将坐标列表中的位置增加一以执行请求
问题描述
我正在尝试遍历坐标列表以生成路线,我不能一次使用所有这些路线,因为我需要单独生成某些值。
所以我的坐标列表被定义为“坐标”,看起来像这样:
[[14.21055347, 47.5674345], [16.39356558, 48.17711001], [14.21055347, 47.5674345], [16.29236955, 48.15006768], [16.32467573, 48.13840484], [16.147533399999997, 48.3067388], [14.502926, 48.19992600000001], [14.21055347, 47.5674345], [16.30826472, 48.13786834], [15.92248574, 47.65823679], [14.21055347, 47.5674345], [16.40964033, 48.18617251], [16.393805666666665, 48.26835166666667], [16.393009142857142, 48.26821028571428], [15.92248574, 47.65823679], [14.21055347, 47.5674345], [16.40964033, 48.18617251], [16.19483273, 47.75397909], [14.21055347, 47.5674345], [13.717176157894738, 48.01453281578947]]
调用路由数据的代码是:
body = {"coordinates":coords,"attributes":["percentage"],"extra_info":["waycategory"]}
headers = {
'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
'Content-Type': 'application/geo+json; charset=utf-8'
}
call = requests.post('http://127.0.0.1:8080/ors/v2/directions/driving-hgv/geojson', json=body, headers=headers)
weiter = call.text
data = json.loads(weiter)
上面的代码将获取整个坐标列表并请求路由并生成数据。我实际上需要为每个坐标对(坐标[x,x+1])生成路线和打印数据。所以我会生成以下请求:
[[14.21055347, 47.5674345], [16.39356558, 48.17711001]], [[16.39356558, 48.17711001], [14.21055347, 47.5674345]], etc.
所以我的猜测是有一个循环像这样遍历身体:
i = 0
while i < len(coords):
body = {"coordinates":coords[int(i),int(i+1)],"attributes":["percentage"],"extra_info":["waycategory"]}
headers = {
'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
'Content-Type': 'application/geo+json; charset=utf-8'
}
call = requests.post('http://127.0.0.1:8080/ors/v2/directions/driving-hgv/geojson', json=body, headers=headers)
weiter = call.text
data = json.loads(weiter)
print(data)
我尝试过的这种方法和其他方法都行不通-如果您对我如何进行操作有建议,我将非常感激!
解决方案
推荐阅读
- javascript - 使用 Chart JS 进行插入排序
- assembly - 在汇编语言中得到错误的结果
- git - 任何人都可以解释成功的 git push 命令的输出吗?尤其是最后一行(master -->> master) ,
- reactjs - 如何传递 cli 参数来反应 craco?
- r - 使用ggplot2统计密度图
- python - Django Rest Framework嵌套不同的序列化程序保存问题
- google-my-business - 为什么我不能使用“fions”这个词来创建谷歌我的商业资料?
- flutter - 在 VSCode 中调试颤振时出错
- xml - 我想在不更改其属性的情况下将 xml 元素“产品”重命名为“项目”,但我不知道该怎么做
- c++ - 大写替代字母