Integration with graphical libraries

Affine transforms, introduced earlier, are extensively used by Apache SIS. About all graphical libraries support some kind of coordinate operations, usually as affine transforms or a slight generalization like perspective transforms. Each library defines its own API. Some examples are listed below:

Affine transform implementations in graphical libraries
Library Transform implementation Dimensions
Java2D java.awt.geom.AffineTransform 2
Java3D javax.media.j3d.Transform3D 3
JavaFX javafx.scene.transform.Affine 2 or 3
Java Advanced Imaging (JAI) javax.media.jai.PerspectiveTransform 2
Android android.graphics.Matrix 2

However in many cases, affine or perspective transforms are the only kind of coordinate operations supported by the graphical library. Apache SIS needs to handle a wider range of operations, in which affine transforms are only special cases. In particular most map projections and datum shifts cannot be represented by affine transforms. SIS also needs to support arbitrary number of dimensions, while above-cited API restrict the use to a fixed number of dimensions. For those reasons SIS cannot use directly the above-cited API. Instead, SIS uses the more abstract org.opengis.referencing.transform.MathTransform interface. But in the special case where the transform is actually affine, SIS may try to use an existing implementation, in particular Java2D. The following Java code can be used in situations where the Java2D object is desired:

MathTransform mt = ...;    // Any math transform created by Apache SIS.
if (mt instanceof AffineTransform) {
    AffineTransform at = (AffineTransform) mt;
    // Use Java2D API from here.
}

Apache SIS uses Java2D on a best effort basis only. The above cast is not guaranteed to succeed, even when the MathTransform meets the requirements allowing Java2D usage.