Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kousongsong

Pages: [1]
1
Python and Java API / Camera Coordinate System Transformation
« on: September 09, 2024, 05:42:54 AM »
Hello, when I use the Java API, I need to convert the coordinate system of the camera. I refer to the coordinate conversion writing method in Python, but the final result does not write the new coordinates. Please help me find the problem with this writing.
Code: [Select]
CoordinateSystem targetCrs = new CoordinateSystem();
targetCrs.init("EPSG::3857");
for (int key : chunk.getCameraKeys()) {
    Camera camera = chunk.getCamera(key).get();
    Vector vector = camera.getReference().getLocation().get();
    Vector targetVector = CoordinateSystem.transform(vector, chunk.getCoordinateSystem(), targetCrs);
    camera.getReference().setLocation(Optional.of(targetVector));
    System.out.println(vector);
    System.out.println(targetVector);

    Vector vector1 = camera.getReference().getLocation().get();
    System.out.println("location2: " + vector1.getX() + " " + vector1.getY()); // The coordinates have not changed after re-reading
}

I tried getting the camera array using chunk.getCameras(), but it returned null no matter what, so I used the getCamera(key) method to get the camera. Is this related?
Code: [Select]
Camera[] cameras = chunk.getCameras();Please give me a java-api version of the coordinate conversion example, thank you very much

metashape-java-api-version:1.8
java-version:1.8.0_162
OS:Windows 11

Pages: [1]