本文整理了Java中org.opengis.referencing.operation.Matrix.setElement()
方法的一些代码示例,展示了Matrix.setElement()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.setElement()
方法的具体详情如下:
包路径:org.opengis.referencing.operation.Matrix
类名称:Matrix
方法名:setElement
[英]Modifies the value at the specified row and column of this matrix.
[中]修改此矩阵指定行和列的值。
代码示例来源:origin: geotools/geotools
/**
* Creates a transform that apply the same translation along all axis.
*
* @param dimension The input and output dimensions.
* @param offset The translation.
* @return The offset transform.
* @since 2.3
*/
public static LinearTransform createTranslation(final int dimension, final double offset) {
if (offset == 0) {
return IdentityTransform.create(dimension);
}
final Matrix matrix = new GeneralMatrix(dimension + 1);
for (int i = 0; i < dimension; i++) {
matrix.setElement(i, dimension, offset);
}
return create(matrix);
}
代码示例来源:origin: geotools/geotools
/**
* Creates a transform that apply a uniform scale along all axis.
*
* @param dimension The input and output dimensions.
* @param scale The scale factor.
* @return The scale transform.
* @since 2.3
*/
public static LinearTransform createScale(final int dimension, final double scale) {
if (scale == 1) {
return IdentityTransform.create(dimension);
}
final Matrix matrix = new GeneralMatrix(dimension + 1);
for (int i = 0; i < dimension; i++) {
matrix.setElement(i, i, scale);
}
return create(matrix);
}
代码示例来源:origin: geotools/geotools
/**
* Creates a matrix from this group of parameters.
*
* @return A matrix created from this group of parameters.
*/
public Matrix getMatrix() {
final int numRow = this.numRow.intValue();
final int numCol = this.numCol.intValue();
final Matrix matrix = MatrixFactory.create(numRow, numCol);
if (matrixValues != null) {
for (int j = 0; j < numRow; j++) {
final ParameterValue[] row = matrixValues[j];
if (row != null) {
for (int i = 0; i < numCol; i++) {
final ParameterValue element = row[i];
if (element != null) {
matrix.setElement(j, i, element.doubleValue());
}
}
}
}
}
return matrix;
}
代码示例来源:origin: geotools/geotools
Integer.parseInt(name.substring(prefix.length(), split));
final int col = Integer.parseInt(name.substring(split + 1));
matrix.setElement(row, col, ((ParameterValue) param).doubleValue());
continue;
} catch (NumberFormatException exception) {
代码示例来源:origin: geotools/geotools
matrix.setElement(j, j, 0.0);
matrix.setElement(j, i, scale);
matrix.setElement(j, dimension, offset);
代码示例来源:origin: geotools/geotools
matrix.setElement(xDimension, dimension, dx);
matrix.setElement(yDimension, dimension, dy);
mt = ProjectiveTransform.create(matrix);
代码示例来源:origin: geotools/geotools
if (translationColumn >= 0) { // Paranoiac check: should always be 1.
final double translation = matrix.getElement(0, translationColumn);
matrix.setElement(0, translationColumn, translation + epochShift);
代码示例来源:origin: apache/sis
/**
* Returns a matrix for an affine transform from all source coordinates to the coordinates of the
* source components selected for participating in the coordinate operation.
*
* @param sourceDimensions number of dimension of the source {@code CompoundCRS}.
* @param selectedDimensions number of source dimensions needed by the coordinate operations.
* @param selected all {@code SourceComponent} instances needed for the target {@code CompoundCRS}.
*/
static Matrix sourceToSelected(final int sourceDimensions, final int selectedDimensions, final SubOperationInfo[] selected) {
final Matrix select = Matrices.createZero(selectedDimensions + 1, sourceDimensions + 1);
select.setElement(selectedDimensions, sourceDimensions, 1);
int j = 0;
for (final SubOperationInfo component : selected) {
for (int i=component.startAtDimension; i<component.endAtDimension; i++) {
select.setElement(j++, i, 1);
}
}
return select;
}
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Returns a matrix for an affine transform from all source coordinates to the coordinates of the
* source components selected for participating in the coordinate operation.
*
* @param sourceDimensions number of dimension of the source {@code CompoundCRS}.
* @param selectedDimensions number of source dimensions needed by the coordinate operations.
* @param selected all {@code SourceComponent} instances needed for the target {@code CompoundCRS}.
*/
static Matrix sourceToSelected(final int sourceDimensions, final int selectedDimensions, final SubOperationInfo[] selected) {
final Matrix select = Matrices.createZero(selectedDimensions + 1, sourceDimensions + 1);
select.setElement(selectedDimensions, sourceDimensions, 1);
int j = 0;
for (final SubOperationInfo component : selected) {
for (int i=component.startAtDimension; i<component.endAtDimension; i++) {
select.setElement(j++, i, 1);
}
}
return select;
}
}
代码示例来源:origin: geotools/geotools
/** A filter for the set of available operations. */
private static final class MethodFilter implements Predicate<MathTransformProvider> {
/** The expected type ({@code Projection.class}) for projections). */
private final Class<? extends Operation> type;
/** Constructs a filter for the set of math operations methods. */
public MethodFilter(final Class<? extends Operation> type) {
this.type = type;
}
/**
* Returns {@code true} if the specified element should be included. If the type is unknown,
* conservatively returns {@code true}.
*/
@Override
public boolean test(MathTransformProvider element) {
if (element instanceof MathTransformProvider) {
final Class<? extends Operation> t =
((MathTransformProvider) element).getOperationType();
if (t != null && !type.isAssignableFrom(t)) {
return false;
}
}
return true;
}
}
代码示例来源:origin: geotools/geotools
matrix.setElement(i, lastMatrixColumn, rotate);
代码示例来源:origin: opengeospatial/geoapi
/**
* Gets the derivative of this transform at a point.
* The derivative of an affine transform is constant everywhere.
*
* @param point ignored - may be {@code null}.
* @return the derivative (never {@code null}).
*/
@Override
public Matrix derivative(final Point2D point) {
final Matrix m = new SimpleMatrix(2, 2);
m.setElement(0, 0, getScaleX());
m.setElement(1, 1, getScaleY());
m.setElement(0, 1, getShearX());
m.setElement(1, 0, getShearY());
return m;
}
代码示例来源:origin: Geomatys/geotoolkit
/**
* Modifies the given matrix in order to reverse the direction of the axis at the given
* dimension. The matrix is assumed affine, but this is not verified.
*
* @param matrix The matrix to modify.
* @param dimension The dimension of the axis to reverse.
* @param span The envelope span at the dimension of the axis to be reversed,
* in units of the source coordinate system.
*
* @since 3.16
*
* @deprecated No replacement, since experience has shown that this operation causes more problems
* than solutions.
*/
@Deprecated
public static void reverseAxisDirection(final Matrix matrix, final int dimension, final double span) {
final int numRows = matrix.getNumRow();
final int lastCol = matrix.getNumCol() - 1;
for (int j=0; j<numRows; j++) {
final double scale = matrix.getElement(j, dimension);
if (scale != 0) {
// The formula below still work with scale=0, but we don't want
// to change the scale sign from positive zero to negative zero.
matrix.setElement(j, dimension, -scale);
matrix.setElement(j, lastCol, matrix.getElement(j, lastCol) + scale*span);
}
}
}
}
代码示例来源:origin: org.geotools/gt2-coverage
/**
* Translates the specified math transform according the specified pixel orientation.
* The {@code gridToCRS} math transform is assumed maps the pixel centers.
*/
private static MathTransform translate(final MathTransform gridToCRS,
final PixelOrientation orientation,
final int gridDimensionX, final int gridDimensionY)
{
if (PixelOrientation.CENTER.equals(orientation)) {
return gridToCRS;
}
final Point2D.Double offset = getDirectPixelTranslation(orientation);
final int dimension = gridToCRS.getSourceDimensions();
final Matrix matrix = MatrixFactory.create(dimension + 1);
matrix.setElement(gridDimensionX, dimension, offset.x);
matrix.setElement(gridDimensionY, dimension, offset.y);
return ConcatenatedTransform.create(ProjectiveTransform.create(matrix), gridToCRS);
}
代码示例来源:origin: apache/sis
/**
* Sets the scale and offset coefficients in the given "grid to CRS" transform if possible.
* This method is invoked only for variables that represent a coordinate system axis.
*/
@Override
protected boolean trySetTransform(final Matrix gridToCRS, final int srcDim, final int tgtDim, final Vector values)
throws IOException, DataStoreException
{
if (variable instanceof CoordinateAxis1D) {
final CoordinateAxis1D axis = (CoordinateAxis1D) variable;
if (axis.isRegular()) {
gridToCRS.setElement(tgtDim, srcDim, axis.getIncrement());
gridToCRS.setElement(tgtDim, gridToCRS.getNumCol() - 1, axis.getStart());
return true;
}
}
return super.trySetTransform(gridToCRS, srcDim, tgtDim, values);
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Returns the derivative at the given grid indices.
*
* <div class="section">Default implementation</div>
* The current implementation assumes that the derivative is constant everywhere in the cell
* at the given indices. It does not yet take in account the fractional part of {@code gridX}
* and {@code gridY}, because empirical tests suggest that the accuracy of such interpolation
* is uncertain.
*
* @param gridX first grid ordinate of the point for which to get the translation.
* @param gridY second grid ordinate of the point for which to get the translation.
* @return the derivative at the given location.
*/
public Matrix derivativeInCell(final double gridX, final double gridY) {
final int ix = Math.max(0, Math.min(gridSize[0] - 2, (int) gridX));
final int iy = Math.max(0, Math.min(gridSize[1] - 2, (int) gridY));
final Matrix derivative = Matrices.createDiagonal(getTranslationDimensions(), gridSize.length);
for (int j=derivative.getNumRow(); --j>=0;) {
final double orig = getCellValue(j, iy, ix);
derivative.setElement(j, 0, derivative.getElement(j, 0) + (getCellValue(j, iy+1, ix) - orig));
derivative.setElement(j, 1, derivative.getElement(j, 1) + (getCellValue(j, iy, ix+1) - orig));
}
return derivative;
}
代码示例来源:origin: apache/sis
/**
* Returns the derivative at the given grid indices.
*
* <div class="section">Default implementation</div>
* The current implementation assumes that the derivative is constant everywhere in the cell
* at the given indices. It does not yet take in account the fractional part of {@code gridX}
* and {@code gridY}, because empirical tests suggest that the accuracy of such interpolation
* is uncertain.
*
* @param gridX first grid ordinate of the point for which to get the translation.
* @param gridY second grid ordinate of the point for which to get the translation.
* @return the derivative at the given location.
*/
public Matrix derivativeInCell(final double gridX, final double gridY) {
final int ix = Math.max(0, Math.min(gridSize[0] - 2, (int) gridX));
final int iy = Math.max(0, Math.min(gridSize[1] - 2, (int) gridY));
final Matrix derivative = Matrices.createDiagonal(getTranslationDimensions(), gridSize.length);
for (int j=derivative.getNumRow(); --j>=0;) {
final double orig = getCellValue(j, ix, iy);
derivative.setElement(j, 0, derivative.getElement(j, 0) + (getCellValue(j, ix+1, iy) - orig));
derivative.setElement(j, 1, derivative.getElement(j, 1) + (getCellValue(j, ix, iy+1) - orig));
}
return derivative;
}
代码示例来源:origin: opengeospatial/geoapi
/**
* Asserts that a matrix of derivatives is equals to the expected ones within a positive delta.
*/
@Override
protected void assertMatrixEquals(final String message, final Matrix expected, final Matrix actual, final Matrix tolmat)
throws DerivativeFailure
{
if (tolmat != null) {
final int numRow = tolmat.getNumRow();
final int numCol = tolmat.getNumCol();
for (int j=0; j<numRow; j++) {
for (int i=0; i<numCol; i++) {
tolmat.setElement(j, i, DERIVATIVE_TOLERANCE);
}
}
}
super.assertMatrixEquals(message, expected, actual, tolmat);
}
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Computes the derivative by concatenating the "geographic to geocentric" and "geocentric to geographic" matrix,
* with the {@linkplain #scale} factor between them.
*
* <div class="note"><b>Note:</b>
* we could improve a little bit the precision by computing the derivative in the interpolation grid:
*
* {@preformat java
* grid.derivativeInCell(grid.normalizedToGridX(λ), grid.normalizedToGridY(φ));
* }
*
* But this is a little bit complicated (need to convert to normalized units and divide by the grid
* cell size) for a very small difference. For now we neglect that part.</div>
*
* @param m1 the derivative computed by the "geographic to geocentric" conversion.
* @param m2 the derivative computed by the "geocentric to geographic" conversion.
* @return the derivative for the "interpolated geocentric" transformation.
*/
final Matrix concatenate(final Matrix m1, final Matrix m2) {
for (int i = m1.getNumCol(); --i >= 0;) { // Number of columns can be 2 or 3.
for (int j = 3; --j >= 0;) { // Number of rows can not be anything else than 3.
m1.setElement(j, i, m1.getElement(j, i) * scale);
}
}
return Matrices.multiply(m2, m1);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link TensorParameters#ALPHANUM} formatting.
* <ul>
* <li>Group name shall be {@code "Affine parametric transformation"}.</li>
* <li>No {@code "num_row"} or {@code "num_col"} parameters if their value is equals to 3.</li>
* <li>Parameter names shall be of the form {@code "A0"}.</li>
* <li>Identifiers present, but only for A0-A2 and B0-B2.</li>
* </ul>
*/
@Test
public void testWKT2() {
final Matrix matrix = Matrices.createIdentity(3);
matrix.setElement(0,2, 4);
matrix.setElement(1,0, -2);
matrix.setElement(2,2, 7);
final ParameterValueGroup group = TensorParameters.ALPHANUM.createValueGroup(
singletonMap(TensorValues.NAME_KEY, Affine.NAME), matrix);
validate(group);
assertWktEquals(
"PARAMETERGROUP[“Affine parametric transformation”,\n" +
" PARAMETER[“A2”, 4.0, ID[“EPSG”, 8625]],\n" +
" PARAMETER[“B0”, -2.0, ID[“EPSG”, 8639]],\n" +
" PARAMETER[“C2”, 7.0]]", group);
}
内容来源于网络,如有侵权,请联系作者删除!