File size: 757 Bytes
5d956f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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