Download src/map_utils.py from RKAITS/TKPS: direct link, hf CLI and curl.
- Browser
- Download file 757 Bytes
-
https://huggingface.co/spaces/RKAITS/TKPS/resolve/main/src/map_utils.py
- Command line
-
hf download hf://spaces/RKAITS/TKPS/src/map_utils.py
-
curl -L -o map_utils.py https://huggingface.co/spaces/RKAITS/TKPS/resolve/main/src/map_utils.py
757 Bytes
| import osmnx as ox | |
| import matplotlib.pyplot as plt | |
| import tempfile | |
| import os | |
| def ambil_graf_dan_gambar(): | |
| # Nonaktifkan cache karena HuggingFace tidak izinkan write di luar tmp | |
| ox.settings.use_cache = False | |
| ox.settings.cache_folder = tempfile.gettempdir() | |
| ox.settings.logs_folder = tempfile.gettempdir() | |
| # Ambil graf OSM | |
| G = ox.graph_from_place("Keputih, Sukolilo, Surabaya, Indonesia", network_type="drive", simplify=True) | |
| # Buat plot dan simpan ke file | |
| fig, ax = ox.plot_graph(G, node_size=20, node_color='red', edge_color="gray", bgcolor="white", show=False, close=True) | |
| path_gambar = os.path.join(tempfile.gettempdir(), "graph_keputih_osm.png") | |
| fig.savefig(path_gambar, dpi=150) | |
| return G, path_gambar | |