def getChangchunReign(): city = ox.gdf_from_places( ['南关区,长春,中国', '朝阳区,长春,中国', '二道区,长春,中国', '绿园区,长春,中国', '宽城区,长春,中国']) city = ox.project_gdf(city) ox.save_gdf_shapefile(city, filename='test1') #save ox.plot_shape(city) #show
def get_bearings(places): try: gdf = ox.gdf_from_places(places.values()) except Exception as e: print(f'Failed to load city data: {e}') bearings = { place: get_bearing(place, places[place]) for place in sorted(places.keys()) } return {key: value for key, value in bearings.items() if value is not None}
def plot_india_map(state_dict: dict): all_states = [] for k in state_dict: all_states.append({"state": k}) try: values = [x / max(state_dict.values()) for x in state_dict.values()] except ZeroDivisionError: values = [0] * len(all_states) places = ox.gdf_from_places(all_states) places = ox.project_gdf(places) ox.plot_shape(places, ec="w", fc=get_colors(values))
def mad_lakes(): global _lakes if _lakes is not None: return _lakes try: import osmnx as ox except ImportError: return None _lakes = ox.gdf_from_places([ 'Lake Mendota, Dane County, WI', 'Lake Monona, Dane County, WI', 'Lake Wingra, Dane County, WI', 'Second Lake, Dane County, WI', 'Lower Mud Lake, Dane County, WI', 'Upper Mud Lake, Dane County, WI', ]) _lakes = _lakes.append( ox.gdf_from_place('Yahara River, Dane County, WI', which_result=5), ) _lakes = _lakes.to_crs(epsg=3857) return _lakes
import pandas as pd ox.config(log_console=True, use_cache=True) weight_by_length = False ox.__version__ places = { 'Albany': 'Albany County, NY, USA', 'Schenectady': 'Schenectady County, NY, USA', 'Troy': 'Rensselaer County, NY, USA', 'Saratoga': 'Saratoga County, NY, USA' } # verify OSMnx geocodes each query to what you expect gdf = ox.gdf_from_places(places.values()) gdf def reverse_bearing(x): return x + 180 if x < 180 else x - 180 from datetime import datetime start = datetime.now() bearings = {} for place in sorted(places.keys()): # get the graph
import osmnx as ox, geopandas as gpd ox.config(log_file=True, log_console=True, use_cache=True) location_point = (-17.1010286, 145.7753749) gdf = ox.buildings_from_point(point=location_point, distance=5000) gdf_proj = ox.project_gdf(gdf) bbox = ox.bbox_from_point(point=location_point, distance=5000, project_utm=True) fig, ax = ox.plot_buildings(gdf_proj) import osmnx as ox, geopandas as gpd ox.config(log_file=True, log_console=True, use_cache=True) place_names = ['Gordonvale, Queensland, Australia'] east_bay = ox.gdf_from_places(place_names) ox.save_gdf_shapefile(east_bay) east_bay = ox.project_gdf(east_bay) fig, ax = ox.plot_shape(east_bay) import osmnx as ox ox.config(log_file=True, log_console=True, use_cache=True) city = ox.gdf_from_place('Sydney, New South Wales, Australia') city ox.save_gdf_shapefile(city) city = ox.project_gdf(city) fig, ax = ox.plot_shape(city) import osmnx as ox from IPython.display import Image ox.config(log_console=True, use_cache=True)
#!/usr/bin/env python # coding: utf-8 # In[5]: import osmnx as ox city = ox.gdf_from_place('Berkeley, California') ox.plot_shape(ox.project_gdf(city)) # In[10]: places = ox.gdf_from_places(['Botswana', 'Zambia', 'Zimbabwe']) places = ox.project_gdf(places) ox.save_gdf_shapefile(places) ox.plot_shape(ox.project_gdf(places)) # In[11]: G = ox.graph_from_bbox(37.79, 37.78, -122.41, -122.43, network_type='drive') G_projected = ox.project_graph(G) ox.plot_graph(G_projected) # In[12]:
args = sys.argv[1:] juris = args[0] # this is nasty - these are cities without building footprints in OSM # that crashes osmnx (at the time of this writing) - so we switch to a # city that doesn't crash and the joins will fail in the next step # but it gives enough for the the process to proceed fetch_juris = juris if juris != "Ross" else "San Anselmo" print "Fetching buildings from OSM", time.ctime() jurises = gpd.GeoDataFrame.from_file("data/juris.geojson") print "Fetching for:", juris if "Unincorporated" in juris: place = osmnx.gdf_from_places([ juris.replace("Unincorporated ", "") + " County, California, United States" ]) else: # I was a little worried the OSM definitions of the cities aren't the # same as ours so we use our shapes for the jurises place = jurises[jurises.NAME10 == fetch_juris] buildings = osmnx.buildings.create_buildings_gdf(place.iloc[0].geometry) print "Done fetching buildings", time.ctime() print "Len buildings: %d" % len(buildings) print "Keeping buildings completely within this city" is_within = buildings.within(place.iloc[0].geometry) buildings = buildings[is_within] print "Len buildings: %d" % len(buildings)
place_names = [] filename = 'cityList.csv' with open(filename) as f: reader = csv.reader(f) places = list(reader) for place in places: if(place[1] == 'yanbianzhou'): place_names.append('yanbian'+','+place[2]+','+place[3]) elif(place[1] == 'daxinganlingdiqu'): place_names.append('daxinganling'+','+place[2]+','+place[3]) else: place_names.append(place[1]+','+place[2]+','+place[3]) print(place_names) dongSanSheng = ox.gdf_from_places(place_names, gdf_name='dongSanSheng_city') print(dongSanSheng) dongSanSheng_city_byPoint = GeoDataFrame([{'geometry':None,'place_name':None}]) for city_polygon,city_name,e,w,n,s in zip(dongSanSheng['geometry'],dongSanSheng['place_name'],dongSanSheng['bbox_east'],dongSanSheng['bbox_west'],dongSanSheng['bbox_north'],dongSanSheng['bbox_south']): placeName = city_name.split(',')[0] placeName = placeName.split('/') print(placeName) if len(placeName) > 1 and placeName[1].strip() == '白山市': placeName = '白山市' else: placeName = placeName[0].strip() if isinstance(city_polygon, (Polygon, MultiPolygon)):
def fetch_counties_gdf(): names = ["{} County, California, USA".format(county) for county in COUNTIES] result = ox.gdf_from_places(names, gdf_name="counties") return result