Forum

Author Topic: Coordinate System of Tie Points and Dense point clouds  (Read 5367 times)

ABCT

  • Newbie
  • *
  • Posts: 6
    • View Profile
Coordinate System of Tie Points and Dense point clouds
« on: December 26, 2023, 05:54:14 AM »
Hello, I'm trying to export Dense Point Cloud and their corresponding 2D UV coordinates for every image using Python API. Firstly, I found that the "Point Cloud" is not Iterable in Python API, so I export the point cloud to a PLY file in a WGS84 crs and read it. How can I convert this crs to a local one using Python API?
I found that the code below transforms the TIe-Points to local coordinates, but it didn't work for point cloud crs, can anyone helps?

Code: [Select]
def get_coord_transform(frame, use_localframe):
    if not use_localframe:
        return frame.transform.matrix
    if not frame.region:
        print("Null region, using world crs instead of local")
        return frame.transform.matrix
    fr_to_gc  = frame.transform.matrix
    gc_to_loc = frame.crs.localframe(fr_to_gc.mulp(frame.region.center))
    fr_to_loc = gc_to_loc * fr_to_gc
    return (Metashape.Matrix.Translation(-fr_to_loc.mulp(frame.region.center)) * fr_to_loc)

Thanks in advance
Kiven
« Last Edit: December 26, 2023, 07:09:04 AM by ABCT »

Paulo

  • Hero Member
  • *****
  • Posts: 1557
    • View Profile
Re: Coordinate System of Tie Points and Dense point clouds
« Reply #1 on: December 26, 2023, 08:29:36 PM »
Hello ABCT,

since your dense cloud is exported in WGS84 geographic coordinates then you should apply to each point a WGS84 to geocentric transform as :
Code: [Select]
def wgs84_to_geoc(lat, lon, alt):
    rad_lat = lat * (math.pi / 180.0)
    rad_lon = lon * (math.pi / 180.0)

    a = 6378137.0
    finv = 298.257223563
    f = 1 / finv
    e2 = 1 - (1 - f) * (1 - f)
    v = a / math.sqrt(1 - e2 * math.sin(rad_lat) * math.sin(rad_lat))

    x = (v + alt) * math.cos(rad_lat) * math.cos(rad_lon)
    y = (v + alt) * math.cos(rad_lat) * math.sin(rad_lon)
    z = (v * (1 - e2) + alt) * math.sin(rad_lat)

    return x, y, z

And then to x,y,z geocentric coordinates apply the geoc_to_loc transform defined as (using  your code definitions):

Code: [Select]
geoc_to_loc = Metashape.Matrix.Translation(-fr_to_loc.mulp(frame.region.center)) * gc_to_loc
Hope this helps,
« Last Edit: December 27, 2023, 01:18:21 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor