Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: BarryReid on June 11, 2015, 05:05:20 AM
-
Hi there
I'm trying to figure out how to convert the coordinate system on all cameras using the API.
I have tried something like this
crs = app.getCoordinateSystem("Select project coordinate system")
chunk.crs = crs
But that changes the project coordinate system but does not convert the cameras projection from the old to the new.
I just want it to do the same thing as hitting the convert button on the camera reference tab.
-
Hello Barry,
In order to convert coordinates for system based on the same Datum, you need to unproject coordinates using the first coordinate system and then project using the second one:
coord = PhotoScan.Vector([X, Y, Z])
crs = PhotoScan.CoordinateSystem("EPSG::...")
crs_new = PhotoScan.CoordinateSystem("EPSG::...")
coord = crs.unproject(coord)
coord = crs_new.project(coord)
-
I'm sorry, I don't understand well the Vector part! what are X, Y, Z and where I can find these, for example in an opened project with metashape?
Because I trying to change the crs by scripts on a Metashape project, but I don't understand this part! I'm sorry for bother!
Thank you in advance,
Best regards,
Emanuele.
-
Hello Emanuele,
Please check the following code:
source_crs = PhotoScan.CoordinateSystem("EPSG::4326")
target_crs = PhotoScan.CoordinateSystem("EPSG::32623")
chunk = Metashape.app.document.chunk
for camera in chunk.camers:
if not camera.reference.location:
continue
camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, source_crs, target_crs)
-
Hi Alexy, thank you for your support!
I made the wrong question probably before, so I need to ask you now another thing.
What I mean is: How I can get the vector coordinates normally? Because I work in pycharm so I usually don't open Agisoft Metashape for this elaborations.
So, my question is, if I need to change e camera and project crs, where I can find vector coordinates? In more, I tried both the method, but when I open for check agisoft and the project, and I go on the calculator icon on reference, I see that the crs is not change! It is normal?
Sorry for the questions, I want only understand how to work this things!
-
Hello Emanuele,
as specified by Alexey, let us say you have your cameras referenced in WGS84 CRS (chunk.crs) and want to convert them to WGS84/ UTM zone 6 N ("EPSG::32606") then following code will do the trick:
chunk = Metashape.app.document.chunk
source_crs = chunk.crs # WGS84
target_crs = PhotoScan.CoordinateSystem("EPSG::32606") # WGS84/UTM06 N
for camera in chunk.cameras:
if not camera.reference.location:
continue
print("Source Coordinates for",camera.label,":",camera.reference.location," in",source_crs.name)
camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, source_crs, target_crs)
print("Target Coordinates for",camera.label,":",camera.reference.location," in",target_crs.name)
chunk.crs = target_crs
and the printed output would be as:
2021-03-18 06:03:11 Source Coordinates for DJI_0357.tiff : Vector([-147.858200000127, 64.8554152780109, 248.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0357.tiff : Vector([459312.5123923809, 7192616.907659786, 248.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0359.tiff : Vector([-147.858108611107, 64.85547638893128, 247.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0359.tiff : Vector([459316.93729799363, 7192623.658982667, 247.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0361.tiff : Vector([-147.858062777519, 64.85551444424524, 248.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0361.tiff : Vector([459319.1676681044, 7192627.870324763, 248.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0363.tiff : Vector([-147.858047500187, 64.85552222198912, 247.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0363.tiff : Vector([459319.903684075, 7192628.727240421, 247.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0365.tiff : Vector([-147.85801694446104, 64.85552222198912, 247.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0365.tiff : Vector([459321.3522641624, 7192628.707601423, 247.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0367.tiff : Vector([-147.857864444521, 64.8555069446563, 248.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0367.tiff : Vector([459328.558876019, 7192626.907122786, 248.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0369.tiff : Vector([-147.857681388855, 64.85549916691251, 247.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0369.tiff : Vector([459337.2254038893, 7192625.922768301, 247.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0371.tiff : Vector([-147.857528611289, 64.8554916667938, 247.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0371.tiff : Vector([459344.45693601645, 7192624.988825623, 247.0]) in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0373.tiff : Vector([-147.857345555623, 64.85548388905, 247.0]) in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0373.tiff : Vector([459353.1234738997, 7192624.0045170905, 247.0]) in WGS 84 / UTM zone 6N
Hope this clears uo your doubts,
-
hello Paul,
I wanted to follow up that previous reply
but I would like to slighlty change it :
I wanted to apply GNSS leverarm before printing source and target coordinates.
I already setup camera.sensor as well as camera.antenna.rerefence vector
something like that
sensor.antenna.location_ref = Metashape.Vector([0.000, -0.005, 0.068])
so how to apply GNSS leverarm ? If I am not wrong, GNSS leverarm vector is given in camera ref system model.
I understand we must work in LSE (Local Space Euclidean coordinate system) if my source coordinate are given in geographic coord (lat ; long ; ellipsoid height)
So should I do that in 2 steps ?
express antenna leverarm in LSE
apply conversion from lat,long,ellip_h into LSE ?
also , is chunk.updateTransform() needed after step 1 ? step 2 ?
thx
antoine
-
Halo Antoine,
Given T = chunk.transform.matrix,
AR = camera.sensor.antenna.location_ref # antenna reference lever arm
and CT = camera.transform for a given camera, then the camera center reference coordinates in ecef CS are:
CC = chunk.crs.unproject(camera.reference.location)
and CC - (T*CT).rotation() * Metashape.Matrix.Diag((1, -1, -1)) * AR is camera center ecef coordinates with antenna offset applied
for target crs the coordinates are target_crs.project(CC - (T*CT).rotation() * Metashape.Matrix.Diag((1, -1, -1)) *AR) or Metashape.CoordinateSystem.transform(CC - (T*CT).rotation() * Metashape.Matrix.Diag((1, -1, -1)) *AR, ecef_crs, target_crs)
Hope this makes sense,
PS. look at https://github.com/agisoft-llc/metashape-scripts/blob/master/src/save_estimated_reference.py where get_AntennaTransform() shows how to apply lever arm and boresight to coordinates
-
thank you Paul for that reply.
I am not sure I understand the Metashape.Matrix.Diag((1, -1, -1) ... whereas on other post on the same topic it's a 4x4 matrix being used such as Metashape.Matrix.Diag((1, -1, -1, 1)
by the way, that post https://www.agisoft.com/forum/index.php?topic=13611.msg60200 should also be helpful as we work with pandas as well.
with that code we can afterward discriminate sensor model as well in the DataFrame written.
antoine