Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Ilya_1

Pages: [1]
1
Python and Java API / How to export orthomosaic with sqare pixel?
« on: August 21, 2024, 02:56:53 PM »
Hello!
I am trying to create a task to export orthomosaic with specified resolution in meters.
When do it manually (in metashape withot python), i achive it by the next steps:
1. I open "export orthomosaic" menu
2. I set resolusion in meters to 0.1
3. The pixel size (m) correspondingly changes for new resolution. If it isn't sqare, i simply copy res in X into Y. (as i see it changes te res in meterers a littlebit, but it's not a bit deal).

Now i am trying to recreate this behaviour in python code. For now  i have this:
Code: [Select]
    def export_ortho(self, export_path, resolution):
        task = Metashape.Tasks.ExportRaster()
        task.source_data = Metashape.OrthomosaicData
        task.path = export_path
        task.resolution = resolution
        return task

As far as i understand, i have to specify resolution_x and resolution_y instead of resolution, but i don't understand how to calculate them.
Note: I work in EPSG::3857

2
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.

3
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.

Pages: [1]