Last active
November 24, 2022 11:08
-
-
Save karussell/12106512fd2daecd4c5ff02feb7b12c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Customizable Routing\n\nLet's try customizable routing inside a Jupyter Notebook. Read the details in [this blog post](https://www.graphhopper.com/blog/2020/05/31/examples-for-customizable-routing/) and also [here](https://www.graphhopper.com/blog/2020/05/06/get-started-with-customizable-routing/).\nYou can install the open source GraphHopper routing engine [locally](https://github.com/graphhopper/graphhopper) and replace the route_url with\n```\nroute_url = 'http://localhost:8989/route?\n```"},{"metadata":{"trusted":true},"cell_type":"code","source":"import requests\n\napi_key = ''\nroute_url = 'https://graphhopper.com/api/1/route?key=' + api_key\n\n# https://graphhopper.com/maps/?point=52.465422%2C13.355255&point=52.534185%2C13.311996&profile=car\nstart=[13.311996,52.534185]\nend=[13.355255,52.465422]\n\ndef send_route ( json ): \n route = requests.post(route_url, json=json).json()\n if 'message' in route: raise Exception(route[\"message\"]) \n path = route[\"paths\"][0]\n print(f'distance: {(int)(path[\"distance\"]/1000)}km, time: {(int)(path[\"time\"]/60000)}min');\n\nsend_route({'profile':'car', 'points':[start,end], 'points_encoded':False})\n\ncustom_model = {\"priority\": [{ \"if\": \"road_class == MOTORWAY\", \"multiply_by\": \"0.0\" }]}\nsend_route({'profile':'car', 'points':[start,end], 'points_encoded':False, 'custom_model': custom_model, 'ch.disable': True})","execution_count":21,"outputs":[{"output_type":"stream","text":"distance: 14km, time: 18min\ndistance: 9km, time: 21min\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3 (ipykernel)","language":"python"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment