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

Mask function generating RGB image instead of single band image. #13

Closed iamtekson closed 1 year ago

iamtekson commented 1 year ago

from the Geotile documentation on how to generate the mask, the code used was as follows:

from geotile import GeoTile
gt = GeoTile('/path/to/raster/file.tif')

# generate shapefile mask
gt.mask('/path/to/shapefile.shp', '/path/to/output/file.tif')

First, the user would have to initialize the geotile using a raster file, i.e., gt = GeoTile('/path/to/raster/file.tif') Second, the user would have to generate the mask by specifying the directory for the shapefile and the output directory for the resulting raster, i.e., gt.mask('/path/to/shapefile.shp', '/path/to/output/file.tif').

The documentation also states clearly that, "The output raster will have similar metadata as the input raster."

So I tried creating a mask using a sample shapefile and initializing the geotile using my 3-band RGB image, and the resulting mask was not binary but an RGB image.

From your tutorial, I saw that you initialized your geotile using an existing binary mask, and as such, you could get a binary mask when you masked your shapefile. In reality, however, there would not be an existing mask for a user to use to initialize their geotile. The only raster that would be available is the multiband image. Kindly take a look and fix the error.

This message from udemy course here: https://www.udemy.com/course/deep-learning-application-for-earth-observation/?referralCode=B4655A8A918826871A40

iamtekson commented 1 year ago

In order to solve this issue, you need to use gt.rasterization() function. The propose of mask function is to clip the raster dataset which is similar to extract by mask function in ArcGIS.