コード例 #1
0
    def test_poly_length(self):
        loclist = [Location(0, 0), Location(5000000, 5000000)]
        polyline = PolyLine(loclist, deep=True)
        self.assertEqual(78626, int(polyline.length()))

        loclist2 = [Location(0, 0), Location(20000000, 20000000)]
        polyline = PolyLine(loclist2, deep=True)
        self.assertEqual(314474, int(polyline.length()))
コード例 #2
0
 def test_polyline_to_shapely_linestring(self):
     polyline1 = PolyLine(
         [Location(-1000, -1000),
          Location(0, 0),
          Location(5000, 8000)])
     linestring1 = geometry.polyline_to_shapely_linestring(polyline1)
     test_against = shapely.geometry.LineString([(-1000, -1000), (0, 0),
                                                 (5000, 8000)])
     self.assertEqual(linestring1, test_against)
コード例 #3
0
    def test_location_to_shapely_point(self):
        l1 = Location(0, 0)
        l2 = Location(1000, 2000)
        l3 = Location(50000, -1000000)

        p1 = geometry.location_to_shapely_point(l1)
        p2 = geometry.location_to_shapely_point(l2)
        p3 = geometry.location_to_shapely_point(l3)

        self.assertEqual(shapely.geometry.Point(0, 0), p1)
        self.assertEqual(shapely.geometry.Point(1000, 2000), p2)
        self.assertEqual(shapely.geometry.Point(50000, -1000000), p3)
コード例 #4
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)
コード例 #5
0
    def test_boundable_to_shapely_box(self):
        loclist = [
            Location(0, 0),
            Location(400000000, 0),
            Location(350000000, 300000000),
            Location(450000000, 450000000),
            Location(1000, 450000000)
        ]
        bounds = Polygon(loclist).bounds()

        shapely_box = geometry.boundable_to_shapely_box(bounds)
        test_against = shapely.geometry.LineString([(0, 0), (450000000, 0),
                                                    (450000000, 450000000),
                                                    (0, 450000000)])
        test_against = shapely.geometry.Polygon(test_against)

        self.assertTrue(shapely_box, test_against)
コード例 #6
0
    def test_polygon_to_shapely_polygon(self):
        loclist = [
            Location(0, 0),
            Location(400000000, 0),
            Location(350000000, 300000000),
            Location(450000000, 450000000),
            Location(1000, 450000000)
        ]
        polygon = Polygon(loclist)

        shapely_poly = geometry.polygon_to_shapely_polygon(polygon)
        test_against = shapely.geometry.LineString([(0, 0), (400000000, 0),
                                                    (350000000, 300000000),
                                                    (450000000, 450000000),
                                                    (1000, 450000000)])
        test_against = shapely.geometry.Polygon(test_against)

        self.assertTrue(shapely_poly, test_against)
コード例 #7
0
 def test_intersects_polygon(self):
     loclist = [
         Location(0, 0),
         Location(400000000, 0),
         Location(350000000, 300000000),
         Location(450000000, 450000000),
         Location(1000, 450000000)
     ]
     loclist2 = [Location(1, 1), Location(10, 10), Location(2000, 3000)]
     polygon = Polygon(loclist)
     polygon2 = Polygon(loclist2)
     self.assertTrue(polygon.intersects(polygon2))
コード例 #8
0
 def test_overlaps_polyline(self):
     loclist = [
         Location(0, 0),
         Location(400000000, 0),
         Location(350000000, 300000000),
         Location(450000000, 450000000),
         Location(1000, 450000000)
     ]
     loclist2 = [Location(1, 1), Location(2000, 3000)]
     polygon = Polygon(loclist)
     polyline0 = PolyLine(loclist2)
     self.assertTrue(polygon.overlaps_polyline(polyline0))
コード例 #9
0
    def test_polyline_compression(self):
        loclist = [Location(1, 1), Location(2, 2), Location(5, 5)]
        correct_polyline = PolyLine(loclist, deep=True)
        test_polyline = geometry.decompress_polyline(
            correct_polyline.compress())
        self.assertEqual(correct_polyline, test_polyline)

        loclist = [
            Location(382117269, -1193153616),
            Location(382117927, -1193152951),
            Location(382116912, -1193151049),
            Location(382116546, -1193151382),
            Location(382116134, -1193150734),
            Location(382115440, -1193151494)
        ]
        correct_polyline = PolyLine(loclist, deep=True)
        test_polyline = geometry.decompress_polyline(
            correct_polyline.compress())
        self.assertEqual(correct_polyline, test_polyline)
コード例 #10
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))
コード例 #11
0
    def test_fully_geometrically_encloses_location(self):
        loclist = [
            Location(0, 0),
            Location(400000000, 0),
            Location(350000000, 300000000),
            Location(450000000, 450000000),
            Location(1000, 450000000)
        ]
        polygon = Polygon(loclist)
        point = Location(1200, 1500)
        self.assertTrue(polygon.fully_geometrically_encloses_location(point))

        point = Location(0, 0)
        self.assertFalse(polygon.fully_geometrically_encloses_location(point))

        point = Location(-34, -1)
        self.assertFalse(polygon.fully_geometrically_encloses_location(point))
コード例 #12
0
 def test_polygon_closedness(self):
     loclist = [
         Location(382117269, -1193153616),
         Location(382117927, -1193152951),
         Location(382116912, -1193151049),
         Location(382116546, -1193151382),
         Location(382116134, -1193150734),
         Location(382115440, -1193151494)
     ]
     correct_polygon = Polygon(loclist, deep=True)
     closed_list = []
     for point in correct_polygon.closed_loop():
         closed_list.append(point)
     self.assertEqual(closed_list[0], closed_list[len(closed_list) - 1])
コード例 #13
0
 def test_intersects_polyline(self):
     loclist = [
         Location(-3, -3),
         Location(-2, -2),
         Location(-1, -1),
         Location(0, 0),
         Location(1, 1),
         Location(2, 2),
         Location(3, 3)
     ]
     loclist2 = [
         Location(-3, 3),
         Location(-2, 2),
         Location(-1, 1),
         Location(0, 0),
         Location(-1, 1),
         Location(-2, 2),
         Location(-3, 3)
     ]
     polyline = PolyLine(loclist)
     polyline2 = PolyLine(loclist2)
     self.assertTrue(polyline.intersects_polyline(polyline2))
コード例 #14
0
    def test_location_packing(self):
        testlocation = Location(1, 1)
        self.assertEqual(
            testlocation,
            geometry.location_from_packed_int(
                testlocation.get_as_packed_int()))

        testlocation = Location(1, -3)
        self.assertEqual(
            testlocation,
            geometry.location_from_packed_int(
                testlocation.get_as_packed_int()))

        testlocation = Location(-3, -3)
        self.assertEqual(
            testlocation,
            geometry.location_from_packed_int(
                testlocation.get_as_packed_int()))

        testlocation = Location(-900000000, 450000000)
        self.assertEqual(
            testlocation,
            geometry.location_from_packed_int(
                testlocation.get_as_packed_int()))

        testlocation = Location(900000000, -1800000000)
        self.assertEqual(
            testlocation,
            geometry.location_from_packed_int(
                testlocation.get_as_packed_int()))

        testlocation = Location(900000000, 1800000000 - 1)
        self.assertEqual(
            testlocation,
            geometry.location_from_packed_int(
                testlocation.get_as_packed_int()))
コード例 #15
0
 def test_location_bounds(self):
     testlocation = Location(450000000, 450000000)
     testlocationbounds = Rectangle(testlocation, testlocation)
     bound = testlocation.bounds()
     self.assertEqual(bound, testlocationbounds)
コード例 #16
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)
コード例 #17
0
    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)