添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
# from some place name, create a GeoDataFrame containing the geometry of the place
city = ox.gdf_from_place('Walnut Creek, California, USA')
# project the geometry to the appropriate UTM zone (calculated automatically) then plot it
city = ox.project_gdf(city)
fig, ax = ox.plot_shape(city)
# define a list of place names
place_names = ['Berkeley, California, USA', 
               'Oakland, California, USA',
               'Piedmont, California, USA',
               'Emeryville, California, USA',
               'Alameda, Alameda County, CA, USA']
# create a GeoDataFrame with rows for each place in the list
east_bay = ox.gdf_from_places(place_names, gdf_name='east_bay_cities')
east_bay
      -122.368679
      POLYGON ((-122.3686792 37.8695716, -122.366813...
      Berkeley, Alameda County, California, United S...
      -122.114672
      37.885368
      37.632226
      -122.355881
      POLYGON ((-122.3558809 37.835727, -122.3301568...
      Oakland, Alameda County, California, United St...
      -122.210148
      37.833026
      37.812276
      -122.249374
      POLYGON ((-122.2493739 37.823649, -122.2491229...
      Piedmont, Alameda County, California, United S...
      -122.276012
      37.849973
      37.827075
      -122.330157
      POLYGON ((-122.3301568 37.841078, -122.3243159...
      Emeryville, Alameda County, California, United...
      -122.223859
      37.800628
      37.707621
      -122.340281
      POLYGON ((-122.3402809 37.800628, -122.3351599...
      Alameda, Alameda County, California, United St...
# project the geometry to the appropriate UTM zone then plot it
east_bay = ox.project_gdf(east_bay)
fig, ax = ox.plot_shape(east_bay)
# pass in buffer_dist in meters
city_buffered = ox.gdf_from_place('Walnut Creek, California, USA', buffer_dist=250)
fig, ax = ox.plot_shape(city_buffered)
# you can buffer multiple places in a single query
east_bay_buffered = ox.gdf_from_places(place_names, gdf_name='east_bay_cities', buffer_dist=250)
fig, ax = ox.plot_shape(east_bay_buffered, alpha=0.7)
gdf = ox.gdf_from_place('Manhattan, New York, New York, USA')
gdf = ox.project_gdf(gdf)
fig, ax = ox.plot_shape(gdf)
gdf = ox.gdf_from_place('Cook County, Illinois, United States')
gdf = ox.project_gdf(gdf)
fig, ax = ox.plot_shape(gdf)
gdf = ox.gdf_from_places(['United Kingdom', 'Ireland'])
gdf = ox.project_gdf(gdf)
fig, ax = ox.plot_shape(gdf)

Be careful to pass the right place name that OSM needs

Be specific and explicit, and sanity check the results. The function logs a warning if you get a point returned instead of a polygon. In the first example below, OSM resolves 'Melbourne, Victoria, Australia' to a single point at the center of the city. In the second example below, OSM correctly resolves 'City of Melbourne, Victoria, Australia' to the entire city and returns its polygon geometry.

melbourne = ox.gdf_from_place('Melbourne, Victoria, Australia')
melbourne = ox.project_gdf(melbourne)
type(melbourne['geometry'].iloc[0])
melbourne = ox.gdf_from_place('City of Melbourne, Victoria, Australia')
melbourne = ox.project_gdf(melbourne)
fig, ax = ox.plot_shape(melbourne)

OSM resolves 'Mexico' to Mexico City and returns a single point at the center of the city. Instead we have a couple options:

  • We can pass a dict containing a structured query to specify that we want Mexico the country instead of Mexico the city.
  • We can also get multiple countries by passing a list of queries. These can be a mixture of strings and dicts.
  •