You’re welcome.
Will add some other “visualization category” feature requests under a different post.
You’re welcome.
Will add some other “visualization category” feature requests under a different post.
Greetings. Any luck with implementing this feature?
Hello,
You can now clip or crop a raster using a vector geometry directly with Aspose.GIS 21.7 (and later). The RasterLayer.Crop method accepts any geometry (polygon, extent, etc.) and returns a new raster where the area outside the geometry is made transparent.
Basic example (C#)
using Aspose.Gis;
using Aspose.Gis.Geometries;
using Aspose.Gis.SpatialReferencing;
// Open the source raster
using (var raster = RasterLayer.Open(@"C:\Data\satellite.tif"))
{
// Load the AOI polygon (WKT) – ensure it uses the same SRS as the raster
var aoi = Geometry.FromWkt(
"POLYGON ((...))",
SpatialReferenceSystem.Wgs84); // or raster.SpatialReferenceSystem if different
// If the raster uses Web Mercator, transform the AOI
var aoiInRasterSrs = aoi.GetTransformed(raster.SpatialReferenceSystem);
// Crop the raster
using (var cropped = raster.Crop(aoiInRasterSrs))
{
// Save the result (GeoTIFF with transparent background)
cropped.Save(@"C:\Data\satellite_cropped.tif", RasterFileFormat.GeoTiff);
}
}
Key points
GetTransformed to convert it if needed (e.g., WGS‑84 → Web Mercator).Extent.ToPolygon() for a simple rectangular AOI, or any complex polygon for precise clipping.Documentation: Cropping raster layers – includes additional samples and details on handling different spatial reference systems.
If you encounter null results, double‑check that the geometry’s coordinates match the raster’s CRS. In earlier versions this was a common cause of the issue.
Feel free to ask if you need help with coordinate transformations or further customisation.