1
Python and Java API / Export Orthomosaic by shape extent with shape label in filename
« on: February 23, 2021, 03:52:02 PM »
Hi,
I have an ortomosaic that I need to split by blocks and the in the filename of each exported block I need to have shape label.
I am trying to proceed with Python script, but I must say I am only a beginner in Python scripting, so maby I am doing something wrong.
I have rewieved some topics that already mention this problem but it did not help me.
One of the problems I have that wasn's menton i those topics is that I can't use the shape with blocks as Outer Boundary - I am already using differenet shape for that as I need two boundaries - it is a network project with buffer along the line, so I need to set the buffer as my Outer Boundary.
I was trying to go the following way - for each block in my shapes layer I try to export orthomosaic that would have the region set to the block's extent. But I must do somerhing wrog there, as each time whole orthomosaic is being exported, like the boundaries were not set at all. I tried setting the boundaries in different ways, but non of it worked.
At lest the file name is correct..
Below is part of the code that I use
When I call tile_region i get Metashape.BBox at 0x288af34ea90 which does't tell me nothing about the actual boundaries.
I also tried to use something like
which also returned some bounding box (different than in the code above), but didnt do the job.
Can anyone point at what am I doing wrong with my code?
It is very easy to set correct boundaries in orthomosaic export dialog box in the Setup Boundaries section, but then i dont get correct names for my files.
Edit:
Sorry i messed up the code when posting here, now it is like I tried it.
I have an ortomosaic that I need to split by blocks and the in the filename of each exported block I need to have shape label.
I am trying to proceed with Python script, but I must say I am only a beginner in Python scripting, so maby I am doing something wrong.
I have rewieved some topics that already mention this problem but it did not help me.
One of the problems I have that wasn's menton i those topics is that I can't use the shape with blocks as Outer Boundary - I am already using differenet shape for that as I need two boundaries - it is a network project with buffer along the line, so I need to set the buffer as my Outer Boundary.
I was trying to go the following way - for each block in my shapes layer I try to export orthomosaic that would have the region set to the block's extent. But I must do somerhing wrog there, as each time whole orthomosaic is being exported, like the boundaries were not set at all. I tried setting the boundaries in different ways, but non of it worked.
At lest the file name is correct..
Below is part of the code that I use
Code: [Select]
import Metashape
#compression
compression = Metashape.ImageCompression()
compression.tiff_compression = Metashape.ImageCompression.TiffCompressionLZW
compression.jpeg_quality = 95
compression.tiff_big = False
compression.tiff_compression = True
compression.tiff_overviews = True
#export
chunk = Metashape.app.document.chunk
ortho = chunk.orthomosaic
ortho_projection = ortho.projection
tiles =[]
for shp in chunk.shapes:
if shp.selected == True:
tiles.append(shp)
for tile in tiles:
t_min = tile.vertices[1]
t_max = tile.vertices[3]
tile_region = Metashape.BBox()
tile_region.min = Metashape.Vector(t_min)
tile_region.max = Metashape.Vector(t_max)
tile_label = tile.label
chunk.exportRaster(path = out_path + line_name + '_'+tile_label+'.tif', projection = ortho_projection, region = tile_region, resolution_x = pixel_size_x_m, resolution_y = pixel_size_y_m, image_compression=compression, save_world = True, white_background = False,)
When I call tile_region i get Metashape.BBox at 0x288af34ea90 which does't tell me nothing about the actual boundaries.
I also tried to use something like
Code: [Select]
tile_region = Metashape.BBox(tile.vertices)
which also returned some bounding box (different than in the code above), but didnt do the job.
Can anyone point at what am I doing wrong with my code?
It is very easy to set correct boundaries in orthomosaic export dialog box in the Setup Boundaries section, but then i dont get correct names for my files.
Edit:
Sorry i messed up the code when posting here, now it is like I tried it.