이것저것 기록

[python, GIS] OSMnx로 OSM 지도를 그래프로 불러오는 방법 본문

코린이/실무를 위한 코딩 기록

[python, GIS] OSMnx로 OSM 지도를 그래프로 불러오는 방법

anweh 2020. 11. 4. 14:25

OSMnx 라이브러리를 사용하면 OSM 지도 위의 어떤 도로든 노드-엣지 그래프로 불러올 수 있다.

찾아보니 여러가지 방법이 있는 것 같아서, 오늘은 그 방법들을 포스팅해볼까 한다. 

 

 

1. 위도 경도 정보를 사용해서 불러오기 (osmnx.graph.graph_from_point)

'''
Method1-1: passing a lat-lng point and network distance in meters
'''
location_point = (37.791427, -122.410018)
G1_1 = ox.graph_from_point(location_point, dist=500, dist_type='network')
fig, ax = ox.plot_graph(G1_1, node_color='r')



'''
Method1-2: passing a lat-lng point bbox distance in meters
'''
# define a point at the corner of California St and Mason St in SF
location_point = (37.791427, -122.410018)
G1_2 = ox.graph_from_point(location_point, dist=750, dist_type='bbox', network_type='drive')
fig, ax = ox.plot_graph(G1_2, node_color='r')

1번 방법은 dist_type의 인자를 bbox를 줄것이냐 network를 줄것이냐에 따라 1-1과 1-2로 나눌 수 있다.

dist_type은 두 가지 종류가 있다. 

  • dist_type (string): {‘network’, ‘bbox’} if ‘bbox’, retain only those nodes within a bounding box of the distance parameter. if ‘network’, retain only those nodes within some network distance from the center-most node.

불러올 네트워크도 도로, 인도, 자전거 도로 등 인자값을 바꾸어 선택할 수 있다. 

  • network_type (string): what type of street network to get if custom_filter is None. One of ‘walk’, ‘bike’, ‘drive’, ‘drive_service’, ‘all’, or ‘all_private’.

G1_1(좌), G1_2(우) 실행 결과

 

 

2. 주소 정보를 사용해서 불러오기 (osmnx.graph.graph_from_address)

'''
Method2: passing an address and distance (bbox or network) in meters 
'''
# network from address, including only nodes within 1km along the network from the address
G2 = ox.graph_from_address(address='350 5th Ave, New York, NY', dist=1000,
                          dist_type='bbox', network_type='drive')
fig, ax = ox.plot_graph(G2, node_color='r')

실행 결과 및 실제 지도와 비교

 

 

 

3. 지역명을 사용해서 불러오기 (osmnx.graph.graph_from_place)

'''
Method3: passing a place name  
'''
G3 = ox.graph_from_place('North Hempstead, New York, USA', network_type='drive')
fig, ax = ox.plot_graph(G3, node_color='r')

실행 결과 및 실제 지도와 비교

 

 

4. 동서남북 좌표를 사용해서 불러오기 (osmnx.graph.graph_from_bbox)

'''
Method4: passing a bbox 
'''
# define a bounding box in San Francisco
north, south, east, west = 37.79, 37.78, -122.41, -122.43

# create network from that bounding box
G4 = ox.graph_from_bbox(north, south, east, west, network_type='drive_service')
fig, ax = ox.plot_graph(G4, node_color='b')

실행 결과 및 실제 지도와 비교

 

 

Comments