def test_plots(): G = ox.graph_from_place('Piedmont, California, USA', network_type='drive', simplify=False) G2 = ox.simplify_graph(G, strict=False) # test getting colors co = ox.get_colors(n=5, return_hex=True) nc = ox.get_node_colors_by_attr(G2, 'osmid') ec = ox.get_edge_colors_by_attr(G2, 'length') # save a plot to disk as png fig, ax = ox.plot_graph(G, save=True, file_format='png') # save a plot to disk as svg G_simplified = ox.simplify_graph(G) fig, ax = ox.plot_graph(G_simplified, show=False, save=True, close=True, file_format='svg') G_projected = ox.project_graph(G_simplified) fig, ax = ox.plot_graph(G_projected) fig, ax = ox.plot_graph(G_projected, fig_height=5, fig_width=5, margin=0.05, axis_off=False, bgcolor='y', file_format='png', filename='x', dpi=180, annotate=True, node_color='k', node_size=5, node_alpha=0.1, node_edgecolor='b', node_zorder=5, edge_color='r', edge_linewidth=2, edge_alpha=0.1, use_geom=False, show=False, save=True, close=True) fig, ax = ox.plot_figure_ground(G=G_simplified, file_format='png') fig, ax = ox.plot_figure_ground(point=(33.694981, -117.841375), file_format='png') fig, ax = ox.plot_figure_ground(address='Denver, Colorado, USA', file_format='png')
def test_plots(): G = ox.graph_from_point(location_point, dist=500, network_type="drive") # test getting colors co = ox.plot.get_colors(n=5, return_hex=True) nc = ox.plot.get_node_colors_by_attr(G, "x") ec = ox.plot.get_edge_colors_by_attr(G, "length", num_bins=5) # plot and save to disk filepath = Path(ox.settings.data_folder) / "test.svg" fig, ax = ox.plot_graph(G, show=False, save=True, close=True, filepath=filepath) fig, ax = ox.plot_graph( G, figsize=(5, 5), bgcolor="y", dpi=180, node_color="k", node_size=5, node_alpha=0.1, node_edgecolor="b", node_zorder=5, edge_color="r", edge_linewidth=2, edge_alpha=0.1, show=False, save=True, close=True, ) # figure-ground plots fig, ax = ox.plot_figure_ground(G=G) fig, ax = ox.plot_figure_ground(point=location_point, dist=500, network_type="drive") fig, ax = ox.plot_figure_ground(address=address, dist=500, network_type="bike")
def test_plots(): G = ox.graph_from_point(location_point, dist=500, network_type="drive") # test getting colors co = ox.plot.get_colors(n=5, return_hex=True) nc = ox.plot.get_node_colors_by_attr(G, "osmid") ec = ox.plot.get_edge_colors_by_attr(G, "length") # plot and save to disk fig, ax = ox.plot_graph(G, save=True, file_format="png") fig, ax = ox.plot_graph(G, show=False, save=True, close=True, file_format="svg") fig, ax = ox.plot_graph( ox.project_graph(G), fig_height=5, fig_width=5, margin=0.05, axis_off=False, bgcolor="y", file_format="png", filename="x", dpi=180, annotate=True, node_color="k", node_size=5, node_alpha=0.1, node_edgecolor="b", node_zorder=5, edge_color="r", edge_linewidth=2, edge_alpha=0.1, use_geom=False, show=False, save=True, close=True, ) # figure-ground plots fig, ax = ox.plot_figure_ground(G=G, file_format="png") fig, ax = ox.plot_figure_ground(point=location_point, dist=500, network_type="drive", file_format="png") fig, ax = ox.plot_figure_ground(address=address, dist=500, network_type="bike", file_format="png")
def make_plot(place, point, network_type='drive', bldg_color='orange', dpi=40, dist=805, default_width=4, street_widths=None): gdf = ox.buildings_from_point(point=point, distance=dist) gdf_proj = ox.project_gdf(gdf) fig, ax = ox.plot_figure_ground(point=point, dist=dist, network_type=network_type, default_width=default_width, street_widths=street_widths, save=False, show=False, close=True) fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=bldg_color, set_bounds=False, save=True, show=False, close=True, filename=place, dpi=dpi)
def make_plot(place, point, network_type="drive", edge_color="#FFD500", bldg_color="#3B14AF", bg_colour="#082368", dpi=40, dist=805, default_width=4, street_widths=None): gdf = ox.buildings_from_point(point=point, distance=dist) gdf_proj = ox.project_gdf(gdf) fig, ax = ox.plot_figure_ground(point=point, dist=dist, network_type=network_type, default_width=default_width, street_widths=street_widths, edge_color=edge_color, bgcolor=bg_colour, save=False, show=False, close=True) fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=bldg_color, set_bounds=False, save=True, show=False, close=True, filename=place, dpi=dpi)
def get_sqml_plot(place, point, network_type='drive', bldg_color='orange', dpi=300, dist=1200, default_width=4, street_widths=None): gdf = ox.footprints.footprints_from_point(point=point, distance=dist) fig, ax = ox.plot_figure_ground(point=point, dist=dist, network_type=network_type, default_width=default_width, street_widths=street_widths, save=False, show=False, close=True) fig, ax = ox.footprints.plot_footprints(gdf, fig=fig, ax=ax, color=bldg_color, set_bounds=False, save=True, show=False, close=True, filename=place, dpi=dpi)
def create_map(list): for city in list: img_folder = 'images' extension = 'png' size = 300 dpi = 150 fig, ax = ox.plot_figure_ground(address=city, filename=city, dpi=dpi) Image('{}.{}'.format(city, extension), height=size, width=size)
def plot_map(self, start_point, distance, type_, footprint=None): _, self._ax = ox.plot_figure_ground(point=start_point, dist=distance, network_type=type_, bgcolor=self.COLOR_BACKGROUND, default_width=4, figsize=self.FIGSIZE, show=False, close=False) if footprint is not None: footprint.plot(ax=self._ax, color=self.COLOR_FOOTPRINT, alpha=0.75)
# -*- coding: utf-8 -*- """ Created on Thu Jul 13 14:26:54 2017 @author: yangjinyue """ import osmnx as ox from IPython.display import Image ox.config(log_file=True, log_console=True, use_cache=True) img_folder = 'images' extension = 'png' size = 800 place = 'chongqing' point = (42.911968, 129.51879) fig, ax = ox.plot_figure_ground(point=point, dist=2000, filename=place, network_type='all', dpi=150) Image('{}/{}.{}'.format(img_folder, place, extension), height=size, width=size)
'steps': 0.5, 'pedestrian': 0.5, 'path': 0.5, 'track': 0.75, 'service': 1.5, 'residential': 2.5, 'primary': 2.5, 'motorway': 3 } # create diagrams by passing in lat-long points place = 'Berlin-Home' point = (52.529556, 13.345430) fig, ax = ox.plot_figure_ground(point=point, filename=place, network_type='all', street_widths=street_widths, dpi=dpi) Image('{}/{}.{}'.format(img_folder, place, extension), height=size, width=size) place = 'Berlin-Work' point = (52.506396, 13.521521) fig, ax = ox.plot_figure_ground(point=point, filename=place, network_type='all', street_widths=street_widths, dpi=dpi) Image('{}/{}.{}'.format(img_folder, place, extension), height=size, width=size) place = 'SanFrancisco' point = (37.793897, -122.402189)
def create_map_from_osm(outfile: str, c_osm: int, north: float, south: float, west: float, east: float): dpi = 200 default_width = 6 network_type = 'drive' fp = f'./images/{outfile}-osm-{c_osm}.png' tag_building = TagTypes.building tag_nature = TagTypes.nature tag_water = TagTypes.water ax = None G = ox.graph_from_bbox(north, south, east, west, network_type=network_type, truncate_by_edge=True, retain_all=True, clean_periphery=False) gdf_building = ox.geometries_from_bbox(north, south, east, west, tags=tag_building) gdf_nature = ox.geometries_from_bbox(north, south, east, west, tags=tag_nature) gdf_water = ox.geometries_from_bbox(north, south, east, west, tags=tag_water) fig, ax = ox.plot_figure_ground(G, default_width=default_width, dpi=dpi, filepath=fp, show=False) if not gdf_nature.empty: fig, ax = ox.plot_footprints(gdf_nature, ax=ax, color='green', filepath=fp, dpi=dpi, save=True) if not gdf_water.empty: fig, ax = ox.plot_footprints(gdf_water, ax=ax, color='blue', filepath=fp, dpi=dpi, save=True) if not gdf_building.empty: fig, ax = ox.plot_footprints(gdf_building, ax=ax, filepath=fp, dpi=dpi, save=True)
def create_square_from_osm(crop_size: float, crop_status: bool, outfile: str, c_osm: int, point, dpi=100, dist=2000, default_width=6): """ :param crop_size: Crop size of the output :param crop_status: Determine whether the output will be cropped or not :param outfile: Outfile name :param c_osm: count of osm image :param point: (lat, long) :param dpi: dpi for the output image :param dist: distance from the given point :param default_width: default width for the roads :return: """ network_type = 'drive' fp = f'./images/{outfile}-osm-{c_osm}.png' tag_building = TagTypes.building tag_nature = TagTypes.nature tag_water = TagTypes.water bbox = ox.utils_geo.bbox_from_point(point, dist=dist) try: G = ox.graph_from_point(point, network_type=network_type, dist=dist, truncate_by_edge=True, retain_all=True, clean_periphery=True) gdf_building = ox.geometries_from_point(point, tag_building, dist=dist) gdf_nature = ox.geometries_from_point(point, tag_nature, dist=dist) gdf_water = ox.geometries_from_point(point, tag_water, dist=dist) fig, ax = ox.plot_figure_ground(G, default_width=default_width, show=False, close=True) if not gdf_nature.empty: # print('nature') fig, ax = ox.plot_footprints(gdf_nature, ax=ax, bbox=bbox, color='green', filepath=fp, dpi=dpi, show=False, save=True, close=True) if not gdf_water.empty: # print('water') fig, ax = ox.plot_footprints(gdf_water, ax=ax, bbox=bbox, color='blue', filepath=fp, dpi=dpi, show=False, save=True, close=True) if not gdf_building.empty: # print('building') fig, ax = ox.plot_footprints(gdf_building, ax=ax, bbox=bbox, filepath=fp, dpi=dpi, save=True, show=False, close=True) if crop_status: image = Image.open(fp) image = crop_image(image=image, size=crop_size) image.save(f"./images/{outfile}-osm-{c_osm}.png") return True except: return False
def plot(self, x=None, size=9, name='temp_image', network_type='walk', dpi=90, default_width=5, street_widths=None): """ plot the map Parameters - x(model.x): default None, variables x after optimization size(int) : default 9 name(string) : default 'temp_image', the saved image name network_type(string) : default walk dpi(int) : default 90 default_width(int) : default 5 street_widths(int) : default None """ # default color set - before optimization ec = [] for i in self.gdf.index: # white color for vacant houses if self.gdf['housetype'][i] == 2: ec.append('w') # yellow color for police station elif self.gdf['amenity'][i] == 'police': ec.append('yellow') # light green for curch elif self.gdf['amenity'][i] == 'place_of_worship': ec.append('#d7ff6e') # red color for non structure elif self.gdf['building'][i] != 'yes': ec.append('r') # #ff6060 for area > 398 elif (pd.isnull(self.gdf['addr:street'][i]) and self.gdf_proj.area[i] > 398) or self.gdf_proj.area[i] > 398: ec.append('#ff6060') # #8e8e8e for no address elif pd.isnull(self.gdf['addr:street'][i]): ec.append('#8e8e8e') # #ffcf77 for renter houses elif self.gdf['housetype'][i] == 0: ec.append('#ffcf77') # #ffcf77 for owner houses elif self.gdf['housetype'][i] == 1: ec.append('orange') # blue coloe fo o.w., which means the model is not correct else: ec.append('blue') # plot the original map before optimization if x == None: #ox.plot_buildings(self.gdf, figsize = (size,size) ,color = ec, bgcolor = "aliceblue") # get gdf_proj gdf_proj = ox.project_gdf(self.gdf) # initial figure ground fig, ax = ox.plot_figure_ground(address=self.address, dist=self.radius, network_type=network_type, default_width=default_width, bgcolor='#333333', edge_color='w', street_widths=street_widths, save=False, show=False, close=True, fig_length=size) # plot the building fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=ec, set_bounds=True, save=True, show=False, close=True, filename=name, dpi=dpi) # save image Image('{}/{}.{}'.format(img_folder, name, extension), height=image_size, width=image_size) return fig, ax # after optimization else: # update color set # if x == 1 or very close to 1 (tolerance) ec_after = [ 'mediumseagreen' if x[self.Houses[i]].X == 1.0 or abs(x[self.Houses[i]].X - 1.0) < 0.000001 else ec[i] for i in xrange(len(self.Houses)) ] # get gdf_proj gdf_proj = ox.project_gdf(self.gdf) # initial figure ground fig, ax = ox.plot_figure_ground(address=self.address, dist=self.radius, network_type=network_type, default_width=default_width, bgcolor='#333333', edge_color='w', street_widths=street_widths, save=False, show=False, close=True, fig_length=size) # plot the building fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=ec_after, set_bounds=True, save=True, show=False, close=True, filename=name, dpi=dpi) # save image Image('{}/{}.{}'.format(img_folder, name, extension), height=image_size, width=image_size) return fig, ax