Forum

Author Topic: crop raster to nodata extent?  (Read 468 times)

andyroo

  • Sr. Member
  • ****
  • Posts: 373
    • View Profile
crop raster to nodata extent?
« on: December 10, 2020, 04:55:51 AM »
For some reason I was under the impression that rasters were built only to the data extent. Is it actually the bounding box?

If so, it would be nice to have a "crop to data extent" option. I have a project where I have three sets of images overlapping but covering different sub-parts of the total aligned project. I iterated through aligned sets of images disabling all but one to generate three different dense clouds, then built DEMs for each dense cloud. THe DEMs all have roughly the same extent (as the total cloud) even though one of them only occupies about 10% of the area. It makes the raster size and export time much larger/longer than if they were cropped to the data extent. Now I have to process to trim to the data extent in external software. To do this with a shapefile is complicated because I am trying to maintain integer bounding boxes, and it would be nice to be able to do it procedurally (python script) or in batch.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 12742
    • View Profile
Re: crop raster to nodata extent?
« Reply #1 on: December 10, 2020, 01:48:06 PM »
Hello andyroo,

Do you mean, that the bounding box remains the same (for the whole area), whereas the dense clouds and DEMs are generated within much smaller area?

If you do not want to alter the bounding box for each subset, maybe you can try to use region argument when building DEM?
Code: [Select]
region = Metashape.BBox()
region.min = Metashape.Vector([x0, y0])
region.max = Metashape.Vector([x1, y1])
chunk.buildDem(region = region)
Best regards,
Alexey Pasumansky,
Agisoft LLC

andyroo

  • Sr. Member
  • ****
  • Posts: 373
    • View Profile
Re: crop raster to nodata extent?
« Reply #2 on: March 17, 2021, 12:29:34 AM »
To clarify:

I originally thought that when exporting a DEM and I select "region" that the x and y bounds that auto-populate are the extent of data in the DEM, but it appears that these numbers are the XY extent of the bounding rectangle for the Metashape region when the DEM was created. It would be nice to be able to only export a raster that has the extent of the data, rather than having to manually build a bounding box. Because the regions are often oriented at an angle to the gridding system of the DEM, the effect is to produce a nodata collar - in some cases one that is tens or hundreds of km outside of the data extent in our use case.

I produce my DEMs in a GCS at full resolution then export in a PCS because in some cases we may export in several different PCSs depending on user.

Alternatively, is there a good way to query the data extent and deliver it in a projected coordinate system so it can be scripted?

Also if anyone knows a good (efficient) way outside of metashape to "trim" nodata I would love to hear it. My method was to create a model in QGIS that used the SAGA crop data to raster tool, then converted from .sdat back to geotiff with gdal_translate. clunky.