We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cropping a Raster Image using Vector Shape

I am wondering if there is a built-in or easy method to clip or crop a raster file using a vector shape. For example, let’s say I have a geotiff satellite data file, but have a specific area of interest in WKT. I’d like to crop the raster to my area of interest bounding rectangle and then mask so anything outside my AOI is transparent. Is this possible with Aspose.GIS?

Hi, @msmearer

Thank you for your interest in the Aspose.GIS product.

Unfortunately, by the moment Aspose.GIS has no option to clip or crop a raster layer using shape form. I have created a ticket GISNET- 1219 and update you here as soon as additional information is available.

Please feel free to contact us if you have any other issues or product questions.

Thank you for the quick response!


I second that request. Was actually creating a post for a similar/the same request. Basically it would be great to obtain an XYZ web tile layer and overlay it onto an extent of a vector shape an then clip/crop the web tile layer so that only the area of the web tile(s) which fit the extent is actually displayed.

Theres actually an online SVG implementation of this written in javascript if you are interested in the link.

Hi, @yemoku

Thank you for paying attention to this topic. I have raised the priority of the GISNET- 1219 ticket.

Thanks for the second, @yemoku. I’ve done more digging around and have a very rough working example using GDAL warp with a “cutline”. It’s complicated, feels a bit fragile, and involves several data format transformations. I’d love a fully managed .Net way to do this!

I appreciate the bump, @Evgeniy.Timofeev.


I was looking at the javascript (node.js) route to achieve this since Mike Bostock had already put up a great working sample in D3 (D3 Sample)

But hopefully the Aspose.GIS team will be able to pull this off in a much cleaner fashion.

thanks, we will try to make the implementation as good as possible

Hello @msmearer ,

Cropping a raster image(GISNET-1219) has been implemented in Aspose.GIS for .NET 21.7. Please feel free to contact us if you have any other issues or difficulty using the product.

Fantastic news - I will check it out as soon as possible. Really impressive response from the Aspose team!


Greetings. This is a great development by the team. Have tried using the functionality by customizing your documented sample code: Cropping raster layer

I actually tried using an xyz tile layer with the syntax xyztile.AsRaster().Crop… but the function always returns null no matter the size of the extent. Is this syntax incorrect?

Many thanks



I think the specified shape has no Mercator coordinates. Please try using Mercator coordinates.

// Return null. The WGS 84 coordinates is bad
var crop1 = raster.Crop(new Extent(-90, -40, 90, 40).ToPolygon());
// Return some values. The mercator coordinates is good.
var crop2 = raster.Crop(new Extent(-20037508, -20037508, 20037508, 20037508).ToPolygon());

Please feel free to contact us if you have any other issues or product questions.

Ok, can we try a slight variation on this scenario? :slight_smile: I am using a valid polygon layer to generate the extent as such:

var extie = new Extent(layer.GetExtent.XMin, layer.GetExtent.YMin, layer.GetExtent.XMax, layer.GetExtent.YMax)


var extie = layer.GetExtent

Then i am trying your lines above:

extie.SpatialReferenceSystem = Wgs84 // as a caveat
var crop3 = raster.Crop(extie.ToPolygon());

which fails as it returns null in the call. Is there something I am missing here?

Many thanks

Please try below code

var extie = layer.GetExtent().GetTransformed(raster.SpatialReferenceSystem)
// or 
var extie = layer.GetExtent().GetTransformed(SpatialReferenceSystem.WebMercator)

I have created GISNET-1257 ticket to convert a shape in a raster spatial reference system for Crop. And we started this task.

Also we found an issue when renders cropped layers (ticket GISNET-1258). But we have already fixed it and going to release in the nearest build.


Hi, @msmearer, @yemoku

The GISNET-1257 and GISNET-1258 tickets have been fixed in Aspose.GIS for .NET 21.8 . Please feel free to contact us if you have any other issues or difficulty using the product.

Many thanks

image001.jpg (173 Bytes)

Hello Evgeniy,

Further to the implementation of the Crop functionality as described above, it appears that it functions to place a minimal rectangular raster layer around the extent.

Is it still possible to implement the functionality for a raster layer to clip or crop exactly around the boundaries of the extent? I have attached a link to an article which illustrates the method and effect of achieving this using QGIS.

Raster Mosaicing and Clipping

Many thanks

Hi, @yemoku

I need to explore your request. I’ll be back with an answer after the weekend.


Ok. Did you ever get a chance to look at this feature?


Hi, @yemoku

Sorry for not answering.

In the article, I found that they select cells using a given value for bands. We’ll add a crop option too.

I have created a ticket GISNET-1351 and update you here as soon as additional information is available.

Thanks for the idea.