def test_tilegrid_props(): grid = grids.TileGrid(ul=[0, 100], crs='epsg:5070', res=[5, 5], size=[10, 10], limits=[[0, 11], [0, 7]]) assert grid.ncol == 8 assert grid.cols == list(range(0, 8)) assert grid.nrow == 12 assert grid.rows == list(range(0, 12)) transform = grid.transform assert isinstance(transform, affine.Affine) assert transform.c == grid.ul[0] assert transform.f == grid.ul[1] assert transform.a == grid.res[0] assert transform.e == -grid.res[1] tile = grid[0, 0] assert isinstance(tile, grids.Tile) assert tile.bounds[0] == grid.ul[0] assert tile.bounds[-1] == grid.ul[1] assert tile.crs == grid.crs assert tile.size == grid.size assert tile.width == tile.size[0] assert tile.height == tile.size[1] assert isinstance(tile.geojson(), dict) last = grid[11, 7] with pytest.raises(IndexError, match=r'.*outside of.*limits'): grid[12, 8] all_tiles = list(grid) assert len(all_tiles) == len(grid)
def test_tilegrid_point(example_kwds_GEOG): grid = grids.TileGrid(**example_kwds_GEOG) point = (-165.0, 30.00001) # 1 tile exactly tile = grid.point_to_tile(point) assert isinstance(tile, grids.Tile) assert tile.horizontal == 1 assert tile.vertical == 4 point = (-165.0, 30.0) # just on start of other tile tile = grid.point_to_tile(point) assert tile.vertical == 5
def test_tilegrid_to_from_dict(): grid = grids.TileGrid(ul=(0, 0), crs='EPSG:32619', res=(30, 30), size=(6000, 6000), limits=((0, 9), (0, 11))) d = grid.to_dict() grid_ = grids.TileGrid.from_dict(d) for k, v in d.items(): g1 = getattr(grid, k) g2 = getattr(grid_, k) assert g1 == g2
def test_tilegrid_examples(example_kwds): grid = grids.TileGrid(**example_kwds) assert grid[0, 0].horizontal == 0 assert grid[0, 0].vertical == 0 repr_ = repr(grid).split('\n') assert re.match(f'^<TileGrid at .*>', repr_[0]) assert re.search(f'.*name: {grid.name}', repr_[1]) assert re.search(f'.*ul=.*{grid.ul[0]}, {grid.ul[1]}.*', repr_[2]) assert re.search(f'.*crs=.*', repr_[3]) assert re.search(f'.*res=.*{grid.res[0]}, {grid.res[1]}.*', repr_[4]) assert re.search(f'.*size=.*{grid.size[0]}, {grid.size[1]}.*', repr_[5]) assert re.search(f'.*limits=.*{grid.limits[-1]}.*{grid.limits[1]}', repr_[6]) if grid.limits: limits = example_kwds['limits'] assert grid.nrow == (max(limits[0]) - min(limits[0])) + 1 assert grid.ncol == (max(limits[1]) - min(limits[1])) + 1 assert len(grid) == (grid.nrow * grid.ncol)
def create_grids(): """ Create ``stems.gis.grids.TileGrid``s """ try: from stems.gis import grids except ImportError as ie: msg = 'You must install `stems` library before continuing' raise ImportError(msg) from ie else: glance_grids = {} for continent in CONTINENTS: grid = grids.TileGrid( GLANCE_GRIDS_UL_XY[continent], GLANCE_GRID_CRS_WKT[continent], GLANCE_GRIDS_RESOLUTION, GLANCE_GRIDS_SIZE, GLANCE_GRIDS_LIMITS[continent], GLANCE_GRIDS_NAME[continent] ) glance_grids[continent] = grid return glance_grids
def test_tilegrid_roi_multiple(example_kwds_GEOG): # example_grid_GEOG is 10x10 degree starting at -180x80, easy to test with grid = grids.TileGrid(**example_kwds_GEOG) roi = Polygon.from_bounds(0.5, 0.5, 10.5, 10.5) tiles = list(grid.roi_to_tiles(roi)) assert len(tiles) == 4
def example_grids(request): return grids.TileGrid(**request.param)
def example_grid_AEA(example_kwds_AEA): return grids.TileGrid(**example_kwds_AEA)
def example_grid_GEOG(example_kwds_GEOG): return grids.TileGrid(**example_kwds_GEOG)
def test_tilegrid_bounds(example_kwds_GEOG): grid = grids.TileGrid(**example_kwds_GEOG) bounds = BoundingBox(-74, 41, -69, 44) tiles = list(grid.bounds_to_tiles(bounds)) assert len(tiles) == 2
def test_tilegrid_roi_exact(example_kwds_GEOG): grid = grids.TileGrid(**example_kwds_GEOG) roi = Polygon.from_bounds(0, 0, 10, 10) # 1 tile exactly tiles = list(grid.roi_to_tiles(roi)) assert len(tiles) == 1 assert tiles[0].bbox.area == roi.area