Forum

Author Topic: How to Transform DEM with Python API?  (Read 6707 times)

Octave A.

  • Newbie
  • *
  • Posts: 4
    • View Profile
How to Transform DEM with Python API?
« on: January 11, 2024, 09:12:24 PM »
I have created 2 DEMs with buildDem, one represents the raw surface elevation with only ground points and one contain all classes after ground point classification.

I don't know how to name them in the Python API so they probably have very similar name, which would probably be a difficulty.

I want to calculate "Canopy Height" which is basically the difference between the 2 DEMs.

I can do that on the GUI by right clicking on one of the DEM and basically following the tutorial here : https://agisoft.freshdesk.com/support/solutions/articles/31000156301-transform-dem-functionality-for-dem-difference-calculation but I haven't found a command to do that in the python API.

I'm currently using version 1.8.4

Thanks a lot in advance for your help !

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15407
    • View Profile
Re: How to Transform DEM with Python API?
« Reply #1 on: January 12, 2024, 12:39:39 PM »
Hello o.ati,

Seems that you are looking for transformRaster() function.

You need to set subtract argument to True and define the operand_asset as elevation.key for the DEM that should be subtracted from the active DEM.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Octave A.

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to Transform DEM with Python API?
« Reply #2 on: January 12, 2024, 04:39:00 PM »
Thanks a lot that worked perfectly !

For those who'll be reading this post its necessary to copy the elevation model before generating because by default buildDem overwrites the current DEM:

Code: [Select]
chunk.elevation.copy()
chunk.elevation.label = "Elevation Label"
chunk.buildDem() # This won't overwrite the previous model

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15407
    • View Profile
Re: How to Transform DEM with Python API?
« Reply #3 on: January 12, 2024, 05:02:34 PM »
Hello Octave,

Another way to make current DEM inactive is:
Code: [Select]
chunk.elevation = None
Best regards,
Alexey Pasumansky,
Agisoft LLC

Octave A.

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to Transform DEM with Python API?
« Reply #4 on: January 12, 2024, 07:41:07 PM »
Thanks a lot for your insight !

aloeb

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: How to Transform DEM with Python API?
« Reply #5 on: March 28, 2024, 05:29:54 PM »
Hello,
I have the same problem but I'm not sure how to use the transformRaster() function.
How to find the elevation.key for the DEM that should be subtracted from the active DEM ?
Also, do you have an example with this function (it might help me)

here is my unfinished code :
Code: [Select]
chunk.buildDem(source_data=Metashape.PointCloudData, interpolation=Metashape.DisabledInterpolation)  # first DEM
chunk.elevation.label = "Initial Elevation"
chunk.buildDem(source_data=Metashape.PointCloudData, interpolation=Metashape.Extrapolated, classes=Metashape.Ground) # ground DEM to subtract to the other
chunk.elevation.label = "Ground Elevation"
chunk.elevation = None
chunk.transformRaster(source_data=Metashape.ElevationData, subtract=True, ...)

Paulo

  • Hero Member
  • *****
  • Posts: 1492
    • View Profile
Re: How to Transform DEM with Python API?
« Reply #6 on: March 28, 2024, 06:47:48 PM »
Hi,

for each elevation in chunk.elevations, its key = elevation.key.

So in example, I have Surface model with key = 5 and Terrain model with key = 3.

So in chunk.transformRaster, I use asset = 5 and operand_asset = 3 to subtract terrain from surface...
« Last Edit: March 28, 2024, 06:51:15 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor