# Forum

### Author Topic: (lat, lon, alt) into local coordinates (to use API to select BBox on the map)  (Read 1929 times)

#### ilia

• Jr. Member
• Posts: 69
##### (lat, lon, alt) into local coordinates (to use API to select BBox on the map)
« on: September 12, 2022, 11:00:39 PM »
I'm trying to predefine reconstruction region on the map by selecting some rectangular area on the map. From this area I have two corner diagonal points in format (lat0, lon0, alt0) and (lat1, lon1, alt1).

Based on this I would like to define some projection which on the next step will give a region if I also give some height for BBox. Idea is the get reconstruction region on the map, without running Metashape's GUI for it. I've tried to find possible solutions for this, but haven't found anything suitable for me. The closest topic I found so far is here:
https://www.agisoft.com/forum/index.php?topic=13222.0

But I would like to understand better this conversion from (lat, lon, height) into local coordinates (x,y,z) for selected model like WGS 84 or something. Is there any guide about such transforms in Metashape?

For an example I know that Metashape is capable quite fast calculate ruler's endpoints into (lat, lon, height). I would like to know how it does this transformation, which functions are applied and but most important how to do reverse this transform, if it not obvious to derive it from knowing transform in the opposite direction.

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14966
##### Re: (lat, lon, alt) into local coordinates (to use API to select BBox on the map)
« Reply #1 on: September 13, 2022, 11:37:28 AM »
Hello ilia,

Please see the example for the script that sets up the bounding box based on two opposite corners. The example also includes the custom dialog for X1, Y1, Z1 and X2, Y2, Z2 definition, but surely you can specify those values in headless mode with a small modification of the code.

The bounding box center, rotation and size is defined in the internal coordinate system and if you have a georeferenced chunk, the following transformation should be applied to convert the values from that internal coordinate system to geographic/projected:
Code: [Select]
`vector_internal = Metashape.Vector([x, y, z])vector_geographic = chunk.crs.project(chunk.transform.matrix.mulp(vector_internal))`Applying chunk.transform matrix converts coordinates to geocentric system and then those values have to be projected based on the coordinate system definition.
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### ilia

• Jr. Member
• Posts: 69
##### Re: (lat, lon, alt) into local coordinates (to use API to select BBox on the map)
« Reply #2 on: September 19, 2022, 08:32:49 PM »
Thank you a lot Alexey.

This helped out.