private static DirectPosition transformTo2D(GeneralDirectPosition srcPosition, MathTransform transformToWGS84_3D,
MathTransform transformFromWGS84) throws TransformException {
if( Double.isNaN( srcPosition.getOrdinate(2)) ){
srcPosition.setOrdinate(2, 0.0 ); // lazy add 3rd ordinate if not provided to prevent failure
}
DirectPosition world3D = transformToWGS84_3D.transform(srcPosition, null );
DirectPosition world2D = new GeneralDirectPosition( DefaultGeographicCRS.WGS84);
world2D.setOrdinate(0, world3D.getOrdinate(0));
world2D.setOrdinate(1, world3D.getOrdinate(1));
DirectPosition targetPosition = transformFromWGS84.transform(world2D, null );
return targetPosition;
}