77 split raster
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install -U leafmap
# %pip install -U leafmap
In [2]:
Copied!
import leafmap
import leafmap
Create an interactive map and add a raster layer to it.
In [3]:
Copied!
m = leafmap.Map()
url = 'https://open.gishub.org/data/raster/cog.tif'
m.add_cog_layer(url, name='COG')
m
m = leafmap.Map()
url = 'https://open.gishub.org/data/raster/cog.tif'
m.add_cog_layer(url, name='COG')
m
Out[3]:
Split the raster layer into multiple tiles.
In [4]:
Copied!
leafmap.split_raster(url, out_dir='tiles', tile_size=(100, 100), overlap=0)
leafmap.split_raster(url, out_dir='tiles', tile_size=(100, 100), overlap=0)
cog.tif already exists. Skip downloading. Set overwrite=True to overwrite.
Show the tiles.
In [5]:
Copied!
leafmap.find_files('tiles', ext='.tif')
leafmap.find_files('tiles', ext='.tif')
Out[5]:
['tiles/tile_0_0.tif', 'tiles/tile_0_1.tif', 'tiles/tile_0_2.tif', 'tiles/tile_1_0.tif', 'tiles/tile_1_1.tif', 'tiles/tile_1_2.tif', 'tiles/tile_2_0.tif', 'tiles/tile_2_1.tif', 'tiles/tile_2_2.tif', 'tiles/tile_3_0.tif', 'tiles/tile_3_1.tif', 'tiles/tile_3_2.tif']
Merge the tiles into a single raster dataset.
In [6]:
Copied!
leafmap.merge_rasters('tiles', output='merged.tif', input_pattern='*.tif')
leafmap.merge_rasters('tiles', output='merged.tif', input_pattern='*.tif')
Last update:
2023-09-22
Created: 2023-09-22
Created: 2023-09-22