import requests mylayer = QgsProject.instance().mapLayersByName("decathlon_france")[0] limit = 20 i = 0 with edit(mylayer): for feat in mylayer.getFeatures(): if feat['iso'] == 0: id_mag = feat['id'] geom = feat.geometry() i += 1 if i > limit: break feat['iso'] = 1 mylayer.updateFeature(feat) #print(id_mag, geom.asPoint().x(), geom.asPoint().y(), i) # ZONE ISOCHRONE body = {"locations":[[geom.asPoint().x(), geom.asPoint().y()]],"range":[900],"attributes":["area","reachfactor","total_pop"],"range_type":"time"} headers = { 'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8', 'Authorization': 'YOUR-API-KEY', 'Content-Type': 'application/json; charset=utf-8' } call = requests.post('https://api.openrouteservice.org/v2/isochrones/driving-car', json=body, headers=headers) #print(call.status_code, call.reason) #print(call.text) with open('C:/Users/Georges/Downloads/CoursQGIS/data/isochrones/'+id_mag+'.geoson', 'w', encoding='utf-8') as outfile: outfile.write(call.text) iface.addVectorLayer('C:/Users/Georges/Downloads/CoursQGIS/data/isochrones/'+id_mag+'.geoson', id_mag, 'ogr') # AJOUTER ID MAGASIN my_geojson = QgsProject.instance().mapLayersByName(id_mag)[0] pr = my_geojson.dataProvider() pr.addAttributes([QgsField("id_mag", QVariant.String)]) my_geojson.updateFields() with edit(my_geojson): for feature in my_geojson.getFeatures(): feature['id_mag'] = id_mag my_geojson.updateFeature(feature)