You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@sis.apache.org by Clay Harter <cl...@bahwancybertek.com> on 2021/03/17 17:10:25 UTC

How to assert datum shift when getting a CoordinateOperation

I see how I may get a CoordinateOperation to convert from one CRS to another in  a given area of interest by calling CRS.findOperation(sourceCRS, targetCRS, areaOfInterest) . But in the case where the source and target CRS have different datum there may be multiple transforms available. If I know the EPSG code of the transform (datum shift) I wish to use how may I assert it?  In this case I  don't want SIS to pick it for me.

Clay Harter


Re: How to assert datum shift when getting a CoordinateOperation

Posted by Martin Desruisseaux <ma...@geomatys.com>.
Hello Clay

I'm glad if the tip could help!

Le 17/03/2021 à 20:20, Clay Harter a écrit :

> (…snip…)
>
>      DirectPosition ptSrc = new DirectPosition2D(300000, 5200000);
>      DirectPosition ptNad27 = conversion.getMathTransform().transform(ptSrc, null);			
>      DirectPosition ptWgs84 = transform.getMathTransform().transform(ptNad27, null);
>
> This works just fine but I wonder whether there is more efficient way to do this ?  May I chain the conversion and transform operations together into one operation in order to convert my NAD27 based projection CRS to WGS84 in one step?

Yes, it is always more efficient and sometime more accurate to 
concatenate the transforms. Internally SIS will erase operations that 
cancel each other such as conversions from radians to degrees to 
radians. It can be done as below:

    MathTransform mt = MathTransforms.concatenate(conversion.getMathTransform(), transform.getMathTransform());
    DirectPosition ptWgs84 = mt.transform(ptSrc, null);

If transforming a large amount of points, the transform methods working 
on float[] or double[] arrays will also be more efficient than the 
method working on a DirectPosition.

     Martin



RE: How to assert datum shift when getting a CoordinateOperation

Posted by Clay Harter <cl...@bahwancybertek.com>.
Merci Martin!

I saw that there was that method on CoordinateOperationAuthorityFactory but didn't see any way to get an object that implemented that interface.   So I can now write something like:

		CoordinateReferenceSystem wgs84 = CommonCRS.WGS84.geographic();
		CoordinateReferenceSystem nad27 = CommonCRS.NAD27.geographic();
		ProjectedCRS projCrs = (ProjectedCRS) CRS.forCode("EPSG:32040");   // NAD27 / Texas South Central
		GeographicCRS geoCrs =   projCrs.getBaseCRS();	
		CoordinateOperation conversion = CRS.findOperation(projCrs, geoCrs, null);		
		CoordinateOperationAuthorityFactory opFactory = (CoordinateOperationAuthorityFactory) CRS.getAuthorityFactory("EPSG");
		CoordinateOperation transform = opFactory.createCoordinateOperation("15851"); //NADCON grid based transform			
		DirectPosition ptSrc = new DirectPosition2D(300000, 5200000);          
		DirectPosition ptNad27 = conversion.getMathTransform().transform(ptSrc, null);			
		DirectPosition ptWgs84 = transform.getMathTransform().transform(ptNad27, null);

This works just fine but I wonder whether there is more efficient way to do this ?  May I chain the conversion and transform operations together into one operation in order to convert my NAD27 based projection CRS to WGS84 in one step?

Clay

Re: How to assert datum shift when getting a CoordinateOperation

Posted by Martin Desruisseaux <ma...@geomatys.com>.
Hello Clay

Le 17/03/2021 à 18:10, Clay Harter a écrit :

> I see how I may get a CoordinateOperation to convert from one CRS to 
> another in  a given area of interest by calling 
> CRS.findOperation(sourceCRS, targetCRS, areaOfInterest) . But in the 
> case where the source and target CRS have different datum there may be 
> multiple transforms available. If I know the EPSG code of the 
> transform (datum shift) I wish to use how may I assert it?  In this 
> case I  don’t want SIS to pick it for me.
>
This is the work of CoordinateOperationAuthorityFactory. An example is 
below. The first line is a bit of cheating, more on it below.

    import org.opengis.referencing.operation.CoordinateOperationAuthorityFactory;

    (...snip...)

    CoordinateOperationAuthorityFactory opFactory = (CoordinateOperationAuthorityFactory) CRS.getAuthorityFactory("EPSG");
    CoordinateOperation op = opFactory.createCoordinateOperation("1172");
    System.out.println(op);

The CRS.getAuthorityFactory(…) method is for fetching a 
CRSAuthorityFactory. We do not have a public method for fetching the 
CoordinateOperationAuthorityFactory at this time, but it appears that in 
the particular case of Apache SIS, the implementation class of 
CRSAuthorityFactory also implements all other authority factory 
interfaces. We will provide methods for factories of all types in some 
future SIS version (it is pending an update of GeoAPI interfaces).

     Martin