Thank you! This is what we needed
On Tue, Dec 17, 2019 at 12:09 PM Martin Desruisseaux < [email protected]> wrote: > Hello Thierry > > No problem. Below is the code for transforming from EPSG::26716 (a > projected CRS) to WGS 84 using explicitly the coordinate operation > EPSG::1175. The key point is that EPSG::1175 is an operation between 2 > geographic CRS, i.e. between (latitude, longitude) coordinates in degrees, > while EPSG::26716 is a projected CRS, i.e. (easting, northing) coordinates > in metres. So before to apply EPSG::1175, we need to convert from (easting, > northing) in metres to (latitude, longitude) in degrees. Normally the > CRS.findOperation(...) method does that automatically, but the following > code allows to control explicitly the transformation steps: > > CRSAuthorityFactory crsFactory = CRS.getAuthorityFactory("EPSG"); > CoordinateOperationAuthorityFactory opFactory = > (CoordinateOperationAuthorityFactory) crsFactory; > CoordinateOperation operation = opFactory.createCoordinateOperation("1175"); > /* > * The EPSG::1175 operation expects a geographic source CRS. > * This can be verified with System.out.println(operation); > * we can see: SourceCRS[GeodeticCRS["NAD27", (...snip...)]]. > * If our coordinates are in another CRS, then first we need > * to convert them to the CRS expected by EPSG::1175 first. > */ > CoordinateReferenceSystem mySourceCRS = > crsFactory.createCoordinateReferenceSystem("26716"); > CoordinateOperation mySourceToOperationSource = > CRS.findOperation(mySourceCRS, operation.getSourceCRS(), null); > /* > * We have two operations: from my source CRS to the CRS expected > * by the operation as inputs, then the operation itself. We want > * the concatenation of those two steps: > */ > MathTransform step1 = mySourceToOperationSource.getMathTransform(); > MathTransform step2 = operation.getMathTransform(); > MathTransform completeTransform = MathTransforms.concatenate(step1, step2); > /* > * Then we can use completeTransform for transforming from EPSG:26716 > * to WGS 84 with EPSG::1175 as a step. > */ > DirectPosition source = new DirectPosition2D(250072.891031813, > 4147221.68033625); > DirectPosition target = completeTransform.transform(source, null); > System.out.println(target); > > With this code I get the following result: > > POINT(37.44000000026929 -89.82500000051678) > > Martin > > >
