Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: tristeng on November 25, 2020, 09:52:48 PM

Title: User defined coordinate system - select without requiring UI?
Post by: tristeng on November 25, 2020, 09:52:48 PM
Hi there,

I downloaded the CGVD28 geoid (HT2_0.tif), and then in the Metashape application, I created some user defined coordinate systems using the tutorial:
https://agisoft.freshdesk.com/support/solutions/articles/31000148332-how-to-use-height-above-geoid-for-the-coordinate-system

For example, I created a compound coordinate system using "NAD83(CSRS) / UTM zone 11N" and then "CGVD28 height" (from the HT2_0.tif file), which I have named "NAD83(CSRS) / UTM zone 11N + CGVD28 height".

Is there a programmatic way, using the Python API, to list the user defined coordinate systems and/or load them by the name or some other ID? I know there is a way to launch a UI selection box via API, but I would like to be able to load my user defined ones without requiring any UI interaction. Or is the suggested way to dump out the WKT data for the user-defined coordinate systems, and then use that to load the coordinate system?

Thanks,

Tristen
Title: Re: User defined coordinate system - select without requiring UI?
Post by: Alexey Pasumansky on November 25, 2020, 10:13:50 PM
Hello tristeng,

If you are calling the script from the command line via -r argument, you should have the related geoid file in /Metashape Pro/geoids/ directory whereas the coordinate system can be assigned from the WKT line, for example:
wkt = '...' #just as a string with the coordinate system definition
crs = Metashape.CoordinateSystem(wkt)

In case you are using the stand-alone Python module, you should initialize the path to the geoid file in the beginning of the script (before the related coordinate system is used) by calling Metashape.CoordinateSystem.addGeoid(path) method.
Title: Re: User defined coordinate system - select without requiring UI?
Post by: tristeng on November 25, 2020, 10:38:19 PM
Perfect, thank you.
Title: Re: User defined coordinate system - select without requiring UI?
Post by: tristeng on November 25, 2020, 11:14:54 PM
I did notice that since I do have the Metashape application installed, and my geoids are in the installation directory's geoids directory, I was able to load my coordinate system using Python stand alone by specifying the authority string (without first adding the geoid):

Code: [Select]
>>> import Metashape
>>> Metashape.CoordinateSystem('EPSG::5713')
<CoordinateSystem 'CGVD28 height (EPSG::5713)'>

I'm guessing that once the geoids are registered with the Metashape API (whether explicitly via addGeoid or implicitly via Metashape installation geoids directory), we can then use the authority string?
Title: Re: User defined coordinate system - select without requiring UI?
Post by: Alexey Pasumansky on November 26, 2020, 12:47:36 PM
Hello tristeng,

You can use definition with EPSG code, if the required compound system is available in registry, so it is not obligatory to use WKT line for such case.