Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: Yoann Courtois on May 07, 2019, 04:26:02 PM
-
Hi everyone,
Within my automated pipeline, I've developed a method that calculate and set the smallest bounding box which included a "project contour" polygon.
The calculation has been separated in 3 steps :
- Set the bounding box center
- Set the bounding box size
- Set the bounding box orientation
Everything works very fine until today ... when I decided to include coordinates system in my pipeline.
Indeed, in "Local Coordinates" ('LOCAL_CS["Local Coordinates",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]'), everything is OK,
but when I use projected coordinates system (For exemple EPSG::3946 in France), the box orientation doesn't work anymore (Center and size are OK !)...
Here is the following code for bounding box orientation setting (Where vertex_a / vertex_b / vertex_c are the corners of my minimum rotated rectangle that include my polygon) :
cos_teta = (vertex_c.x - vertex_a.x) / vertex_a.distance(vertex_c)
sin_teta = (vertex_c.y - vertex_a.y) / vertex_a.distance(vertex_c)
__pseudo_region.rot = [[sin_teta, -cos_teta, 0],
[cos_teta, sin_teta, 0],
[0, 0, 1]]
chunk.region.rot = chunk.transform.matrix.rotation().inv() * __pseudo_region.rot
After some investigation, my pseudo_region hasn't changed, so the problem is coming from the chunk rotation matrix (chunk.transform.matrix.rotation()).
I cannot understand how chunk.crs has inlfuenced the chunk.transform matrix... and have no idea how to fix the problem...
Regards
-
Hello Yoann,
In which coordinate system space you are defining the bounding box orientation with pseudo_region.rot?
-
Hello Alexey,
My pseudo_region is calculated in georeferenced coordinates, so previously in "Local coordinates" but now in a projected coordinate system.
Then, I apply some transformation to set the chunk.region in his chunk coordinate system :
- To reproject the region center :
chunk.transform.matrix.inv().mulp(chunk.crs.unproject(__pseudo_region.center))
- To scale the region size :
chunk.region.size = (__pseudo_region_long / chunk.transform.scale,
__pseudo_region_larg / chunk.transform.scale,
__pseudo_region_haut / chunk.transform.scale)
- To convert the region rotation :
chunk.region.rot = chunk.transform.matrix.rotation().inv() * __pseudo_region.rot
Everything works fine for the center and the size, but not for the rotation...
-
Notice that since last week, I found a work-around by setting back the whole project in "Local coordinates", then calculating my box, and finally reprojecting the whole project in my projected coordinates system
But, besides I don't know if the double reprojection is really good, I would prefer find how to correct the region rotation conversion...