Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull latest gboeing master into geometry #14

Merged
merged 8 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osmnx/geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def geocode_to_gdf(query, which_result=None, buffer_dist=None):

# if caller passed a list of queries but a scalar which_result value, then
# turn which_result into a list with same length as query list
if isinstance(query, list) and isinstance(which_result, int):
if isinstance(query, list) and (isinstance(which_result, int) or which_result is None):
which_result = [which_result] * len(query)

# turn query and which_result into lists if they're not already
Expand Down
52 changes: 22 additions & 30 deletions osmnx/utils_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,53 +395,45 @@ def _intersect_index_quadrats(points, geometry, quadrat_width=0.05, min_num=3):

def bbox_from_point(point, dist=1000, project_utm=False, return_crs=False):
"""
Create a bounding box from a point.
Create a bounding box from a (lat, lng) center point.

Create a bounding box some distance in each direction (north, south, east,
and west) from some (lat, lng) point.
and west) from the center point and optionally project it.

Parameters
----------
point : tuple
the (lat, lng) point to create the bounding box around
the (lat, lng) center point to create the bounding box around
dist : int
how many meters the north, south, east, and west sides of the box should
each be from the point
bounding box distance in meters from the center point
project_utm : bool
if True return bbox as UTM coordinates
if True, return bounding box as UTM-projected coordinates
return_crs : bool
if True and project_utm=True, return the projected CRS
if True, and project_utm=True, return the projected CRS too

Returns
-------
tuple
(north, south, east, west) if return_crs=False or
(north, south, east, west, crs_proj) if return_crs=True
(north, south, east, west) or (north, south, east, west, crs_proj)
"""
# reverse the order of the (lat,lng) point so it is (x,y) for shapely, then
# project to UTM and buffer in meters
earth_radius = 6371009 # meters
lat, lng = point
point_proj, crs_proj = projection.project_geometry(Point((lng, lat)))
buffer_proj = point_proj.buffer(dist)

delta_lat = (dist / earth_radius) * (180 / math.pi)
delta_lng = (dist / earth_radius) * (180 / math.pi) / math.cos(lat * math.pi / 180)
north = lat + delta_lat
south = lat - delta_lat
east = lng + delta_lng
west = lng - delta_lng

if project_utm:
west, south, east, north = buffer_proj.bounds
utils.log(
f"Created bbox {dist} m from {point} and projected it: {north},{south},{east},{west}"
)
else:
# if project_utm is False, project back to lat-lng then get the
# bounding coordinates
buffer_latlong, _ = projection.project_geometry(buffer_proj, crs=crs_proj, to_latlong=True)
west, south, east, north = buffer_latlong.bounds
utils.log(
(
f"Created bounding box {dist} meters in each direction "
f"from {point}: {north},{south},{east},{west}"
)
)

if return_crs:
bbox_poly = bbox_to_poly(north, south, east, west)
bbox_proj, crs_proj = projection.project_geometry(bbox_poly)
west, south, east, north = bbox_proj.bounds

utils.log(f"Created bbox {dist} m from {point}: {north},{south},{east},{west}")

if project_utm and return_crs:
return north, south, east, west, crs_proj
else:
return north, south, east, west
Expand Down
2 changes: 1 addition & 1 deletion osmnx/utils_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def k_shortest_paths(G, orig, dest, k, weight="length"):

def induce_subgraph(G, node_subset):
"""
Induce a subgraph of G.
Induce a subgraph of G: deprecated, do not use.

Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions tests/test_osmnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def test_network_saving_loading():
def test_get_network_methods():

# graph from bounding box
_ = ox.utils_geo.bbox_from_point(location_point, project_utm=True, return_crs=True)
north, south, east, west = ox.utils_geo.bbox_from_point(location_point, dist=500)
G = ox.graph_from_bbox(north, south, east, west, network_type="drive")
G = ox.graph_from_bbox(
Expand Down