Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: pedrounas on March 17, 2021, 12:48:22 PM

Title: Crop Raster by boundaries
Post by: pedrounas on March 17, 2021, 12:48:22 PM
Hello,

I am trying to limit the area of the generated Ortomosaic using a .gpkg file as boundaries, importing it as such:
Code: [Select]
        self.chunk.importShapes(
            path='limits.gpkg',
            boundary_type=Metashape.Shape.OuterBoundary,
            format=Metashape.ShapesFormat.ShapesFormatGeoPackage, crs=v_projection)

And when exporting the raster I am using the flag clip_to_boundary=True:
Code: [Select]
        self.chunk.exportRaster(path='ortomosaic.tiff',
                                image_format=Metashape.ImageFormatTIFF, projection=projection, clip_to_boundary=True)

Despite this the generated file is still the same as when I did not try to crop it.
Title: Re: Crop Raster by boundaries
Post by: Alexey Pasumansky on March 17, 2021, 04:07:10 PM
Hello pedrounas,

Can you please check, if the imported shapes have at least one polygon?

Also I can suggest to debug the problem in the application GUI:

1. Try to import the shapes and check, if the boundary is applied.

2. Try to export the orthomosaic, providing that the boundary shapes do exist.

I was not able to reproduce the problem on some random project.
Title: Re: Crop Raster by boundaries
Post by: pedrounas on March 17, 2021, 06:41:13 PM
The file contains one polygon which is an area inside of the larger Ortomosaic. I cannot try in GUI as I only have access to the API.
Title: Re: Crop Raster by boundaries
Post by: Alexey Pasumansky on March 17, 2021, 09:31:52 PM
Hello pedrounas,

Please try to print out the following lines after importing shape for debugging:

Code: [Select]
shape = self.chunk.shapes[-1]
print(shape.type)
print(shape.boundary_type)
print(len(shape.vertices))
print(self.chunk.shapes.crs)
print(self.chunk.orthomosaic.crs)

Can you post the output here?