def test_bbox_row_col_web(self): tol = 1e-9 tolY = 1e-3 rect_all = (-180, -90, 180, 90) rect_lowerL = (-180, -90, 0 - tol, 0 - tolY) rect_lowerR = (0, -90, 180, 0 - tolY) rect_upperL = (-180, 0 + tol, 0 - tol, 90) rect_upperR = (0, 0 + tol, 180, 90) for rect in [ rect_all, rect_lowerL, rect_lowerR, rect_upperL, rect_upperR ]: self.assertEqual( sorted(tile_utils.bboxToListColRow(*rect, 0, schema="web")), ["0_0_0"]) self.assertEqual( sorted(tile_utils.bboxToListColRow(*rect_all, 1, schema="web")), ["1_0_0", "1_0_1", "1_1_0", "1_1_1"], ) self.assertEqual( [ tile_utils.bboxToListColRow(*rect, 1, schema="web") for rect in [rect_upperL, rect_lowerL, rect_upperR, rect_lowerR] ], [["1_0_0"], ["1_0_1"], ["1_1_0"], ["1_1_1"]], ) self.assertEqual( len(tile_utils.bboxToListColRow(*rect_all, 2, schema="web")), 16)
def _load_layer(self, loader, conn_info, meta, **kw_start): self.canvas = self.canvas_init() rect, level, tile_schema = [ kw_start[k] for k in ["rect", "level", "tile_schema"] ] # for i, rect in enumerate(self._split_rect(rect,2,2)): for i, limit in enumerate([10, 20, 30, 40]): self._log_debug(rect) kw_start["tile_ids"] = tile_utils.bboxToListColRow( *rect, level, tile_schema) kw_start["limit"] = limit if not i: loader.start(conn_info, meta, **kw_start) else: loader.restart(conn_info, meta, **kw_start) # self._process_async() # import time # time.sleep(1) # self._process_async() # QTimer.singleShot(100, self._stop_async) # early interrupt self._wait_async() lst_layer = list(loader.layer.iter_layer()) if not lst_layer: continue if self.flag_canvas: self.canvas.setLayers(lst_layer) self.canvas_zoom_to_layer(self.canvas, lst_layer[0]) return loader.layer
def _test_bbox_to_quad_tile(self, fn): # https://wiki.openstreetmap.org/wiki/Zoom_levels rect = (-180, -90, 180, 90) for level in range(2): with self.subTest(level=level, rect=rect): lst = tile_utils.bboxToListQuadkey(*rect, level) lst2 = tile_utils.bboxToListColRow(*rect, level) print(level, len(lst), len(lst2), lst, lst2)
def test_bbox_row_col(self): tol = 1e-9 tolY = 1e-3 rect_all = (-180, -90, 180, 90) rect_lowerL = (-180, -90, 0 - tol, 0 - tolY) rect_lowerR = (0, -90, 180, 0 - tolY) rect_upperL = (-180, 0, 0 - tol, 90) rect_upperR = (0, 0, 180, 90) for rect in [ rect_all, rect_lowerL, rect_lowerR, rect_upperL, rect_upperR ]: self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect, 0)), ["0_0_0"]) self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect_all, 1)), ["1_0_0", "1_1_0"]) for rect in [rect_lowerL, rect_upperL]: self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect, 1)), ["1_0_0"]) for rect in [rect_lowerR, rect_upperR]: self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect, 1)), ["1_1_0"]) self.assertEqual( sorted(tile_utils.bboxToListColRow(*rect_all, 2)), [ "2_0_0", "2_0_1", "2_1_0", "2_1_1", "2_2_0", "2_2_1", "2_3_0", "2_3_1" ], ) self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect_lowerL, 2)), ["2_0_0", "2_1_0"]) self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect_lowerR, 2)), ["2_2_0", "2_3_0"]) self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect_upperL, 2)), ["2_0_1", "2_1_1"]) self.assertEqual(sorted(tile_utils.bboxToListColRow(*rect_upperR, 2)), ["2_2_1", "2_3_1"])
# # all # tags = "%s-%s"%("point",level) # rect = [-180, -90, 180, 90] # lst_tiles = generate_tile(level, tile_schema) # print(lst_tiles) # validator = Validator(level) # bounded tags = "point" # rect = [-180, -90, -165, -65] # rect = [-136.7, -61.5, -92.9, -34.0] # level 5 rect = [-136.9, -61.5, -130.9, -55.5] # level 9 # higher level require moore precise coord lst_tiles = tile_utils.bboxToListColRow(*rect, level, tile_schema) print(lst_tiles) validator = BoundedValidator(level, *rect) lst_params = [ dict(tile_schema=tile_schema, tile_id=t, limit=100000, tags=tags) for t in lst_tiles ] total = len(lst_tiles) loop = QEventLoop(app) network = NetManager(app) counter = Counter(total, loop.quit) network.network.finished.connect(validator.check_reply)