Package org.apache.sis.coverage.grid
Class PixelTranslation
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.coverage.grid.PixelTranslation
- All Implemented Interfaces:
Serializable
The translation to apply for different values of
PixelOrientation or PixelInCell.
The translation are returned by a call to one of the following static methods:
getPixelTranslation(PixelOrientation)for the two-dimensional case.getPixelTranslation(PixelInCell)for the n-dimensional case.
translate(…) convenience methods,
which apply the translation on a given MathTransform instance.
Example:
if the following code snippet,
gridToCRS is an AffineTransform from
grid cell coordinates (typically pixel coordinates) to some arbitrary CRS coordinates.
In this example, the transform maps pixels center,
while the upper left corner is desired.
This code will switch the affine transform from the pixel center to
upper left corner convention:
- Since:
- 1.0
- Version:
- 1.0
- See Also:
-
PixelInCellPixelOrientation- Serialized Form
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal doubleThe translation among the x axis relative to pixel center.final doubleThe translation among the y axis relative to pixel center.final org.opengis.metadata.spatial.PixelOrientationThe pixel orientation for this translation.private static final Map<org.opengis.metadata.spatial.PixelOrientation,PixelTranslation> The offset for various pixel orientations.private static final longFor cross-version compatibility.private static final org.opengis.referencing.operation.MathTransform[]Math transforms created bytranslate(MathTransform, PixelInCell, PixelInCell)for dimensions 1 to 6. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePixelTranslation(org.opengis.metadata.spatial.PixelOrientation orientation, double dx, double dy) Creates a new pixel translation. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidadd(org.opengis.metadata.spatial.PixelOrientation orientation, double dx, double dy) ForORIENTATIONSconstruction only.static org.opengis.metadata.spatial.PixelOrientationgetPixelOrientation(org.opengis.referencing.datum.PixelInCell anchor) Returns the pixel orientation which is equivalent to the givenPixelInCellcode.static PixelTranslationgetPixelTranslation(org.opengis.metadata.spatial.PixelOrientation anchor) Returns the specified position relative to the pixel center.static doublegetPixelTranslation(org.opengis.referencing.datum.PixelInCell anchor) Returns the position relative to the cell center.private static IllegalArgumentExceptionillegalDimension(String name, Object dimension) Formats an exception for an illegal dimension.toString()Returns a string representation of this pixel translation.static org.opengis.referencing.operation.MathTransformtranslate(org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.metadata.spatial.PixelOrientation current, org.opengis.metadata.spatial.PixelOrientation desired, int xDimension, int yDimension) Converts a math transform from a "pixel orientation" convention to another "pixel orientation" convention.static org.opengis.referencing.operation.MathTransformtranslate(org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.referencing.datum.PixelInCell current, org.opengis.referencing.datum.PixelInCell desired) Converts a math transform from a "pixel in cell" convention to another "pixel in cell" convention.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
translations
private static final org.opengis.referencing.operation.MathTransform[] translationsMath transforms created bytranslate(MathTransform, PixelInCell, PixelInCell)for dimensions 1 to 6. Each element in this array will be created when first needed. Even indices are translations by -0.5 while odd indices are translations by +0.5. -
orientation
public final org.opengis.metadata.spatial.PixelOrientation orientationThe pixel orientation for this translation. Most common values arePixelOrientation.UPPER_LEFTandPixelOrientation.CENTER. -
dx
public final double dxThe translation among the x axis relative to pixel center. The value is typically −½, 0 or +½. -
dy
public final double dyThe translation among the y axis relative to pixel center. The value is typically −½, 0 or +½. -
ORIENTATIONS
private static final Map<org.opengis.metadata.spatial.PixelOrientation,PixelTranslation> ORIENTATIONSThe offset for various pixel orientations. Keys must be upper-case names.
-
-
Constructor Details
-
PixelTranslation
private PixelTranslation(org.opengis.metadata.spatial.PixelOrientation orientation, double dx, double dy) Creates a new pixel translation.
-
-
Method Details
-
add
private static void add(org.opengis.metadata.spatial.PixelOrientation orientation, double dx, double dy) ForORIENTATIONSconstruction only. -
getPixelOrientation
public static org.opengis.metadata.spatial.PixelOrientation getPixelOrientation(org.opengis.referencing.datum.PixelInCell anchor) Returns the pixel orientation which is equivalent to the givenPixelInCellcode. This equivalence can be used for converting n-dimensional parameters to the more specific two-dimensional case. This method implements the following mapping:Pixel orientation equivalences Pixel in cell Pixel orientation CELL_CENTERCENTERCELL_CORNERUPPER_LEFTnullnull- Parameters:
anchor- thePixelInCellcode, ornull.- Returns:
- the corresponding pixel orientation, or
nullif the argument was null. - Throws:
IllegalArgumentException- if the givenanchoris not a known code list value.
-
getPixelTranslation
public static double getPixelTranslation(org.opengis.referencing.datum.PixelInCell anchor) Returns the position relative to the cell center. This method is typically used for n-dimensional grids, where the number of dimension is unknown. The translation is determined from the following table, with the same value applied to all dimensions:Translations Pixel in cell offset CELL_CENTER0.0CELL_CORNER-0.5- Parameters:
anchor- the "pixel in cell" value.- Returns:
- the translation for the given "pixel in cell" value.
- Throws:
IllegalArgumentException- if the givenanchoris not a known code list value.
-
getPixelTranslation
public static PixelTranslation getPixelTranslation(org.opengis.metadata.spatial.PixelOrientation anchor) Returns the specified position relative to the pixel center. This method can be used for grid restricted to 2 dimensions. The translation vector is determined from the following table:Translations Pixel orientation dx dy CENTER0.00.0UPPER_LEFT-0.5-0.5UPPER_RIGHT+0.5-0.5LOWER_LEFT-0.5+0.5LOWER_RIGHT+0.5+0.5- Parameters:
anchor- the pixel orientation.- Returns:
- the position relative to the pixel center.
- Throws:
IllegalArgumentException- if the givenanchoris not a known code list value.
-
translate
public static org.opengis.referencing.operation.MathTransform translate(org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.referencing.datum.PixelInCell current, org.opengis.referencing.datum.PixelInCell desired) Converts a math transform from a "pixel in cell" convention to another "pixel in cell" convention. This method concatenates −½, 0 or +½ translations on all dimensions before the given transform. If the two given conventions are the same, then this method returns the given transform unchanged.Example: if a givenIf the givengridToCRStransform was mapping the cell corner to "real world" coordinates, then a call totranslate(gridToCRS,will return a new transform performing the following steps: first convert grid coordinates from cell center convention (CELL_CORNER,CELL_CENTER)desired) to cell corner convention (current), then concatenate the givengridToCRStransform which was designed for the cell corner convention. The above-cited cell center → cell corner conversion is done by translating the grid coordinates by +½, because the grid coordinates (0,0) relative to cell center is (½,½) relative to cell corner.gridToCRSis null, then this method ignores all other arguments and returnsnull. Otherwisecurrentanddesiredarguments must be non-null.- Parameters:
gridToCRS- a math transform from pixel coordinates to any CRS, ornull.current- the pixel orientation of the givengridToCRStransform.desired- the pixel orientation of the desired transform.- Returns:
- the translation from
currenttodesired, ornullifgridToCRSwas null. - Throws:
IllegalArgumentException- ifcurrentordesiredis not a known code list value.
-
translate
public static org.opengis.referencing.operation.MathTransform translate(org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.metadata.spatial.PixelOrientation current, org.opengis.metadata.spatial.PixelOrientation desired, int xDimension, int yDimension) Converts a math transform from a "pixel orientation" convention to another "pixel orientation" convention. This method concatenates −½, 0 or +½ translations on two dimensions before the given transform. The given transform can have any number of input and output dimensions, but only two of them will be converted.Example: if a givenIf the givengridToCRStransform was mapping the upper-left corner to "real world" coordinates, then a call totranslate(gridToCRS,will return a new transform translating grid coordinates by +0.5 before to apply the givenUPPER_LEFT,CENTER, 0, 1)gridToCRStransform. See example in abovetranslatemethod for more details.gridToCRSis null, then this method ignores all other arguments and returnsnull. Otherwisecurrentanddesiredarguments must be non-null.- Parameters:
gridToCRS- a math transform from pixel coordinates to any CRS, ornull.current- the pixel orientation of the givengridToCRStransform.desired- the pixel orientation of the desired transform.xDimension- the dimension of x coordinates (pixel columns). Often 0.yDimension- the dimension of y coordinates (pixel rows). Often 1.- Returns:
- the translation from
currenttodesired, ornullifgridToCRSwas null. - Throws:
IllegalArgumentException- ifcurrentordesiredis not a known code list value.
-
illegalDimension
Formats an exception for an illegal dimension. -
toString
Returns a string representation of this pixel translation.
-