Forum

Author Topic: How to delete tie points, orthophotomosaic and dem data from project via python?  (Read 7433 times)

Ilya_1

  • Newbie
  • *
  • Posts: 3
    • View Profile
I need to delete points, orthophotomosaic and dem from project files.
I've tried to do it with several methods, including
```python
    def remove(self):
            self.doc.chunk.tie_points = None
            self.doc.chunk.remove((self.doc.chunk.elevation,))
            self.doc.chunk.remove((self.doc.chunk.orthomosaic,))
        self.doc.save()
```
This does delete poiters to the data, but the data itself still using disk space.
« Last Edit: August 12, 2024, 04:06:34 PM by Ilya_1 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Hello Ilya,

I think you can try to debug it in the minimalistic script and check, if it works in the following way (pretty same as in your code):

Code: [Select]
doc = Metashape.Document()
doc.open(path)
doc.chunk.tie_points = None
doc.chunk.remove(doc.chunk.elevation)
doc.chunk.remove(doc.chunk.orthomosaic)
doc.save()

I think it should work. And it would mean that the problem could be related to the way doc variable is defined or updated. Do you see other chunk folders in the project.files folder or other sub-directories related to orthomosaic or elevation with the numeric suffix?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Ilya_1

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hello Alexey!
The code you provided works great.
I do performe some multiple chunks manipulations, but before deletion i have only one chunk. I am dead sure that variables that i have points to the target chunk and target document.
The last code i've tried is:
Code: [Select]
    def remove(self,
               tie_points=False,
               dem=False,
               ortho=False,
               ):
        if tie_points:
            try:
                self.chunk.tie_points = None
            except:
                print('Не удалось удалить точки')
                pass
        if dem:
            try:
                self.chunk.remove(self.chunk.elevation)
            except:
                print('Не удалось удалить дем')
                pass
        if ortho:
            try:
                self.chunk.remove(self.chunk.orthomosaic)
            except:
                print('Не удалось удалить ортофото')
                pass

        self.doc.save()
it only prints 'Не удалось удалить ортофото', which means it perfoms other operations without exeption.
After that, the project doesn't have pointers to DEM or orthomosaic, but the size of the files is the same as without any deletion.
With code you provided, everything worked fine.
I'll try to implent it within my programm, thank you for answering.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Hello Ilya,,

The unusual thing that I see and that could be related to the problem is that you have self.doc and self.chunk.

Maybe you can use self.chunk = self.doc.chunk assignment in the beginning of the function and check, if it resolves the problem?

Another possible reason could be related to re-saving of the project using doc.save(path), where path is defined as already existing project path.
Best regards,
Alexey Pasumansky,
Agisoft LLC