I need to set chunk.crs to 'GDA + AHD', which does exist inbuilt set of CRSs. When using API I need to be able to use geoids from some particular folder, not Metashape one, so I have exact same geoids in Metashape geoid folder and in another one.
When I set CRS in UI (either through Reference Settings menu or with console) and run Alignment - all works fine.
When I do the same with API - set chunk CRS to 'GDA94 + AHD' and add geoid - MatchPhotos/Alignment fails with the error: "Vertical datum missing". But if I open the file after that - CRS is set to 'GDA94 + AHD' with geoid and Alignment from UI works fine again...
I have checked that the files in Metashape and custom geoids folder are identical.
I have attached two screenshots:
1. Setting CRS in UI - alignment runs fine
2. Opening document after setting CRS from standalone script and failing alignment (if align from this point in UI - works fine)
Code:
crs = [x for x in Metashape.CoordinateSystem().listBuiltinCRS() if x.name == 'GDA94 + AHD height'][0]
log.debug(f"CRS WKT: {crs.wkt}\n")
#### get geoid info
data = gdal.Open(geoid_path)
metadata = data.GetMetadata()
wkt = data.GetProjection()
proj = osr.SpatialReference(wkt=wkt)
epsg_tiff = proj.GetAttrValue('AUTHORITY', 1)
log.debug(f"Geoid path: {geoid_path}")
log.debug(f"Geoid WKT: {wkt}")
log.debug(f"Geoid EPSG: {epsg_tiff}")
log.debug(f"Geoid CRS name: {crs.name}")
log.debug(f"Geoid description: {metadata['TIFFTAG_IMAGEDESCRIPTION']}")
log.debug(f"CRS WKT: \n{crs.wkt}\n")
crs.addGeoid(geoid_path)
chunk.crs = crs
log.info(f"Chunk <{chunk.label}> CRS is '{chunk.crs.name}'")
Response:
2022-07-23 16:59:34,506 - DEBUG - CRS WKT:
COMPD_CS["GDA94 + AHD height",GEOGCS["GDA94",DATUM["Geocentric Datum of Australia 1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0.06155,-0.01087,-0.04019,0.0394924,0.0327221,0.0328979,-0.009993999999999999],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9102"]],AUTHORITY["EPSG","4283"]],VERT_CS["AHD height",VERT_DATUM["Australian Height Datum",2005,AUTHORITY["EPSG","5111"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","5711"]],AUTHORITY["EPSG","9464"]]
2022-07-23 16:59:34,524 - DEBUG - Geoid path: ./metashape/geoids/au_ga_AUSGeoid09_V1.01.tif
2022-07-23 16:59:34,524 - DEBUG - Geoid WKT: GEOGCRS["GDA94",DATUM["Geocentric Datum of Australia 1994",ELLIPSOID["GRS 1980",6378137,298.257222101,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,3],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],AXIS["ellipsoidal height (h)",up,ORDER[3],LENGTHUNIT["metre",1]],USAGE[SCOPE["Geodesy."],AREA["Australia including Lord Howe Island, Macquarie Island, Ashmore and Cartier Islands, Christmas Island, Cocos (Keeling) Islands, Norfolk Island. All onshore and offshore."],BBOX[-60.55,93.41,-8.47,173.34]],ID["EPSG",4939]]
2022-07-23 16:59:34,524 - DEBUG - Geoid EPSG: 4939
2022-07-23 16:59:34,524 - DEBUG - Geoid CRS name: GDA94 + AHD height
2022-07-23 16:59:34,524 - DEBUG - Geoid description: GDA94 (EPSG::4939) to AHD height (EPSG::5711)
2022-07-23 16:59:34,524 - DEBUG - CRS WKT:
COMPD_CS["GDA94 + AHD height",GEOGCS["GDA94",DATUM["Geocentric Datum of Australia 1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0.06155,-0.01087,-0.04019,0.0394924,0.0327221,0.0328979,-0.009993999999999999],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9102"]],AUTHORITY["EPSG","4283"]],VERT_CS["AHD height",VERT_DATUM["Australian Height Datum",2005,AUTHORITY["EPSG","5111"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","5711"]],AUTHORITY["EPSG","9464"]]
2022-07-23 16:59:34,525 - INFO - Chunk <API_chunk> CRS is 'GDA94 + AHD height'
2022-07-23 16:59:34,933 - CRITICAL - matchPhotos failed.
2022-07-23 16:59:34,933 - CRITICAL - Vertical datum missing