def print_coord_to_row_col(self): level = 1 for lon in [-180, -90, 0, 90, 180]: for lat in [-90, -45, 0, 45, 90]: coord = [lon, lat] rc = tile_utils.coord_to_row_col(coord, level) print(level, coord, "\t", rc)
def test_extent_from_row_col(self): linesep = "\n " level = 1 for schema in ["here", "web"]: lst_msg = list() lst_check = list() for lon in [-180, -90, 0, 90, 180]: for lat in [-90, -45, 0, 45, 90]: coord = [lon, lat] r, c = tile_utils.coord_to_row_col(coord, level, schema) extent = tile_utils.extent_from_row_col( r, c, level, schema) check = ((extent[0] <= coord[0] <= extent[2]) and (extent[1] <= coord[1] <= extent[3])) lst_msg.append(" ".join( map(str, [ level, [r, c], "\t", coord, "\t", extent, "\t", "Ok" if check else "Fail" ]))) lst_check.append(check) self.assertTrue( all(lst_check), "schema: %s. " % (schema) + "Converted extent does not cover input coord" + linesep + linesep.join(lst_msg))
def test_coord_to_row_col(self): # self.print_coord_to_row_col() for schema, expected in [["here", [547589, 407779]], ["web", [547589, 692956]]]: with self.subTest(schema=schema): level = 20 coord = [8, 50] rc = tile_utils.coord_to_row_col(coord, level, schema) print(level, coord, rc, schema) # self.assertEqual(list(reversed(rc)), [547589, 355619]) # from geotool # rc vs xy self.assertEqual( list(reversed(rc)), expected) # 2^(n-1), reversed index # rc vs xy
def test_example_1(self): level = 6 for coord in [[-136.7, -61.5], [-136.7, 61.5], [-92.9, -34.0]]: rc = tile_utils.coord_to_row_col(coord, level) print(level, coord, rc)