def test_map_service(self): ms = MapService() ms.set_overpass_wrapper(OverpassWrapperServerSide(ms.get_config())) nodes = ms.get_nodes_in_bounding_box( BoundingBox(49.4790812638, 7.7679723593, 49.482845546, 7.7734850962)) for node in nodes[:5]: ms.get_node(node.get_id()) node.to_geojson() node.get_tags() node.to_wkt() ms.set_overpass_wrapper(OverpassWrapperClientSide(ms.get_config())) links = ms.get_links_in_bounding_box( BoundingBox(49.4796172829, 8.4784880064, 49.5097706833, 8.5317118292)) for link in links[:5]: self.assertEqual(ms.get_link_by_id(link.get_id()), link) ms.get_links(link.get_way_osm_id()) link.to_geojson() link.to_wkt() link.get_tags() link_distances = ms.get_linkdistances_in_radius( (49.4298243272, 7.7204445597), 500) for ld in link_distances: ld.get_link().to_geojson() ld.get_distance() ld.get_fraction() ld.get_point()
def test_contains_node(self): """ :return: """ bbox = BoundingBox(50.0, 10.0, 50.5, 12.0) # Are located in bbox. n1 = Node(NodeId(1, ""), (50.0, 10.0)) n2 = Node(NodeId(2, ""), (50.0, 11.0)) n3 = Node(NodeId(3, ""), (50.2, 10.0)) n4 = Node(NodeId(4, ""), (50.5, 11.0)) # Are not located in bbox. n5 = Node(NodeId(5, ""), (49.0, 9.0)) n6 = Node(NodeId(6, ""), (49.0, 10.0)) n7 = Node(NodeId(7, ""), (50.0, 9.0)) self.assertTrue(bbox.contains_node(n1)) self.assertTrue(bbox.contains_node(n2)) self.assertTrue(bbox.contains_node(n3)) self.assertTrue(bbox.contains_node(n4)) self.assertTrue( bbox.contains_node(Node(NodeId(8, ""), (bbox.south, bbox.west)))) self.assertFalse(bbox.contains_node(n5), False) self.assertFalse(bbox.contains_node(n6), False) self.assertFalse(bbox.contains_node(n7), False)
def main(): """ This methods runs all tests from the directory tests. If any test fails the corresponding assertion will print an error. Otherwise nothing happens. :return: None """ mapService = MapService() #nodes = mapService.get_nodes_in_bounding_box(BoundingBox (48.161844064843976, 11.572936935405323,48.1675975217803,11.578730506877491)) nodes = mapService.get_nodes_in_bounding_box( BoundingBox(48.1301415 - 0.01, 11.5579533 - 0.01, 48.1301415 + 0.01, 11.5579533 + 0.01)) counter = 0 for node in nodes: if "amenity" in node.get_tags() and counter < 20: counter = counter + 1 print("--------- Found POI at: " + node.to_wkt()) for k, v in node.get_tags().items(): print(" " + k + " --> " + v) # parse links links = mapService.get_links_in_bounding_box( BoundingBox(48.161844064843976, 11.572936935405323, 48.1675975217803, 11.578730506877491)) for link in links[:1]: print(link.to_wkt()) print(link.to_geojson()) print(link.get_geometry()) for k, v in link.get_tags().items(): print(k + " --> " + v) print("Car from Start: ", link.is_navigatable_from_start(Car())) print("Car to Start: ", link.is_navigatable_to_start(Car())) print("Start Note: ", link.get_start_node().get_id()) print("End Note: ", link.get_end_node().get_id().get_osm_id()) print("Length Meter:", link.get_length())
def get_geohashes(): """ :return tile of given GeoHash """ bbox_str = request.args.get("bbox") bbox = [] for val in bbox_str.split(","): bbox.append(float(val)) south, west, north, east = tuple(bbox) bbox = BoundingBox(south, west, north, east) msw = MapserviceWrapper(map_service) data = msw.get_dict_geohashes(bbox) return _resp(data)
def _build_query(self, geohash, q_filter: str): """ Returns the URL to download the data, which is required to build the tile with the specified geohash. :param geohash: str :param q_filter: str """ bbox_str = "%s" % BoundingBox.from_geohash(geohash) query = '?data=[out:json];way%s%s->.ways;node(w.ways)->.nodes;.nodes out body; .ways out;' % ( bbox_str, q_filter) # adding this will also download the POIs in the region # TODO: make it configuration to download pois query += 'node%s["amenity"];out;' % (bbox_str) return query
def _build_query(self, geohash, q_filter: str): """ Returns the URL to download the data, which is required to build the tile with the specified geohash. The intersections of ways are determined on server-side. :param geohash: str :param q_filter: str """ bbox_str = "%s" % BoundingBox.from_geohash(geohash) query = '?data=[out:json];way%s%s->.ways;node(w.ways)->.nodes;relation.nodes->.intersections;foreach.ways->.w((' \ '.ways; - .w;)->.otherWays;node(w.w)->.currentWayNodes;node(' \ 'w.otherWays)->.otherWayNodes;node.currentWayNodes.otherWayNodes->.currentIntersections;(' \ '.intersections; .currentIntersections;)->.intersections;);.intersections out count;.intersections ' \ 'out ids;.nodes out body; .ways out geom;' % (bbox_str, q_filter) return query
def _get_predictions( self, frames: np.ndarray ) -> Tuple[List[List[str]], List[List[float]], List[List[BoundingBox]]]: """ Performs predictions on input frames Arguments: frames (np.ndarray): Frames on which predictions need to be performed Returns: tuple containing predicted_classes (List[List[str]]), predicted_boxes (List[List[BoundingBox]]), predicted_scores (List[List[float]]) """ transform = transforms.Compose([transforms.ToTensor()]) images = [transform(frame) for frame in frames] predictions = self.model(images) prediction_boxes = [] prediction_classes = [] prediction_scores = [] for prediction in predictions: pred_class = [ str(self.labels[i]) for i in list(prediction['labels'].numpy()) ] pred_boxes = [ BoundingBox(Point(i[0], i[1]), Point(i[2], i[3])) for i in list(prediction['boxes'].detach().numpy()) ] pred_score = list(prediction['scores'].detach().numpy()) pred_t = [ pred_score.index(x) for x in pred_score if x > self.threshold ][-1] pred_boxes = list(pred_boxes[:pred_t + 1]) pred_class = list(pred_class[:pred_t + 1]) pred_score = list(pred_score[:pred_t + 1]) prediction_boxes.append(pred_boxes) prediction_classes.append(pred_class) prediction_scores.append(pred_score) return prediction_classes, prediction_scores, prediction_boxes
def test_contains_bbox(self): bbox_1 = BoundingBox(0.513282437, 0.0159996796, 84.0942163677, 89.3608800602) self.assertTrue(bbox_1.contains_bbox(bbox_1)) self.assertTrue( bbox_1.contains_bbox( BoundingBox(21.6647872488, 15.5327550602, 65.2416229192, 89.3608800602))) self.assertTrue( bbox_1.contains_bbox( BoundingBox(21.6647872488, 15.5327550602, 65.2416229192, 67.5640050602))) self.assertTrue( bbox_1.contains_bbox( BoundingBox(60.4394489351, 1.4702550602, 73.7411216463, 53.5015050602))) self.assertFalse( bbox_1.contains_bbox( BoundingBox(64.0372106287, 111.1577550602, 75.7716930825, -160.2484949398))) self.assertFalse( bbox_1.contains_bbox( BoundingBox(-63.6817377051, 4.9858800602, -14.894669805, 93.5796300602))) self.assertFalse( bbox_1.contains_bbox( BoundingBox(-11.8165911863, -44.2328699398, 48.95656608, 44.3608800602))) bbox_2 = BoundingBox(-66.9097288411, 89.3608800602, 0.403422688, -132.8266199398) self.assertTrue(bbox_2.contains_bbox(bbox_2)) self.assertTrue( bbox_2.contains_bbox( BoundingBox(-66.9097288411, 89.3608800602, 0.403422688, 162.4858800602))) self.assertTrue( bbox_2.contains_bbox( BoundingBox(-60.0389493929, 104.1265050602, -18.9299746389, 161.7827550602))) self.assertTrue( bbox_2.contains_bbox( BoundingBox(-35.1314035932, 162.1343175602, -6.613091808, -169.0375574398))) self.assertFalse( bbox_2.contains_bbox( BoundingBox(-35.1314035932, 162.1343175602, 16.3488238092, -169.0375574398))) self.assertFalse( bbox_2.contains_bbox( BoundingBox(-18.5970967976, -33.3344324398, 33.4747130173, 53.5015050602))) self.assertFalse( bbox_2.contains_bbox( BoundingBox(-69.9426596955, 63.5210363102, -40.807816162, 150.3569738102)))
def test_overlap(self): bbox_1 = BoundingBox(-84.7230301687, -88.0437195301, 5.0824166086, -0.1530945301) self.assertTrue(bbox_1.overlap(bbox_1)) self.assertTrue( bbox_1.overlap( BoundingBox(-87.2784773532, -42.6921570301, -79.0065948826, 45.1984679699))) self.assertTrue( bbox_1.overlap( BoundingBox(-51.7323307799, -25.9929382801, -12.0476934022, 31.3117492199))) self.assertTrue( bbox_1.overlap( BoundingBox(-24.0542820566, -117.3991882801, 23.0718554917, -60.0945007801))) self.assertTrue( bbox_1.overlap( BoundingBox(-65.7341451731, -75.9148132801, -36.7457445723, -18.6101257801))) self.assertFalse( bbox_1.overlap( BoundingBox(-69.9633727485, 5.6476867199, -45.2190344304, 62.9523742199))) self.assertFalse( bbox_1.overlap( BoundingBox(9.4406166, 0.9894835949, 70.8418632201, 81.6730773449))) self.assertFalse( bbox_1.overlap( BoundingBox(-68.3050695526, -116.3005554676, -56.1258325306, -93.5368835926))) self.assertFalse( bbox_1.overlap( BoundingBox(80.2221338128, -171.1443054676, 83.8384658562, -148.3806335926))) bbox_2 = BoundingBox(5.0824166086, 107.4250304699, 82.0445552426, -138.6687195301) self.assertTrue(bbox_2.overlap(bbox_2)) self.assertTrue( bbox_2.overlap( BoundingBox(48.1017141934, 134.1437804699, 69.7151388143, -179.4499695301))) self.assertTrue( bbox_2.overlap( BoundingBox(-4.7492073269, 157.3469054699, 36.1664456641, -156.2468445301))) self.assertTrue( bbox_2.overlap( BoundingBox(33.2774628304, 92.3078429699, 52.584499321, 122.5422179699))) self.assertTrue( bbox_2.overlap( BoundingBox(80.5595384997, 159.8078429699, 84.0698625322, -169.9577820301))) self.assertFalse( bbox_2.overlap( BoundingBox(42.1570571961, -112.3015320301, 58.9002238264, -82.0671570301))) self.assertFalse( bbox_2.overlap( BoundingBox(-57.0453872502, -168.1999695301, -9.9772825246, 174.3976867199))) self.assertFalse( bbox_2.overlap( BoundingBox(13.0604370531, 14.2609679699, 77.116122992, 41.6828429699))) self.assertFalse( bbox_2.overlap( BoundingBox(83.3075016401, 139.7687804699, 84.745656882, 162.2687804699)))