Skip to content

Commit

Permalink
Merge branch 'master' into jax-start
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbaldridge committed Sep 21, 2020
2 parents dab819b + c39a0b8 commit 2659d13
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 468 deletions.
3 changes: 0 additions & 3 deletions bologna.json

This file was deleted.

Empty file removed bologna_dev.json
Empty file.
1 change: 0 additions & 1 deletion bologna_test.json

This file was deleted.

2 changes: 0 additions & 2 deletions bologna_train.json

This file was deleted.

12 changes: 4 additions & 8 deletions cabby/geo/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ py_library(
srcs = ['walk.py'],
deps = [
':util',
':item',
'//cabby/rvs:item',
':geo_item',
'//cabby/geo/map_processing:map_structure',

Expand All @@ -25,7 +25,7 @@ py_test(
srcs = ["walk_test.py"],
python_version = "PY3",
deps = [
':item',
'//cabby/rvs:item',
':geo_item',
":walk",
"//cabby/geo/map_processing:map_structure",
Expand All @@ -49,10 +49,6 @@ py_library(
],
)

py_library(
name = 'item',
srcs = ['item.py'],
)

py_library(
name = 'geo_item',
Expand All @@ -68,7 +64,7 @@ py_binary(
deps = [
':walk',
':util',
':item',
'//cabby/rvs:item',
':geo_item',
"//cabby:logger"
],
Expand Down Expand Up @@ -96,7 +92,7 @@ py_binary(
deps = [
':walk',
':util',
':item',
'//cabby/rvs:item',
':geo_item',
"//cabby:logger",
],
Expand Down
12 changes: 8 additions & 4 deletions cabby/geo/map_processing/map_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

map_logger = logger.create_logger("map.log", 'map')

OSM_CRS = 4326 # Coordinate reference system.
OSM_CRS = 32633 # UTM Zones (North).

class Map:

Expand Down Expand Up @@ -72,8 +72,9 @@ def __init__(self, map_name: Text, level: int, load_directory: Text = None):
self.load_map(load_directory)
self.create_S2Graph(level)

self.nodes = self.nodes.set_crs(epsg=OSM_CRS)
self.edges = self.edges.set_crs(epsg=OSM_CRS)

self.nodes = self.nodes.set_crs(epsg=OSM_CRS, allow_override=True)
self.edges = self.edges.set_crs(epsg=OSM_CRS, allow_override=True)

def closest_nodes(self, point: Point) -> int:
'''Find closest nodes to POI.
Expand All @@ -98,6 +99,8 @@ def get_poi(self) -> Tuple[GeoSeries, GeoSeries]:
osm_poi_streets = osm_poi_named_entities[osm_highway.notnull()]

# Get centroid for POI.
osm_poi_no_streets = osm_poi_no_streets.set_crs(epsg=OSM_CRS,
allow_override=True)
osm_poi_no_streets['centroid'] = osm_poi_no_streets['geometry'].apply(
lambda x: x if isinstance(x, Point) else x.centroid)

Expand Down Expand Up @@ -137,7 +140,8 @@ def create_S2Graph(self, level: int):
self.poi['cellids'] = self.poi['geometry'].apply(self.get_cellids_for_poi)

# Get cellids for streets.
self.streets['cellids'] = self.streets['geometry'].apply(self.get_cellids_for_streets)
self.streets['cellids'] = self.streets['geometry'].apply(self.
get_cellids_for_streets)

# Filter out entities that we didn't mange to get cellids covering.
self.poi = self.poi[self.poi['cellids'].notnull()]
Expand Down
Binary file modified cabby/geo/pathData/pittsburgh_geo_paths.gpkg
Binary file not shown.
22 changes: 10 additions & 12 deletions cabby/geo/plot.ipynb

Large diffs are not rendered by default.

80 changes: 47 additions & 33 deletions cabby/geo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from s2geometry import pywraps2 as s2
from shapely.geometry.point import Point
from shapely.geometry.polygon import Polygon
from typing import Optional, Tuple, Sequence
from typing import Optional, Tuple, Sequence, Any
import webbrowser


Expand Down Expand Up @@ -235,49 +235,63 @@ def get_distance_km(start: Point, goal: Point) -> float:


def tuple_from_point(point: Point) -> Tuple[float, float]:
'''Convert a Point into a tuple, with latitude as first element, and
longitude as second.
Arguments:
point(Point): A lat-lng point.
Returns:
A lat-lng Tuple[float, float].
'''
'''Convert a Point into a tuple, with latitude as first element, and
longitude as second.
Arguments:
point(Point): A lat-lng point.
Returns:
A lat-lng Tuple[float, float].
'''

return (point.y, point.x)
return (point.y, point.x)


def list_xy_from_point(point: Point) -> Sequence[float]:
'''Convert a Point into a sequence, with longitude as first element, and
latitude as second.
'''Convert a Point into a sequence, with longitude as first element, and
latitude as second.
Arguments:
point(Point): A lat-lng point.
Returns:
A lng-lat Sequence[float, float].
'''
Arguments:
point(Point): A lat-lng point.
Returns:
A lng-lat Sequence[float, float].
'''

return [point.x, point.y]
return [point.x, point.y]


def list_yx_from_point(point: Point) -> Sequence[float]:
'''Convert a Point into a sequence, with latitude as first element, and longitude as second.
'''Convert a Point into a sequence, with latitude as first element, and longitude as second.
Arguments:
point(Point): A lat-lng point.
Returns:
A lat-lng Sequence[float, float].
'''
Arguments:
point(Point): A lat-lng point.
Returns:
A lat-lng Sequence[float, float].
'''

return [point.y, point.x]
return [point.y, point.x]


def midpoint(p1: Point, p2: Point) -> Point:
'''Get the midpoint between two points.
Arguments:
p1(Point): A lat-lng point.
p2(Point): A lat-lng point.
Returns:
A lat-lng Point.
'''
return Point((p1.x+p2.x)/2, (p1.y+p2.y)/2)
'''Get the midpoint between two points.
Arguments:
p1(Point): A lat-lng point.
p2(Point): A lat-lng point.
Returns:
A lat-lng Point.
'''
return Point((p1.x+p2.x)/2, (p1.y+p2.y)/2)


def check_if_geometry_in_polygon(geometry: Any, poly: Polygon) -> Polygon:
'''Check if geometry is intersects with polygon.
Arguments:
geometry: The geometry to check intersection against a polygon.
poly: The polygon that to check intersection against a geometry.
Returns:
A lat-lng Point.
'''
if isinstance(geometry, Point):
return poly.contains(geometry)
else:
geometry['geometry'].intersects(poly)
4 changes: 2 additions & 2 deletions cabby/geo/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def get_osm_map(gdf: gpd.GeoDataFrame) -> Sequence[folium.Map]:
'''

mid_point = util.midpoint(gdf.end_point, gdf.start_point)
zoom_location = util.list_yx_from_point(gdf.end_point)
zoom_location = util.list_yx_from_point(mid_point)

# create a map
map_osm = folium.Map(location=zoom_location,
zoom_start=18, tiles='OpenStreetMap')
zoom_start=15, tiles='OpenStreetMap')

# draw the points
start_point = util.list_yx_from_point(gdf.start_point)
Expand Down
Loading

0 comments on commit 2659d13

Please sign in to comment.