Beispiel #1
0
 def test_projections(self):
     t = terrarium.Terrarium([], [])
     z, x, y = (13, 1308, 3165)
     ll_bbox = t.mercator.latlon_bbox(z, x, y)
     cx = 0.5 * (ll_bbox.bounds[0] + ll_bbox.bounds[2])
     cy = 0.5 * (ll_bbox.bounds[1] + ll_bbox.bounds[3])
     self.assertEqual((x, y), t.mercator.lonlat_to_xy(z, cx, cy))
Beispiel #2
0
    def test_group_dispatch_tiles(self):
        regions = [
            Region(BoundingBox(-124.56, 32.4, -114.15, 42.03), [8, 10])
        ]
        t = terrarium.Terrarium(regions, [])

        class Batch(object):
            def __init__(self, queue, max_batch_len):
                self.queue = queue
                self.batch = []

            def append(self, job):
                self.batch.append(job)

            def flush(self):
                for job in self.batch:
                    self.queue.append(job)
                self.batch = []

        class Queue(object):
            def __init__(self):
                self.expected = set([
                    (8, 41, 99),
                    (8, 43, 98)
                ])

            def start_batch(self, max_batch_len):
                return Batch(self, max_batch_len)

            def append(self, tile):
                coord = (tile['z'], tile['x'], tile['y'])
                if coord in self.expected:
                    self.expected.remove(coord)

            def flush(self):
                pass

        class FakeLogger(object):
            def info(self, msg):
                print msg

            def warning(self, msg):
                print msg

        logger = FakeLogger()
        queue = Queue()
        d = dispatcher.GroupingDispatcher(queue, 10, logger, 1000)

        for tile in t.generate_tiles():
            d.append(tile.freeze_dry())

        d.flush()
        self.assertEqual(queue.expected, set([]))
Beispiel #3
0
 def test_generate_tiles(self):
     regions = [
         Region(BoundingBox(-124.56, 32.4, -114.15, 42.03), [8, 10])
     ]
     t = terrarium.Terrarium(regions, [])
     expected = set([
         (8, 41, 99),
         (8, 43, 98)
     ])
     for tile in t.generate_tiles():
         coord = (tile.z, tile.x, tile.y)
         if coord in expected:
             expected.remove(coord)
     self.assertEqual(expected, set([]))
Beispiel #4
0
    def test_dispatch_tiles(self):
        regions = [
            Region(BoundingBox(-124.56, 32.4, -114.15, 42.03), [8, 10])
        ]
        t = terrarium.Terrarium(regions, [])

        class Batch(object):
            def __init__(self, queue, max_batch_len):
                self.queue = queue
                self.batch = []

            def append(self, job):
                self.batch.append(job)

            def flush(self):
                for job in self.batch:
                    self.queue.append(job)
                self.batch = []

        class Queue(object):
            def __init__(self):
                self.expected = set([
                    (8, 41, 99),
                    (8, 43, 98)
                ])

            def start_batch(self, max_batch_len):
                return Batch(self, max_batch_len)

            def append(self, tile):
                coord = (tile.z, tile.x, tile.y)
                if coord in self.expected:
                    self.expected.remove(coord)

            def flush(self):
                pass

        logger = logging.getLogger('process')
        queue = Queue()
        d = dispatcher.Dispatcher(queue, 10, logger)

        for tile in t.generate_tiles():
            d.append(tile)

        d.flush()
        self.assertEqual(queue.expected, set([]))
Beispiel #5
0
 def test_location_to_xy(self):
     t = terrarium.Terrarium([], [])
     x, y = t.mercator.lonlat_to_xy(19, -122.39199, 37.79123)
     self.assertEqual(83897, x)
     self.assertEqual(202618, y)