def test_poly_bounds(self):
        # create a lopsided PolyLine to test bounding box
        loclist = [
            Location(0, 0),
            Location(400000000, 0),
            Location(350000000, 300000000),
            Location(450000000, 450000000),
            Location(1000, 450000000)
        ]
        expected_rect = Rectangle(Location(0, 0),
                                  Location(450000000, 450000000))
        computed_rect = PolyLine(loclist).bounds()
        self.assertEqual(expected_rect, computed_rect)

        # now test again but with a Polygon
        loclist = [
            Location(0, 0),
            Location(400000000, 0),
            Location(350000000, 300000000),
            Location(450000000, 450000000),
            Location(1000, 450000000)
        ]
        expected_rect = Rectangle(Location(0, 0),
                                  Location(450000000, 450000000))
        computed_rect = Polygon(loclist).bounds()
        self.assertEqual(expected_rect, computed_rect)
Exemple #2
0
 def test_rectangle_construction(self):
     rect = Rectangle(Location(0, 0), Location(450000000, 450000000))
     loop = []
     for point in rect.closed_loop():
         loop.append(point)
     # first and last points should be the same
     self.assertEqual(loop[0], loop[len(loop) - 1])
     # test consistency
     self.assertEqual(loop[0], Location(0, 0))
     self.assertEqual(loop[1], Location(450000000, 0))
     self.assertEqual(loop[2], Location(450000000, 450000000))
     self.assertEqual(loop[3], Location(0, 450000000))
     self.assertEqual(loop[4], Location(0, 0))
Exemple #3
0
    def test_entity_bounding_calculation_on_relations(self):
        atlas = Atlas("resources/test.atlas")

        relation = atlas.relation(1)
        expected_rect = Rectangle(
            Location(390000000, -1190300000), Location(390500000, -1180000000))
        computed_rect = geometry.bounds_atlasentities([relation])
        self.assertEqual(expected_rect, computed_rect)

        relation = atlas.relation(2)
        expected_rect = Rectangle(
            Location(380000000, -1180100000), Location(380100000, -1180000000))
        computed_rect = geometry.bounds_atlasentities([relation])
        self.assertEqual(expected_rect, computed_rect)
Exemple #4
0
    def test_node_spatial_index(self):
        atlas = Atlas("resources/test.atlas")

        lower_left = geometry.location_with_degrees(39, -119.04)
        upper_right = geometry.location_with_degrees(39.05, -119)

        # NOTE node 4 does not show up in results because it lies on the the polygon border
        test_results = atlas.nodes_within(Rectangle(lower_left, upper_right))
        self.assertEqual({atlas.node(2)}, test_results)

        test_results = atlas.nodes_within(
            Rectangle(lower_left, upper_right), lambda n: n.get_identifier() == 3)
        self.assertEqual(frozenset(), test_results)

        test_results = atlas.nodes_at(geometry.location_with_degrees(39, -119.05))
        self.assertEqual({atlas.node(3)}, test_results)
Exemple #5
0
    def test_point_spatial_index(self):
        atlas = Atlas("resources/test.atlas")

        lower_left = geometry.location_with_degrees(37, -118.02)
        upper_right = geometry.location_with_degrees(39, -118)

        # NOTE point 1 does not show up in the results because it lies on the polygon border
        test_results = atlas.points_within(Rectangle(lower_left, upper_right))
        self.assertEqual({atlas.point(2), atlas.point(3)}, test_results)

        test_results = atlas.points_within(
            Rectangle(lower_left, upper_right), lambda p: p.get_identifier() % 2 != 0)
        self.assertEqual({atlas.point(3)}, test_results)

        test_results = atlas.points_at(geometry.location_with_degrees(38, -118))
        self.assertEqual({atlas.point(1)}, test_results)
    def test_basic_spatial_index_operations(self):
        atlas = Atlas("resources/test.atlas")

        index = SpatialIndex(atlas, EntityType.POINT, atlas.points())
        index.initialize_rtree()

        lower_left = geometry.location_with_degrees(37, -118.02)
        upper_right = geometry.location_with_degrees(39, -118)

        test_results = index.get(Rectangle(lower_left, upper_right))
        self.assertEqual(
            {atlas.point(2), atlas.point(3),
             atlas.point(1)}, test_results)

        test_results = index.get(Rectangle(lower_left, upper_right),
                                 lambda p: p.get_identifier() == 2)
        self.assertEqual({atlas.point(2)}, test_results)
Exemple #7
0
    def test_relation_spatial_index(self):
        atlas = Atlas("resources/test.atlas")

        lower_left = geometry.location_with_degrees(37.999, -118.001)
        upper_right = geometry.location_with_degrees(38.001, -117.999)

        test_results = atlas.relations_with_entities_intersecting(
            Rectangle(lower_left, upper_right))
        self.assertEqual({atlas.relation(2)}, test_results)
Exemple #8
0
    def test_edge_spatial_index(self):
        atlas = Atlas("resources/test.atlas")

        test_location = geometry.location_with_degrees(39, -119.05)
        test_results = atlas.edges_containing(test_location)
        self.assertEqual({atlas.edge(1), atlas.edge(3)}, test_results)

        poly = Rectangle(
            geometry.location_with_degrees(38, -120), geometry.location_with_degrees(40, -117))
        test_results = atlas.edges_intersecting(poly)
        self.assertEqual({atlas.edge(1), atlas.edge(2), atlas.edge(3)}, test_results)
Exemple #9
0
    def test_line_spatial_index(self):
        atlas = Atlas("resources/test.atlas")

        test_location = geometry.location_with_degrees(38.02, -118.02)
        test_results = atlas.lines_containing(test_location)
        self.assertEqual({atlas.line(1)}, test_results)

        poly = Rectangle(
            geometry.location_with_degrees(38, -118), geometry.location_with_degrees(39, -119))
        test_results = atlas.lines_intersecting(poly)
        self.assertEqual({atlas.line(1), atlas.line(2)}, test_results)
Exemple #10
0
    def test_location_bounding_calculation(self):
        loclist = [
            Location(0, 0),
            Location(450000000, 0),
            Location(450000000, 450000000),
            Location(0, 450000000)
        ]
        expected_rect = Rectangle(Location(0, 0), Location(450000000, 450000000))
        computed_rect = geometry.bounds_locations(loclist)
        self.assertEqual(expected_rect, computed_rect)

        # create a lopsided polygon to test bounding box
        loclist = [
            Location(0, 0),
            Location(400000000, 0),
            Location(350000000, 300000000),
            Location(450000000, 450000000),
            Location(1000, 450000000)
        ]
        expected_rect = Rectangle(Location(0, 0), Location(450000000, 450000000))
        computed_rect = geometry.bounds_locations(loclist)
        self.assertEqual(expected_rect, computed_rect)
Exemple #11
0
    def test_rtree(self):
        # The bounding box defined in this test should only encompass
        # test Points 1, 2, and 3 from the test atlas

        atlas = Atlas("resources/test.atlas")
        tree = _RTree(atlas.points())

        lower_left = geometry.location_with_degrees(37, -118.02)
        upper_right = geometry.location_with_degrees(39, -118)

        test_results = []
        for element in tree.get(Rectangle(lower_left, upper_right)):
            test_results.append(element)

        self.assertEqual({1, 2, 3}, set(test_results))
Exemple #12
0
 def test_location_bounds(self):
     testlocation = Location(450000000, 450000000)
     testlocationbounds = Rectangle(testlocation, testlocation)
     bound = testlocation.bounds()
     self.assertEqual(bound, testlocationbounds)