osgeonepal / geotile

GeoTile is the python library for tiling the geographic raster data (eg. Tiff etc)
https://geotile.readthedocs.io
MIT License
74 stars 9 forks source link

Need function to construct the single prediction raster from tiles #18

Closed iamtekson closed 1 year ago

iamtekson commented 1 year ago

Now it can be done with following code,

from geotile import GeoTile
import numpy as np
gt = GeoTile(r"path/to/raster.tif")

# generate tiles but save it only on the class
gt.generate_tiles(r'../data/test_tiles', save_tiles = False)

# normalize data
gt.normalize_tiles()

# convert nan values to zero
gt.convert_nan_to_zero()

From above code, the data will be stored in gt.tile_data with shape (num_sample, x, y, num_bands). Now you can run the prediction code and replace the tile_data as below,

prediction = model.predict(gt.tile_data) 

# You can run intermediate steps such as thresholding, reshaping etc
# But you need to finally reshape it to (num_sample, x, y, num_bands) format
# after that, simply overwrite the tile_data in geotile 
gt.tile_data = prediction 
gt.save_tiles('/path/to/output/folder')

After saving the tiles, you can merge tiles by following code;

from geotile import mosaic
mosaic('/path/to/input/tiles', '/path/to/output/file.tif')
Memelly12 commented 1 week ago

please my model give me images with different shape but when i save the tiles, the shape of my images don't change