#!/usr/bin/python3
import sys
import Metashape
import os
from pathlib import Path
current_path = os.getcwd()
parent_path = str(Path(current_path).parent)
save_path = ''
project_name = ''
def main():
project_folder_name = 'project2'
# save path
save_path = parent_path + '/projects/' \
+ project_folder_name + '/' \
+ project_folder_name
# + '_' \
# + start_time
# creating save directory
os.makedirs(name=save_path, exist_ok=True)
global project_name
project_name = 'main_file.psx'
# creating document
doc = Metashape.Document()
# epsg_code
epsg_code = 'EPSG::32643'
doc.open(path=save_path + '/' + project_name)
# adding chunk
chunk = Metashape.Chunk
chunk = doc.chunk
# adding co-ordinate reference system
# chunk.crs = Metashape.CoordinateSystem(epsg_code)
raster_compression = Metashape.ImageCompression()
raster_compression.tiff_compression = Metashape. \
ImageCompression.TiffCompressionJPEG
raster_compression.jpeg_quality = 90
raster_compression.tiff_big = True
# projection
projection = Metashape.OrthoProjection()
projection.crs = Metashape.CoordinateSystem(epsg_code)
chunk.exportRaster(
path=parent_path + '/projects/'
+ project_folder_name + '/' + 'export/' + 'orthophoto.tif',
format=Metashape.RasterFormatTiles,
image_format=Metashape.ImageFormat.ImageFormatTIFF,
projection=projection,
save_world=True,
save_alpha=True,
image_description='Orthophoto',
image_compression=raster_compression,
white_background=True,
save_kml=False,
)
doc.save(path=save_path + '/' + project_name, chunks=[chunk])
return
main()
LoadProject: path = /home/xxxx/projects/project2/project2/main_file.psx
loaded project in 0.000677 sec
Traceback (most recent call last):
File "testing_arguments.py", line 74, in <module>
main()
File "testing_arguments.py", line 55, in main
chunk.exportRaster(
AttributeError: 'NoneType' object has no attribute 'exportRaster'
chunk>(Right click)> Export xyz option
2020-11-04T22:12:04.586 +0530 INFO [init_doc.py: 82] ****************************************************************************************************
2020-11-04T22:12:04.586 +0530 INFO [init_doc.py: 83] logger initiated
2020-11-04T22:12:04.586 +0530 INFO [init_doc.py:436] Options: {'projectName': 'attur', 'geoProjection': 'EPSG::32643', 'exportRaster': 'true',[b] 'lastStep': '5'[/b]}
2020-11-04T22:12:04.586 +0530 INFO [init_doc.py:437] Processing started
2020-11-04T22:12:04.587 +0530 INFO [init_doc.py:462] Opening existing file: /home/mapboxuser/projects/attur/attur/main_file.psx
2020-11-04T22:12:04.787 +0530 INFO [init_doc.py: 89] Retrieve/Add Chunk
2020-11-04T22:12:04.843 +0530 INFO [init_doc.py:100] Adding Chunk Completed
2020-11-04T22:12:04.844 +0530 INFO [init_doc.py:396] Raster Extraction Started
2020-11-04T22:12:05.045 +0530 ERROR [init_doc.py:413] Error while exporting Orthomosaic. Error: Null orthomosaic
2020-11-04T22:12:19.580 +0530 INFO [init_doc.py: 82] ****************************************************************************************************
2020-11-04T22:12:19.580 +0530 INFO [init_doc.py: 83] logger initiated
2020-11-04T22:12:19.580 +0530 INFO [init_doc.py:436] Options: {'projectName': 'attur', 'geoProjection': 'EPSG::32643', [b]'lastStep': '4'[/b], 'exportRaster': 'true'}
2020-11-04T22:12:19.580 +0530 INFO [init_doc.py:437] Processing started
2020-11-04T22:12:19.581 +0530 INFO [init_doc.py:462] Opening existing file: /home/mapboxuser/projects/attur/attur/main_file.psx
2020-11-04T22:12:19.781 +0530 INFO [init_doc.py: 89] Retrieve/Add Chunk
2020-11-04T22:12:19.835 +0530 INFO [init_doc.py:100] Adding Chunk Completed
2020-11-04T22:12:19.836 +0530 INFO [init_doc.py:358] step5 started
2020-11-04T22:12:19.836 +0530 INFO [init_doc.py:360] building orthomosaic started
2020-11-04T22:12:20.037 +0530 ERROR [init_doc.py:368] Error in Build Depth Maps Step Null elevation
Traceback (most recent call last):
File "init_doc.py", line 364, in begin_image_processing
projection=projection
Exception: Null elevation
2020-11-04T22:12:24.085 +0530 INFO [init_doc.py: 82] ****************************************************************************************************
2020-11-04T22:12:24.085 +0530 INFO [init_doc.py: 83] logger initiated
2020-11-04T22:12:24.086 +0530 INFO [init_doc.py:436] Options: {'exportRaster': 'true', 'geoProjection': 'EPSG::32643', 'projectName': 'attur', [b]'lastStep': '3'[/b]}
2020-11-04T22:12:24.086 +0530 INFO [init_doc.py:437] Processing started
2020-11-04T22:12:24.086 +0530 INFO [init_doc.py:462] Opening existing file: /home/mapboxuser/projects/attur/attur/main_file.psx
2020-11-04T22:12:24.286 +0530 INFO [init_doc.py: 89] Retrieve/Add Chunk
2020-11-04T22:12:24.340 +0530 INFO [init_doc.py:100] Adding Chunk Completed
2020-11-04T22:12:24.341 +0530 INFO [init_doc.py:339] step4 started
2020-11-04T22:12:24.341 +0530 INFO [init_doc.py:341] building DEM started
2020-11-04T22:12:24.542 +0530 ERROR [init_doc.py:348] Error in Build DEM Step Null dense cloud
Traceback (most recent call last):
File "init_doc.py", line 344, in begin_image_processing
projection=projection
Exception: Null dense cloud
2020-11-04T22:12:28.030 +0530 INFO [init_doc.py: 82] ****************************************************************************************************
2020-11-04T22:12:28.030 +0530 INFO [init_doc.py: 83] logger initiated
2020-11-04T22:12:28.030 +0530 INFO [init_doc.py:436] Options: {[b]'lastStep': '2'[/b], 'geoProjection': 'EPSG::32643', 'projectName': 'attur', 'exportRaster': 'true'}
2020-11-04T22:12:28.030 +0530 INFO [init_doc.py:437] Processing started
2020-11-04T22:12:28.030 +0530 INFO [init_doc.py:462] Opening existing file: /home/mapboxuser/projects/attur/attur/main_file.psx
2020-11-04T22:12:28.231 +0530 INFO [init_doc.py: 89] Retrieve/Add Chunk
2020-11-04T22:12:28.285 +0530 INFO [init_doc.py:100] Adding Chunk Completed
2020-11-04T22:12:28.286 +0530 INFO [init_doc.py:308] step3 started
2020-11-04T22:12:28.286 +0530 INFO [init_doc.py:310] building depthmaps started
2020-11-04T22:12:28.487 +0530 ERROR [init_doc.py:318] Error in Build Depth Maps Step Empty region
Traceback (most recent call last):
File "init_doc.py", line 314, in begin_image_processing
reuse_depth=reuse_depth
Exception: Empty region
/home/mapboxuser/Downloads/metashape-pro/metashape.sh -r init_doc.py --projectName attur --geoProjection EPSG::32643 --exportRaster true [b]--lastStep 2[/b]
chunk.exportRaster(
path=export_path + 'dsm.tif',
format=Metashape.RasterFormatTiles,
image_format=Metashape.ImageFormat.ImageFormatTIFF,
projection=projection,
save_world=True,
save_alpha=True,
image_description='DSM',
white_background=True,
save_kml=True,
source_data=Metashape.DataSource.ElevationData
)
chunk.exportRaster(
path=export_path + 'dsm.tif',
raster_transform=Metashape.RasterTransformType.RasterTransformPalette, #modification here
format=Metashape.RasterFormatTiles,
image_format=Metashape.ImageFormat.ImageFormatTIFF,
projection=projection,
save_world=True,
save_alpha=True,
image_description='DSM',
white_background=True,
save_kml=True,
source_data=Metashape.DataSource.ElevationData
)
chunk.exportRaster(
path=export_path + 'dsm.tif',
format=Metashape.RasterFormatTiles,
image_format=Metashape.ImageFormat.ImageFormatTIFF,
projection=projection,
save_world=True,
save_alpha=True,
image_description='DSM',
white_background=True,
save_kml=True,
source_data=Metashape.DataSource.ElevationData
)
Hello darkl1ght,
32-bit TIFF with the elevation data is a single-channel raster where each pixel contains a floating point corresponding to the elevation. It is not a grayscale image, the visual color representation should be adjusted in the application that you are using to view the file.
Hello darkl1ght,
Do you mean that you need to export DEM as four channel TIFF file with RGB channels and elevation data in the fourth channel?
--> I dont know if that is possible or not, but it can be seen in Image1, Agisoft UI has RGB + elevation data.
Do you have any example of data in such representation? Unless I am mistaken, TIFF format doesn't allow to have different data types for the channels in the same file, therefore all four bands in such case should be either 8-bit or 32-bit. And I have some doubts that 8-bit float would allow to save the elevation values with proper grade of accuracy.
-->I am not that expert in image processing, so I don't know if I can answer that. Its okay if TIFF does not allow that to happen, but is there any other way to export the DEM that allows it?