def search_nodes(map): if len(map.nodeList) > 0: valid, lat, lon = parse_gps() if not valid: return dlist = map.generate_dlist(lat, lon) dlist_sorted = sorted(dlist) show_type = input("Show (1) nodes closer than a certain distance, or (2) given number of closest nodes: ") show_num = 0 if show_type == '1': keepTrying = 'y' while keepTrying == 'y': dist_str = input("Show nodes closer than the following distance (in feet): ") try: dist_num = int(dist_str) show_num = sum([CvtdUtil.coord_to_ft(y) < dist_num for y in dlist]) show = input(f"Show {show_num} entries (y/n): ") if show == 'y': print(f"Showing {show_num} nodes within {dist_num} feet of {lat}, {lon}") for i in range(show_num): dlist_ix = dlist.index(dlist_sorted[i]) e = round(CvtdUtil.coord_to_ft(dlist_sorted[i]), 3) print(f"{i+1}: {map.nodeList[dlist_ix].lat}, {map.nodeList[dlist_ix].lon} ({e} feet)") keepTrying = 'n' else: keepTrying = input("Try again (y/n): ") except ValueError: keepTrying = input(f"Error: Could not convert ${show_str} to an integer. Try again (y/n): ") elif show_type == '2': nnodes = len(map.nodeList) show_str = input(f"Show how many entries (max {nnodes}): ") try: show_num = min(int(show_str), nnodes) print(f"Showing {show_num} nodes close to {lat}, {lon}") for i in range(show_num): dlist_ix = dlist.index(dlist_sorted[i]) e = round(dlist_sorted[i]*70*5280, 3) print(f"{i+1}: {map.nodeList[dlist_ix].lat}, {map.nodeList[dlist_ix].lon} ({e} feet)") except ValueError: print(f"Error: Could not convert ${show_str} to an integer") # Now, let them choose one of these nodes if show_num > 0: while True: try: node_info = int(input(f"Get more info about a node (1-{show_num}) or (n)o: ")) if 1 <= node_info <= show_num: plist = map.get_node_usage(dlist.index(dlist_sorted[node_info - 1])) if len(plist) > 0: print("The following roads use this node: ") for p in plist: print(p.addr_repr(map.roadList)) else: break except ValueError: break else: print("No nodes have been added, you might want to read roads.txt (key 'r')")
def add_to_print_list(myMap, locator, print_list, rid, ix): try: position = locator.pos[rid][ix] t = position.timestamp lat = position.lat lon = position.lon dir = position.direction except IndexError: return # Determine route try: route = myMap.routeDict[rid] routeName = route.routeShortName # validStreets = route.get_street_list() except KeyError: routeName = "Unknown Route" # validStreets = None validStreets = None # Compute address # roadIx, addr, error = myMap.compute_addr_repr(lat, lon, validStreets) roadIx, addr, error = myMap.compute_addr_repr(lat, lon, None) if validStreets is not None and error > 250: roadIx, addr_off_route, error_off_route = myMap.compute_addr_repr( lat, lon, None) if error_off_route < 200: addr = "!" + addr_off_route error = error_off_route error = round(error) # Determine if direction is actual or if it should be X try: lat_to_lat_diff = CvtdUtil.coord_to_ft( abs(locator.pos[rid][ix - 1].lat - lat)) lon_to_lon_diff = CvtdUtil.coord_to_ft( abs(locator.pos[rid][ix - 1].lon - lon)) pos_to_pos_diff = math.sqrt(lat_to_lat_diff**2 + lon_to_lon_diff**2) if (pos_to_pos_diff < 40): dir = Direction.X else: dir = direction.get_direction(dir) except IndexError: dir = direction.get_direction(dir) # Add to list to print later try: print_list[rid].append([t, addr, error, dir]) except KeyError: print_list[rid] = [routeName] print_list[rid].append([t, addr, error, dir])
def choose_gps(map): valid, lat, lon = parse_gps() if not valid: return False node_ix = len(map.nodeList) dlist = map.generate_dlist(lat, lon) dlist_sorted = sorted(dlist) node_count = sum([CvtdUtil.coord_to_ft(y) < 150 for y in dlist]) if node_count > 0: print(f"The following {node_count} nodes already exist close to the location you entered:") for i in range(node_count): dlist_ix = dlist.index(dlist_sorted[i]) print(f"{i+1}: {map.nodeList[dlist_ix].lat}, {map.nodeList[dlist_ix].lon} ({CvtdUtil.coord_to_ft(dlist_sorted[i])} feet)") usenode = input("Use instead any of these nodes? Enter 'n' or number: ") try: usenode = int(usenode) if 1 <= usenode <= node_count: plist = map.get_node_usage(dlist_ix) if len(plist) > 0: print("The following roads use this node: ") for point in plist: print(p.addr_repr(map.roadList)) okay = input("Okay (y/n): ") if okay.lower() != 'y': return None else: lat = map.nodeList[dlist_ix].lat lon = map.nodeList[dlist_ix].lon node_ix = dlist_ix except ValueError: # node_ix, lat and lot already have their desired values pass return node_ix, lat, lon
def compute_addr(self, lat, lon, nodeDict): point_ix, proj_ratio, error = self.compute_proj_ratio( lat, lon, nodeDict) vaddr_begin = self.points[point_ix].addr vaddr_end = self.points[point_ix + 1].addr address = round(proj_ratio * (vaddr_end - vaddr_begin) + vaddr_begin) addrRepr = CvtdUtil.addr_repr(address, self.dir, self.name) return addrRepr, CvtdUtil.coord_to_ft(error)
def compute_addr(self, lat, lon, valid_streets): ix, seg_ix, proj_ratio, error = self.compute_proj_ratio( lat, lon, valid_streets) if ix != -1: vaddr_begin = self.roadList[ix].points[seg_ix].addr vaddr_end = self.roadList[ix].points[seg_ix + 1].addr address = round(proj_ratio * (vaddr_end - vaddr_begin) + vaddr_begin) else: address = 0 return ix, address, CvtdUtil.coord_to_ft(error)
def get_min_point_error(self, lat, lon): min_pos_to_proj = 0x7FFFFFFF for point_ix, point in enumerate(self.pointList[:-1]): blon = point.lon blat = point.lat elon = self.pointList[point_ix + 1].lon elat = self.pointList[point_ix + 1].lat street_sc, pos_sc, projection_sc, begin_or_end = CvtdUtil.sub_proj_ratio(lat, lon, blat, blon, elat, elon) if projection_sc != 0.0: proj_sc_fixed = min(projection_sc, street_sc) try: pos_to_proj = math.sqrt((pos_sc * pos_sc) - (proj_sc_fixed * proj_sc_fixed)) except ValueError: pos_to_proj = 0 if pos_to_proj < min_pos_to_proj: min_pos_to_proj = pos_to_proj else: print(f"Error [get_min_point_error] on shape: two adjacent points with same node") return CvtdUtil.coord_to_ft(min_pos_to_proj)
def test_coord_to_ft(self): self.assertEqual(CvtdUtil.coord_to_ft(1), 369600)