Crop
Satellite data products, especially those with high resolution, often cover vast geographical areas, sometimes larger than what is needed for a specific analysis. To manage these large datasets and focus on the region of interest, it is essential to crop the images to the desired area.
The Area of Interest (AOI) is typically defined during the data download phase, where you specify a shapefile or other geospatial boundary file that outlines the region you want to analyze. This shapefile could be in formats like .shp, .geojson, .kml, or .gpkg.
If the cropped result does not contain any data (all values are 0), then the result is not saved or if the input and output directory are equal, deleted.
Once the satellite image has been downloaded, cropping ensures that only the pixels falling within this AOI are retained, while the rest of the image, which is outside the AOI, is discarded. This reduces the size of the dataset, making it more manageable for further processing and analysis.
Crop Methods¤
There are two primary methods available for cropping the raster using the shapefile:
CropMethod.SHAPE: This method crops the raster to the exact shape defined by the shapefile. Only the area inside the shapefile's boundaries will be retained in the output image, ensuring that the data is cropped precisely to your AOI.CropMethod.TOTAL_BOUNDS: This method crops the raster to the bounding box of the shapefile, which is the smallest rectangle that completely contains the shapefile’s shape. This can be useful when you want to include all pixels that fall within the overall extent of the shapefile's boundary, without needing to adhere to the specific shape or outline.
Parameters
| Name | Type | Description |
|---|---|---|
input_dir |
str |
Input directory containing GeoTIFF files. Can contain subfolders. |
output_dir |
str |
Output directory. If same as input then the original files are overwritten. Keeps subfolders. |
shapefile_path |
str |
A shapefile is used to define the AOI for cropping. The shapefile should contain the geographic boundaries that you want to preserve in the output image. Supported formats: .shp, .geojson, .kml, .gpkg |
crop_method |
CropMethod |
Crop-Method used for cropping. Default is CropMethod.SHAPE |
delete_empty |
bool |
Delete images with no valid pixel remaining. Default is False |
num_processes |
int |
Process multiple files in parallel using multi-processing. Default is 1. |