geetools.ImageAccessor.toGrid#
- geetools.ImageAccessor.toGrid(size=1, band='', geometry=None)#
Convert an image to a grid of polygons.
Based on the size given by the user, the tool will build a grid of size*pixelSize x size * pixelSize cells. Each cell will be a polygon. Note that for images that have multiple scale depending on the band, we will use the first one or the one stated in the parameters.
- Parameters:
size (geetools.types.ee_int) – The size of the grid. It will be size * pixelSize x size * pixelSize cells.
band (geetools.types.ee_str) – The band to burn into the grid.
geometry (Optional[ee.Geometry]) – The geometry to use as reference for the grid. If None, the image footprint will be used.
- Returns:
The grid as a FeatureCollection.
- Return type:
ee.FeatureCollection
Note
The method has a known bug when the projection of the image is different than 3857. As we use a buffer, the grid cells can slightly overlap. Feel free to open a Issue and contribute if you feel it needs improvements.
Examples
import ee, geetools ee.Initialize() src = 'COPERNICUS/S2_SR_HARMONIZED/20200101T100319_20200101T100321_T32TQM' image = ee.Image(src) buffer = ee.Geometry.Point([12.4534, 41.9033]).buffer(100) grid = image.geetools.toGrid(1, 'B2', buffer) print(grid.getInfo())