Forum

Author Topic: Changing coordinate system on all cameras  (Read 4499 times)

BarryReid

  • Newbie
  • *
  • Posts: 15
    • View Profile
Changing coordinate system on all cameras
« 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

Code: [Select]
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.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13990
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #1 on: June 11, 2015, 08:08:53 PM »
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:

Code: [Select]
coord = PhotoScan.Vector([X, Y, Z])
crs = PhotoScan.CoordinateSystem("EPSG::...")
crs_new = PhotoScan.CoordinateSystem("EPSG::...")

coord = crs.unproject(coord)
coord = crs_new.project(coord)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Emanuele1234

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #2 on: March 17, 2021, 06:59:49 PM »
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.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13990
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #3 on: March 17, 2021, 09:16:49 PM »
Hello Emanuele,

Please check the following code:

Code: [Select]

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)

Best regards,
Alexey Pasumansky,
Agisoft LLC

Emanuele1234

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #4 on: March 18, 2021, 12:57:57 PM »
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!

Paulo

  • Hero Member
  • *****
  • Posts: 1073
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #5 on: March 18, 2021, 01:56:56 PM »
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:
Code: [Select]
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:
Code: [Select]
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,
« Last Edit: March 18, 2021, 03:06:09 PM by Paulo »
Best Regards,

Paul Pelletier,
Surveyor