Forum

Author Topic: Convert from any coordinate system to WGS 84  (Read 5512 times)

Ainur

  • Newbie
  • *
  • Posts: 8
    • View Profile
Convert from any coordinate system to WGS 84
« on: September 23, 2016, 01:37:46 PM »
Dear Agisoft team,

do you have a script to convert from any local coordinate system to WGS 84. Just wanted to minimize manual work by batch process.

Or do I have to have separate scripts for each coordnate system to convert it to WGS?

Thanks in advance.

BR,
Ainur

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Convert from any coordinate system to WGS 84
« Reply #1 on: September 23, 2016, 02:36:43 PM »
Hello Ainur,

Conversion from the coordinate system and WGS84 is possible only if there's TOWGS84 section in the source coordinate system definition (in WKT format).
Best regards,
Alexey Pasumansky,
Agisoft LLC

Ainur

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Convert from any coordinate system to WGS 84
« Reply #2 on: September 23, 2016, 03:12:52 PM »
Hello Alexey,

thank you very much for your quick reply.

So the problem now is that I am not good in scripting... I have found out below script in the forum and have tried to run the script, but it does not work out. Could you please help me? I need to convert from EPSG::3068 to EPSG::4326 as in a testing area.

import math
import PhotoScan

print("Script started")

doc = PhotoScan.app.document
chunk = doc.chunk

new_crs = PhotoScan.CoordinateSystem("EPSG::4326")
new_wkt = new_crs.wkt.split("TOWGS84[")[1].split("]")[0]
dx, dy, dz, rx, ry, rz, s = [float(x) for x in new_wkt.split(",")]

rx = rx * math.pi  / (180. * 3600.)
ry = ry * math.pi  / (180. * 3600.)
rz = rz * math.pi  / (180. * 3600.)
s = 1.0 + s / 1.0E6

R = s * PhotoScan.Matrix([[1, -rz, ry], [rz, 1, -rx], [-ry, rx, 1]])
T = PhotoScan.Matrix([[R[0,0], R[0,1], R[0,2], dx], [R[1,0], R[1,1], R[1,2], dy], [R[2,0], R[2,1], R[2,2], dz], [0, 0, 0, 1]])

for camera in chunk.cameras:
   
   new_loc = new_crs.project(T.inv().mulp(chunk.crs.unproject(camera.reference.location)))
   camera.reference.location = new_loc
   
chunk.crs = new_crs
PhotoScan.app.update()

print("Script finished")

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Convert from any coordinate system to WGS 84
« Reply #3 on: September 23, 2016, 05:56:32 PM »
Hello Ainur,

I think that in the version 1.2.6 you can use the following code:

Code: [Select]
for camera in chunk.cameras:
      camera.reference.location = PhotoScan.CoordinateSystem.transform(camera.reference.location, crs, new_crs)
I think it should give you exactly the same result that you get using Convert button on the Reference pane toolbar. The function used above takes into account possible transformations between the datums.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Ainur

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Convert from any coordinate system to WGS 84
« Reply #4 on: September 26, 2016, 09:35:43 AM »
Hello Alexey,

I am sorry, but I am still struggling with the conversion. After changing the function I got below error:

2016-09-26 08:33:35     camera.reference.location = PhotoScan.CoordinateSystem.transform(camera.reference.location, crs, new_crs)
2016-09-26 08:33:35 NameError: name 'crs' is not defined

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Convert from any coordinate system to WGS 84
« Reply #5 on: September 26, 2016, 12:06:07 PM »
Hello Ainur,

Under crs I meant chunk.crs, so it should be
Code: [Select]
crs = chunk.crsbefore the conversion.
Best regards,
Alexey Pasumansky,
Agisoft LLC