def from_google_directions(origin, destination): """Pulls directions from Google API""" url = 'https://maps.googleapis.com/maps/api/directions/json?origin=' + \ origin + '&destination=' + destination + \ '&key=AIzaSyDNlWzlyeHuRVbWrMSM2ojZm-LzINVcoX4' util.smart_print("url: " + url) raw_directions = urllib2.urlopen(url) string_directions = http_to_string(raw_directions) dict_response = json.loads(string_data) routes = dict_response['routes'] result = [] for route in routes: result.append(Directions(origin, destination, route)) return result
def __init__(self, spatial_lattice, spatial_interpolator, tube_builder): self.spatial_interpolator = spatial_interpolator self.tube_builder = tube_builder self.spatial_base_resolution = spatial_lattice.SPATIAL_BASE_RESOLUTION spatial_degree_constraint = self.compute_spatial_degree_constraint( spatial_lattice) util.smart_print("The edge degree constraint is: " + str(spatial_degree_constraint)) self.spatial_metadata = spatial_lattice.spatial_metadata self.geospatials_to_latlngs = spatial_lattice.geospatials_to_latlngs abstract_edges.AbstractEdgesSets.__init__(self, spatial_lattice, SpatialEdge, spatial_degree_constraint) self.filtered_edges_sets = self.iterative_filter(self.raw_edges_sets) self.build_coordinates() self.finish_edges_sets()
def finish_edges_sets(self): util.smart_print("Now building elevation profiles") t1 = time.time() self.build_elevation_profiles() t2 = time.time() util.smart_print("Finished building elevation profiles in: " + str(t2 - t1) + " seconds.") if self.TUBE_READY: util.smart_print("Now building tube profiles") self.build_tubes() t3 = time.time() util.smart_print("Finished building tube profiles in: " + str(t3 - t2) + " seconds.") self.compute_land_costs()
def get_directions_latlngs(self, route_data): """Applies decoding functions to Google API response""" polyline_directions = self.string_to_polylines(route_data) util.smart_print("Opened directions.") latlngs_with_duplicates = self.decode_polylines(polyline_directions) util.smart_print("Decoded directions.") raw_latlngs = self.remove_duplicates(latlngs_with_duplicates) util.smart_print("Removed duplicate Coordinates.") directions_latlngs = util.round_points(raw_latlngs, 8) directions_latlngs_array = np.array([np.array(latlng) for latlng in directions_latlngs]) return directions_latlngs_array
def iterative_filter(self, edges_sets): edges_sets = self.filter_edges(edges_sets) prefilter_num_edges = util.list_of_lists_len(edges_sets) util.smart_print("The original number of edges: " + str(prefilter_num_edges)) while True: self.determine_useful_edges(edges_sets) edges_sets = self.filter_edges(edges_sets) any_empty_edges_set = self.check_empty(edges_sets) if any_empty_edges_set: raise ValueError("Encountered Empty EdgesSet") postfilter_num_edges = util.list_of_lists_len(edges_sets) if postfilter_num_edges == prefilter_num_edges: util.smart_print("The final number of edges is: " + str(postfilter_num_edges)) break util.smart_print("The current number of edges is: " + str(postfilter_num_edges)) prefilter_num_edges = postfilter_num_edges return edges_sets
def build_spatial_lattice(route_directions): """Build lattice between directions points and spline points """ route_spatial_lattice = spatial_lattice.get_spatial_lattice( route_directions, 6, 4) if config.VISUAL_MODE: util.smart_print("With a base resolution of: " + str(route_spatial_lattice.SPATIAL_BASE_RESOLUTION)+ " meters.") util.smart_print("The resolution parallel to the right of way is: " + str(route_spatial_lattice.parallel_resolution) + " meters.") util.smart_print("The resolution transverse to the right of way is: " + str(route_spatial_lattice.transverse_resolution) + " meters.") if VISUALIZE_SPLINE: plottable_spline = route_spatial_lattice.get_plottable_spline('r-') visualize.PLOT_QUEUE_SPATIAL_2D.append(plottable_spline) if VISUALIZE_DIRECTIONS: plottable_directions = \ route_spatial_lattice.get_plottable_directions('b-') visualize.PLOT_QUEUE_SPATIAL_2D.append(plottable_directions) if VISUALIZE_LATTICE: plottable_lattice = route_spatial_lattice.get_plottable_lattice('g.') visualize.PLOT_QUEUE_SPATIAL_2D.append(plottable_lattice) return route_spatial_lattice
def get_partition_elevations(latlngs_partition): """Gets the elevation at a given lat-lng coord """ coordstring = get_coordstring(latlngs_partition[0]) coord_zipfile = coordstring + ".zip" coord_folder_name = coordstring + "/" url = USGS_FTP_PATH + coord_zipfile download_directory = config.CWD + USGS_FOLDER zip_file_path = download_directory + coord_zipfile unzip_directory = download_directory + coord_folder_name img_file_name = get_img_file_name(coordstring) img_file_path = unzip_directory + img_file_name geotiff_file_path = unzip_directory + coordstring + ".tif" if file_exists(geotiff_file_path): pass else: if file_exists(img_file_path): pass else: if file_exists(zip_file_path): pass else: util.smart_print("Not yet downloaded.") util.smart_print("Now downloading " + coord_zipfile + "...") util.smart_print("From " + str(url)) urllib.urlretrieve(url, zip_file_path) unzip_zipfile(zip_file_path, unzip_directory, img_file_name) remove_file(zip_file_path) img_to_geotiff(img_file_name, unzip_directory, coordstring) remove_file(img_file_path) lnglats = util.swap_pairs(latlngs_partition) partition_elevations = get_geotiff_elevations(geotiff_file_path, lnglats) return partition_elevations