TKPS / src /map_utils.py
DianDzzz's picture
Rename src/src to src/map_utils.py
5d956f3 verified
Raw History Blame Contribute Delete
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