Forum

Author Topic: Setting export bounding box using geographic co-ordinates  (Read 1660 times)

ScottB

  • Newbie
  • *
  • Posts: 13
    • View Profile
Setting export bounding box using geographic co-ordinates
« on: September 26, 2021, 07:55:38 AM »
Hi,

I want to set a region when exporting an Orthomosaic and wish to do this using geographic co-ordinates, some something like:

the_region = Metashape.BBox()
the_region.min = Metashape.Vector([143.394383, -9.881762])
the_region.max = Metashape.Vector([143.394414, -9.881790])

and then use region=the_region in my export.

Note I am in the southern hemisphere hence my latitudes are negative.

This doesn't work and it seems I need to convert my co-ordinates to internal co-ordinates but while I have seen a couple of ways to do this none seem to work.

This is what I have tried:

 
Code: [Select]
  T = chunk.transform.matrix
    crs = chunk.crs

    point_one = Metashape.Vector([143.390345,  -9.867410, 0])  # in geographic coordinates
    point_one_conv = chunk.crs.unproject(point_one)

    point_two = Metashape.Vector([143.390379,  -9.867440, 0])  # in geographic coordinates
    point_two_conv = chunk.crs.unproject(point_two)

    print(point_two_conv[:2])

    the_region.min = point_one_conv[0:2]
    the_region.max = point_two_conv[0:2]

But it doesn't seem to work in that the resulting exported ortho is the full input size not the one cut to the bounding box.


Any ideas what I am doing wrong??


Thanks,



Scott.


Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: Setting export bounding box using geographic co-ordinates
« Reply #1 on: September 26, 2021, 12:17:37 PM »
Heelo ScottB,

I think that you should keep your bounding box coordinates as originally defined geographic and add the following:

Code: [Select]
orthoproj = Metashape.OrthoProjection()

orthoproj.crs = chunk.crs.geogcs  # geographic CS
and in the exportRaster command add the paramater projection = orthoproj along with the region parameter...

ie. chunk.exportRaster(...., projection = orthoproj, region = the_region, ....)

It should work,
« Last Edit: September 26, 2021, 12:21:50 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

ScottB

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Setting export bounding box using geographic co-ordinates
« Reply #2 on: September 26, 2021, 01:13:50 PM »
Hi,

Thanks for the help but it doesn't seem to work, this is what I have:

Code: [Select]
the_region = Metashape.BBox()
the_region.min = Metashape.Vector([143.390345, -9.867410])
the_region.max = Metashape.Vector([143.390380, -9.867438])

for chunk in doc.chunks:
 
    orthoproj = Metashape.OrthoProjection()
    orthoproj.crs = chunk.crs.geogcs  # geographic CS

    chunk.exportRaster(path="c:/aData/agisoftTest/outFour.tif", resolution=0.01,
                       source_data=Metashape.OrthomosaicData, save_kml=True, min_zoom_level=11,
                       max_zoom_level=27, split_in_blocks=False, block_width=4096, block_height=4096,
                       image_description="test project", projection=orthoproj, region=the_region)


So I get the same sized output with and without the region and project statements...


Thanks,



Scott.

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: Setting export bounding box using geographic co-ordinates
« Reply #3 on: September 26, 2021, 01:37:03 PM »
Scott,

maybe check the region min max lat definition, I think they are inverted...

-9.867438 is less than -9.867410
Best Regards,
Paul Pelletier,
Surveyor

ScottB

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Setting export bounding box using geographic co-ordinates
« Reply #4 on: September 26, 2021, 04:05:35 PM »
Perfect - thanks that works. Confusing as I was presuming top left and bottom right but in the southern hemisphere it is bottom left and top right...


Many thanks,



Scott.