1

**Python and Java API / Re: CRS coordinates to Region coordinates**

« **on:**March 30, 2021, 04:12:45 PM »

As always, thank you very much Alexey, that was very helpful! The code worked perfectly, but I noticed that it is also required to scale the region size. The complete working code, for anyone who might be interested is as follows:

where:

Code: [Select]

`def placeRegion(center,size,angle):`

crs = chunk.crs

T = chunk.transform.matrix

center = Metashape.Vector((center[0],center[1],center[2]))

center = T.inv().mulp(crs.unproject(center))

m = crs.localframe(T.mulp(center)) * T

R = m.rotation() * (1. / m.scale())

size = Metashape.Vector((size[0],size[1],size[2])) / m.scale() # scaling the size is required

angle = np.radians(angle)

rot = Metashape.Matrix([[np.cos(angle), -np.sin(angle), 0], [np.sin(angle), np.cos(angle), 0], [0, 0, 1]])

rotation = R.t() * rot

chunk.region.rot = rotation

chunk.region.center = center

chunk.region.size = size

where:

Code: [Select]

`center = (X,Y,Z) # in CRS coordinates`

size = (width,depth,height) # in meters

angle = float # rotation angle of the region (in degrees)