コード例 #1
0
ファイル: utils.py プロジェクト: surroundaustralia/tb16pix
def calculate_neighbours(zone_id):
    if zone_id == "Earth":
        return None
    else:
        c = Cell(TB16Pix, _suid_from_string(zone_id))
        neighbours = []
        for k, v in sorted(c.neighbors().items()):
            neighbours.append((k, str(v)))
        return neighbours
コード例 #2
0
    def test_neighbors(self):
        for rdggs in [WGS84_003, WGS84_003_RADIANS]:
            # Plane test.
            # Should work on resolution 1 cells with suids of the form s0
            get = []
            for s in CELLS0:
                nb = Cell(rdggs, [s] + [0]).neighbors()
                for d in ["up", "left", "down", "right"]:
                    get.append(nb[d])
            expect = [
                (Q, 2),
                (R, 0),
                (N, 3),
                (N, 1),
                (N, 6),
                (R, 2),
                (O, 3),
                (O, 1),
                (N, 8),
                (O, 2),
                (P, 3),
                (P, 1),
                (N, 2),
                (P, 2),
                (Q, 3),
                (Q, 1),
                (N, 0),
                (Q, 2),
                (R, 3),
                (R, 1),
                (O, 6),
                (R, 8),
                (S, 3),
                (S, 1),
            ]
            expect = [Cell(rdggs, s) for s in expect]
            for i in range(len(expect)):
                self.assertEqual(get[i], expect[i])

            # Ellipsoid test.
            # Quad.
            c = Cell(rdggs, (O, 0))
            get = c.neighbors(plane=False)
            expect = dict()
            expect["north"] = Cell(rdggs, (N, 6))
            expect["south"] = Cell(rdggs, (O, 3))
            expect["west"] = Cell(rdggs, (R, 2))
            expect["east"] = Cell(rdggs, (O, 1))
            for k in list(get.keys()):
                self.assertEqual(get[k], expect[k])
            # Cap.
            c = Cell(rdggs, (S, 4))
            get = c.neighbors(plane=False)
            expect = dict()
            expect["north_0"] = Cell(rdggs, (S, 1))
            expect["north_1"] = Cell(rdggs, (S, 5))
            expect["north_2"] = Cell(rdggs, (S, 7))
            expect["north_3"] = Cell(rdggs, (S, 3))
            for k in list(get.keys()):
                self.assertEqual(get[k], expect[k])
            # Dart.
            c = Cell(rdggs, (N, 6))
            get = c.neighbors(plane=False)
            expect = dict()
            expect["west"] = Cell(rdggs, (N, 3))
            expect["east"] = Cell(rdggs, (N, 7))
            expect["south_west"] = Cell(rdggs, (R, 2))
            expect["south_east"] = Cell(rdggs, (O, 0))
            for k in list(get.keys()):
                self.assertEqual(get[k], expect[k])
            # Skew quad.
            c = Cell(rdggs, (N, 3))
            get = c.neighbors(plane=False)
            expect = dict()
            expect["north"] = Cell(rdggs, (N, 4))
            expect["south"] = Cell(rdggs, (R, 1))
            expect["west"] = Cell(rdggs, (N, 0))
            expect["east"] = Cell(rdggs, (N, 6))
            for k in list(get.keys()):
                self.assertEqual(get[k], expect[k])