- 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
In 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:
public AffineTransform getGridToPixelCorner() {
AffineTransform gridToCRS = ...;
PixelOrientation current = PixelOrientation.CENTER;
PixelOrientation desired = PixelOrientation.UPPER_LEFT;
// Switch the transform from 'current' to 'desired' convention.
PixelTranslation source = getPixelTranslation(current);
PixelTranslation target = getPixelTranslation(desired);
return gridToCRS.translate(target.dx - source.dx,
target.dy - source.dy);
}
- Since:
- 1.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal double
The translation among the x axis relative to pixel center.final double
The translation among the y axis relative to pixel center.final PixelOrientation
The pixel orientation for this translation. -
Method Summary
Modifier and TypeMethodDescriptionstatic PixelOrientation
getPixelOrientation
(PixelInCell anchor) Returns the pixel orientation which is equivalent to the givenPixelInCell
code.static PixelTranslation
Returns the specified position relative to the pixel center.static double
getPixelTranslation
(PixelInCell anchor) Returns the position relative to the cell center.Returns a string representation of this pixel translation.static MathTransform
translate
(MathTransform gridToCRS, PixelOrientation current, PixelOrientation desired, int xDimension, int yDimension) Converts a math transform from a "pixel orientation" convention to another "pixel orientation" convention.static MathTransform
translate
(MathTransform gridToCRS, PixelInCell current, PixelInCell desired) Converts a math transform from a "pixel in cell" convention to another "pixel in cell" convention.
-
Field Details
-
orientation
The pixel orientation for this translation. Most common values arePixelOrientation.UPPER_LEFT
andPixelOrientation.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 +½.
-
-
Method Details
-
getPixelOrientation
Returns the pixel orientation which is equivalent to the givenPixelInCell
code. 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_CENTER
CENTER
CELL_CORNER
UPPER_LEFT
null
null
- Parameters:
anchor
- thePixelInCell
code, ornull
.- Returns:
- the corresponding pixel orientation, or
null
if the argument was null. - Throws:
IllegalArgumentException
- if the givenanchor
is not a known code list value.
-
getPixelTranslation
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_CENTER
0.0
CELL_CORNER
-0.5
- Parameters:
anchor
- the "pixel in cell" value.- Returns:
- the translation for the given "pixel in cell" value.
- Throws:
IllegalArgumentException
- if the givenanchor
is not a known code list value.
-
getPixelTranslation
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 CENTER
0.0
0.0
UPPER_LEFT
-0.5
-0.5
UPPER_RIGHT
+0.5
-0.5
LOWER_LEFT
-0.5
+0.5
LOWER_RIGHT
+0.5
+0.5
- Parameters:
anchor
- the pixel orientation.- Returns:
- the position relative to the pixel center.
- Throws:
IllegalArgumentException
- if the givenanchor
is not a known code list value.
-
translate
public static MathTransform translate(MathTransform gridToCRS, PixelInCell current, 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.If the given
gridToCRS
is null, then this method ignores all other arguments and returnsnull
. Otherwisecurrent
anddesired
arguments must be non-null.Example
If a givengridToCRS
transform 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 givengridToCRS
transform 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.- Parameters:
gridToCRS
- a math transform from pixel coordinates to any CRS, ornull
.current
- the pixel orientation of the givengridToCRS
transform.desired
- the pixel orientation of the desired transform.- Returns:
- the translation from
current
todesired
, ornull
ifgridToCRS
was null. - Throws:
IllegalArgumentException
- ifcurrent
ordesired
is not a known code list value.
-
translate
public static MathTransform translate(MathTransform gridToCRS, PixelOrientation current, 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.If the given
gridToCRS
is null, then this method ignores all other arguments and returnsnull
. Otherwisecurrent
anddesired
arguments must be non-null.Example
If a givengridToCRS
transform 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)gridToCRS
transform. See example in abovetranslate
method for more details.- Parameters:
gridToCRS
- a math transform from pixel coordinates to any CRS, ornull
.current
- the pixel orientation of the givengridToCRS
transform.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
current
todesired
, ornull
ifgridToCRS
was null. - Throws:
IllegalArgumentException
- ifcurrent
ordesired
is not a known code list value.
-
toString
Returns a string representation of this pixel translation.
-