Esempio n. 1
0
class TestTile(LoggedInTest):
    # see
    # http://gis.stackexchange.com/questions/8650/how-to-measure-the-accuracy-of-latitude-and-longitude
    POSITION_ACCURANCY = 3  # = up to 110 meters

    def setUp(self):
        super().setUp()
        self.tile = Tile(self.gc, 8800, 5574, 14)

    def test_download_utfgrid(self):
        """Test if downloading a UTFGrid passes without errors"""
        with self.recorder.use_cassette("geo_point_utfgrid"):
            with self.subTest("not getting .png tile first"):
                self.tile._download_utfgrid()

            with self.subTest("getting .png tile first"):
                self.tile._download_utfgrid(get_png=True)

    @mock.patch.object(Tile, "_download_utfgrid")
    def test_blocks(self, mock_utfgrid):
        """Parse locally stored grid and compare to expected results"""

        # load mock utfgrid from file
        with open(_sample_utfgrid_file, encoding="utf8") as f:
            mock_utfgrid.return_value = json.load(f)

        # load expected caches from file
        expected_caches = {}
        with open(_sample_caches_file) as f:
            for row in f:
                wp, lat, lon, pm_only = row.strip().split(",")
                expected_caches[wp] = float(lat), float(lon), bool(int(pm_only))

        for b in self.tile.blocks:
            c = Cache.from_block(b)
            self.assertIn(c.wp, expected_caches)
            if not expected_caches[c.wp][2]:  # if not PM only
                self.assertAlmostEqual(c.location.latitude, expected_caches[c.wp][0], self.POSITION_ACCURANCY)
                self.assertAlmostEqual(c.location.longitude, expected_caches[c.wp][1], self.POSITION_ACCURANCY)
            expected_caches.pop(c.wp)
        self.assertEqual(len(expected_caches), 0)

    def test_precision(self):
        with self.subTest("with point coorection"):
            t1 = make_tile(0, 0, 14)[0]
            p = Point(49.75, 13.36)
            self.assertAlmostEqual(t1.precision(p), 6.173474613462484)

        with self.subTest("precision is larger on greater z values"):
            t1 = make_tile(0, 0, 13)[0]
            t2 = make_tile(0, 0, 14)[0]
            self.assertGreater(t1.precision(), t2.precision())

        with self.subTest("precision is larger when tile is divided to smaller pieces"):
            t1 = make_tile(0, 0, 14)[0]
            t1.size = 10
            t2 = make_tile(0, 0, 14)[0]
            t2.size = 100
            self.assertGreater(t1.precision(), t2.precision())
Esempio n. 2
0
 def setUp(self):
     self.tile = Tile(self.gc, 8800, 5574, 14)
Esempio n. 3
0
def make_tile(x, y, z, a=0, b=0, size=256):
    t = Tile(None, x, y, z)
    t.size = size
    return t, UTFGridPoint(a, b)
Esempio n. 4
0
 def setUp(self):
     super().setUp()
     self.tile = Tile(self.gc, 8800, 5574, 14)
Esempio n. 5
0
def make_tile(x, y, z, a=0, b=0, size=256):
    t = Tile(None, x, y, z)
    t.size = size
    return t, UTFGridPoint(a, b)
Esempio n. 6
0
 def setUp(self):
     super().setUp()
     self.tile = Tile(self.gc, 8800, 5574, 14)
Esempio n. 7
0
class TestTile(NetworkedTest):
    # see
    # http://gis.stackexchange.com/questions/8650/how-to-measure-the-accuracy-of-latitude-and-longitude
    POSITION_ACCURANCY = 3  # = up to 110 meters

    def setUp(self):
        super().setUp()
        self.tile = Tile(self.gc, 8800, 5574, 14)

    def test_download_utfgrid(self):
        """Test if downloading a UTFGrid passes without errors"""
        with self.recorder.use_cassette('geo_point_utfgrid'):
            with self.subTest("not getting .png tile first"):
                self.tile._download_utfgrid()

            with self.subTest("getting .png tile first"):
                self.tile._download_utfgrid(get_png=True)

    @mock.patch.object(Tile, '_download_utfgrid')
    def test_blocks(self, mock_utfgrid):
        """Parse locally stored grid and compare to expected results"""

        # load mock utfgrid from file
        with open(_sample_utfgrid_file) as f:
            mock_utfgrid.return_value = json.load(f)

        # load expected caches from file
        expected_caches = {}
        with open(_sample_caches_file) as f:
            for row in f:
                wp, lat, lon, pm_only = row.strip().split(",")
                expected_caches[wp] = float(lat), float(lon), bool(int(pm_only))

        for b in self.tile.blocks:
            c = Cache.from_block(b)
            self.assertIn(c.wp, expected_caches)
            if not expected_caches[c.wp][2]:  # if not PM only
                self.assertAlmostEqual(c.location.latitude, expected_caches[
                    c.wp][0], self.POSITION_ACCURANCY)
                self.assertAlmostEqual(c.location.longitude, expected_caches[
                    c.wp][1], self.POSITION_ACCURANCY)
            expected_caches.pop(c.wp)
        self.assertEqual(len(expected_caches), 0)

    def test_precision(self):
        with self.subTest("with point coorection"):
            t1 = make_tile(0, 0, 14)[0]
            p = Point(49.75, 13.36)
            self.assertAlmostEqual(t1.precision(p), 6.173474613462484)

        with self.subTest("precision is larger on greater z values"):
            t1 = make_tile(0, 0, 13)[0]
            t2 = make_tile(0, 0, 14)[0]
            self.assertGreater(t1.precision(), t2.precision())

        with self.subTest("precision is larger when tile is divided to smaller pieces"):
            t1 = make_tile(0, 0, 14)[0]
            t1.size = 10
            t2 = make_tile(0, 0, 14)[0]
            t2.size = 100
            self.assertGreater(t1.precision(), t2.precision())
Esempio n. 8
0
 def setUp(self):
     self.tile = Tile(self.gc, 8800, 5574, 14)