Skip to content

Commit ff9133e

Browse files
committed
read osm data to images and graphs based on admin boundaries
1 parent 64e6ce3 commit ff9133e

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
data/output/*
1+
data/*
22
__pycache__/*

osm2graphdata.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pyrosm import OSM, get_data
2+
import networkx as nx
3+
4+
# Initialize reader
5+
dir_name = "data/osm/"
6+
map_name = "SantaBarbara"
7+
osm = OSM(dir_name+map_name+".osm.pbf")
8+
for i in range(len(osm.get_boundaries()['osm_type'])):
9+
if(osm.get_boundaries()['osm_type'][i]=='relation'):
10+
osm_data = OSM(dir_name+map_name+".osm.pbf", osm.get_boundaries()['geometry'][i])
11+
nodes, edges = osm_data.get_network(nodes=True, network_type="driving")
12+
nx_graph = osm.to_graph(nodes, edges, graph_type="networkx")
13+
nx.write_gpickle(nx_graph, 'data/output/'+map_name+str(i)+'.gpickle')
14+

osm2imgdata.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Program to return images and graphs given an OSM PBF file.
2+
from pyrosm import OSM, get_data
3+
import matplotlib.pyplot as plt
4+
import osmnx as ox
5+
6+
# Initialize reader
7+
dir_name = "data/osm/"
8+
map_name = "SanJose"
9+
osm = OSM(dir_name+map_name+".osm.pbf")
10+
for i in range(len(osm.get_boundaries()['osm_type'])):
11+
if(osm.get_boundaries()['osm_type'][i]=='relation'):
12+
osm_data = OSM(dir_name+map_name+".osm.pbf", osm.get_boundaries()['geometry'][i])
13+
net = osm_data.get_network(network_type="driving")
14+
if net is not None:
15+
net.plot(linewidth=0.5)
16+
plt.axis('off')
17+
plt.savefig('data/output/'+map_name+str(i)+'.png', bbox_inches='tight', pad_inches=0, dpi=400)
18+
19+
20+

readmbtiles.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import mbutil
2+
3+
mbutil.mbtiles_to_disk('data/input/mbtiles/PaloAlto-mbtiles-openmaptiles/PaloAlto.mbtiles', 'data/output/tiles')

sliceimages.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Script to slice up image files as needed.
2+
3+
from PIL import Image
4+
import numpy as np
5+
from matplotlib import image as mpimg
6+
7+
np_image = mpimg.imread('data/output/SanJose3.png')
8+
i=0
9+
10+
11+
12+
13+
14+
15+

0 commit comments

Comments
 (0)