def test_iterbottomup(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fill_up(0) self.assertEqual( list(bp.iterbottomup()), [TileCoord(2, 1, 3), TileCoord(1, 0, 1), TileCoord(0, 0, 0)] )
def test_add(self): bp = BoundingPyramid() bp.add(TileCoord(1, 0, 0)) self.assertEqual(len(bp), 1) self.assertTrue(TileCoord(1, 0, 0) in bp) self.assertFalse(TileCoord(1, 0, 1) in bp) self.assertFalse(TileCoord(1, 1, 0) in bp) self.assertFalse(TileCoord(1, 1, 1) in bp) self.assertEqual(list(bp), [TileCoord(1, 0, 0)])
def test_itertopdown(self) -> None: bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fill_up(0) self.assertEqual( list(bp.itertopdown()), [TileCoord(0, 0, 0), TileCoord(1, 0, 1), TileCoord(2, 1, 3)])
def test_add(self): bp = BoundingPyramid() bp.add(TileCoord(1, 0, 0)) self.assertEqual(len(bp), 1) self.assertTrue(TileCoord(1, 0, 0) in bp) self.assertFalse(TileCoord(1, 0, 1) in bp) self.assertFalse(TileCoord(1, 1, 0) in bp) self.assertFalse(TileCoord(1, 1, 1) in bp) self.assertEqual(list(bp), [TileCoord(1, 0, 0)])
def test_zs(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fill_up(0) self.assertEqual(sorted(bp.zs()), [0, 1, 2])
def test_ziter(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fill_up(0) self.assertEqual(list(bp.ziter(1)), [TileCoord(1, 0, 1)])
def test_fill_up2(self): bp = BoundingPyramid({1: (Bounds(0, 2), Bounds(1, 2))}) bp.add(TileCoord(2, 1, 3)) bp.fill_up(0) self.assertEqual(bp.zget(1), (Bounds(0, 2), Bounds(1, 2))) self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
def test_fill_down(self): bp = BoundingPyramid() bp.add(TileCoord(1, 1, 0)) bp.fill_down(3) self.assertEqual(bp.zget(2), (Bounds(2, 4), Bounds(0, 2))) self.assertEqual(bp.zget(3), (Bounds(4, 8), Bounds(0, 4)))
def test_zs(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fillup(0) self.assertEqual(sorted(bp.zs()), [0, 1, 2])
def test_ziter(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fillup(0) self.assertEqual(list(bp.ziter(1)), [TileCoord(1, 0, 1)])
def test_itertopdown(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fillup(0) self.assertEqual(list(bp.itertopdown()), [TileCoord(0, 0, 0), TileCoord(1, 0, 1), TileCoord(2, 1, 3)])
def test_fillup(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fillup(0) self.assertEqual(bp.zget(1), (Bounds(0, 1), Bounds(1, 2))) self.assertEqual(bp.zget(0), (Bounds(0, 1), Bounds(0, 1)))
def test_filldown(self): bp = BoundingPyramid() bp.add(TileCoord(1, 1, 0)) bp.filldown(3) self.assertEqual(bp.zget(2), (Bounds(2, 4), Bounds(0, 2))) self.assertEqual(bp.zget(3), (Bounds(4, 8), Bounds(0, 4)))
def test_iterbottomup(self): bp = BoundingPyramid() bp.add(TileCoord(2, 1, 3)) bp.fill_up(0) self.assertEqual(list(bp.iterbottomup()), [TileCoord(2, 1, 3), TileCoord(1, 0, 1), TileCoord(0, 0, 0)])
def init_tilecoords(self, layer): resolutions = layer['grid_ref']['resolutions'] if self.options.time is not None and self.options.zoom is None: if 'min_resolution_seed' in layer: # pragma: no cover self.options.zoom = [ resolutions.index(layer['min_resolution_seed']) ] else: self.options.zoom = [len(resolutions) - 1] if self.options.zoom is not None: zoom_max = len(resolutions) - 1 for zoom in self.options.zoom: if zoom > zoom_max: logger.warning( "zoom %i is greater than the maximum zoom %i" " of grid %s of layer %s, ignored." % (zoom, zoom_max, layer['grid'], layer['name'])) self.options.zoom = [z for z in self.options.zoom if z <= zoom_max] if 'min_resolution_seed' in layer: if self.options.zoom is None: self.options.zoom = [] for z, resolution in enumerate(resolutions): if resolution >= layer['min_resolution_seed']: self.options.zoom.append(z) else: for zoom in self.options.zoom: resolution = resolutions[zoom] if resolution < layer['min_resolution_seed']: logger.warning( "zoom %i corresponds to resolution %s is smaller" " than the 'min_resolution_seed' %s of layer %s, ignored." % (zoom, resolution, layer['min_resolution_seed'], layer['name'])) self.options.zoom = [ z for z in self.options.zoom if resolutions[z] >= layer['min_resolution_seed'] ] if self.options.zoom is None: self.options.zoom = [z for z, r in enumerate(resolutions)] # fill the bounding pyramid tilegrid = layer['grid_ref']['obj'] bounding_pyramid = BoundingPyramid(tilegrid=tilegrid) for zoom in self.options.zoom: if zoom in self.geoms: extent = self.geoms[zoom].bounds if len(extent) == 0: logger.warning("bounds empty for zoom {}".format(zoom)) else: minx, miny, maxx, maxy = extent px_buffer = layer['px_buffer'] m_buffer = px_buffer * resolutions[zoom] minx -= m_buffer miny -= m_buffer maxx += m_buffer maxy += m_buffer bounding_pyramid.add( tilegrid.tilecoord( zoom, max(minx, tilegrid.max_extent[0]), max(miny, tilegrid.max_extent[1]), )) bounding_pyramid.add( tilegrid.tilecoord( zoom, min(maxx, tilegrid.max_extent[2]), min(maxy, tilegrid.max_extent[3]), )) if layer.get('meta', False): self.set_tilecoords( bounding_pyramid.metatilecoords(layer['meta_size']), layer) else: self.set_tilecoords(bounding_pyramid, layer)
def init_tilecoords(self, layer): resolutions = layer['grid_ref']['resolutions'] if self.options.time is not None and self.options.zoom is None: if 'min_resolution_seed' in layer: # pragma: no cover self.options.zoom = [resolutions.index( layer['min_resolution_seed'] )] else: self.options.zoom = [len(resolutions) - 1] if self.options.zoom is not None: zoom_max = len(resolutions) - 1 for zoom in self.options.zoom: if zoom > zoom_max: logger.warning( "zoom %i is greater than the maximum zoom %i" " of grid %s of layer %s, ignored." % ( zoom, zoom_max, layer['grid'], layer['name'] ) ) self.options.zoom = [z for z in self.options.zoom if z <= zoom_max] if 'min_resolution_seed' in layer: if self.options.zoom is None: self.options.zoom = [] for z, resolution in enumerate(resolutions): if resolution >= layer['min_resolution_seed']: self.options.zoom.append(z) else: for zoom in self.options.zoom: resolution = resolutions[zoom] if resolution < layer['min_resolution_seed']: logger.warning( "zoom %i corresponds to resolution %s is smaller" " than the 'min_resolution_seed' %s of layer %s, ignored." % ( zoom, resolution, layer['min_resolution_seed'], layer['name'] ) ) self.options.zoom = [ z for z in self.options.zoom if resolutions[z] >= layer['min_resolution_seed'] ] if self.options.zoom is None: self.options.zoom = [z for z, r in enumerate(resolutions)] # fill the bounding pyramid tilegrid = layer['grid_ref']['obj'] bounding_pyramid = BoundingPyramid(tilegrid=tilegrid) for zoom in self.options.zoom: if zoom in self.geoms: extent = self.geoms[zoom].bounds if len(extent) == 0: logger.warning("bounds empty for zoom {}".format(zoom)) else: minx, miny, maxx, maxy = extent px_buffer = layer['px_buffer'] m_buffer = px_buffer * resolutions[zoom] minx -= m_buffer miny -= m_buffer maxx += m_buffer maxy += m_buffer bounding_pyramid.add(tilegrid.tilecoord( zoom, max(minx, tilegrid.max_extent[0]), max(miny, tilegrid.max_extent[1]), )) bounding_pyramid.add(tilegrid.tilecoord( zoom, min(maxx, tilegrid.max_extent[2]), min(maxy, tilegrid.max_extent[3]), )) if layer.get('meta', False): self.set_tilecoords(bounding_pyramid.metatilecoords(layer['meta_size']), layer) else: self.set_tilecoords(bounding_pyramid, layer)