use of org.apache.sis.parameter.Parameters in project sis by apache.
the class GeocentricAffine method asDatumShift.
/**
* Given a transformation chain, conditionally replaces the affine transform elements by an alternative object
* showing the Bursa-Wolf parameters. The replacement is applied if and only if the affine transform is a scale,
* translation or rotation in the geocentric domain.
*
* <p>This method is invoked only by {@code ConcatenatedTransform.getPseudoSteps()} for the need of WKT formatting.
* The purpose of this method is very similar to the purpose of {@code AbstractMathTransform.beforeFormat(List, int,
* boolean)} except that we need to perform the {@code forDatumShift(…)} work only after {@code beforeFormat(…)}
* finished its work for all {@code ContextualParameters}, including the {@code EllipsoidToCentricTransform}'s one.</p>
*
* @param transforms the full chain of concatenated transforms.
*/
public static void asDatumShift(final List<Object> transforms) {
for (int i = transforms.size() - 2; --i >= 0; ) {
if (isOperation(GeographicToGeocentric.NAME, transforms.get(i)) && isOperation(GeocentricToGeographic.NAME, transforms.get(i + 2))) {
final Object step = transforms.get(i + 1);
if (step instanceof LinearTransform) {
final BursaWolfParameters parameters = new BursaWolfParameters(null, null);
try {
parameters.setPositionVectorTransformation(((LinearTransform) step).getMatrix(), BURSAWOLF_TOLERANCE);
} catch (IllegalArgumentException e) {
/*
* Should not occur, except sometime on inverse transform of relatively complex datum shifts
* (more than just translation terms). We can fallback on formatting the full matrix.
*/
log(Loggers.WKT, "asDatumShift", e);
continue;
}
final boolean isTranslation = parameters.isTranslation();
final Parameters values = createParameters(isTranslation ? GeocentricTranslation.PARAMETERS : PositionVector7Param.PARAMETERS, parameters, isTranslation);
transforms.set(i + 1, new FormattableObject() {
@Override
protected String formatTo(final Formatter formatter) {
WKTUtilities.appendParamMT(values, formatter);
return WKTKeywords.Param_MT;
}
});
}
}
}
}
use of org.apache.sis.parameter.Parameters in project sis by apache.
the class GeocentricAffine method createMathTransform.
/**
* Creates a math transform from the specified group of parameter values.
* The default implementation creates an affine transform, but some subclasses
* will wrap that affine operation into Geographic/Geocentric conversions.
*
* @param factory the factory to use for creating concatenated transforms.
* @param values the group of parameter values.
* @return the created math transform.
* @throws FactoryException if a transform can not be created.
*/
@Override
@SuppressWarnings("fallthrough")
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values) throws FactoryException {
final BursaWolfParameters parameters = new BursaWolfParameters(null, null);
final Parameters pv = Parameters.castOrWrap(values);
boolean reverseRotation = false;
switch(getType()) {
default:
throw new AssertionError();
// Fall through
case FRAME_ROTATION:
reverseRotation = true;
case SEVEN_PARAM:
parameters.rX = pv.doubleValue(RX);
parameters.rY = pv.doubleValue(RY);
parameters.rZ = pv.doubleValue(RZ);
parameters.dS = pv.doubleValue(DS);
case // Fall through
TRANSLATION:
// Fall through
parameters.tX = pv.doubleValue(TX);
parameters.tY = pv.doubleValue(TY);
parameters.tZ = pv.doubleValue(TZ);
}
if (reverseRotation) {
parameters.reverseRotation();
}
return MathTransforms.linear(parameters.getPositionVectorTransformation(null));
}
use of org.apache.sis.parameter.Parameters in project sis by apache.
the class GeocentricAffineBetweenGeographic method createMathTransform.
/**
* Creates a math transform from the specified group of parameter values.
* This method wraps the affine operation into Geographic/Geocentric conversions.
*
* @param factory the factory to use for creating concatenated transforms.
* @param values the group of parameter values.
* @return the created math transform.
* @throws FactoryException if a transform can not be created.
*/
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values) throws FactoryException {
final Parameters pv = Parameters.castOrWrap(values);
final MathTransform affine = super.createMathTransform(factory, pv);
/*
* Create a "Geographic to Geocentric" conversion with ellipsoid axis length units converted to metres
* (the unit implied by SRC_SEMI_MAJOR) because it is the unit of Bursa-Wolf parameters that we created above.
*/
MathTransform toGeocentric = EllipsoidToCentricTransform.createGeodeticConversion(factory, pv.doubleValue(SRC_SEMI_MAJOR), pv.doubleValue(SRC_SEMI_MINOR), Units.METRE, getSourceDimensions() >= 3, EllipsoidToCentricTransform.TargetType.CARTESIAN);
/*
* Create a "Geocentric to Geographic" conversion with ellipsoid axis length units converted to metres
* because this is the unit of the Geocentric CRS used above.
*/
MathTransform toGeographic = EllipsoidToCentricTransform.createGeodeticConversion(factory, pv.doubleValue(TGT_SEMI_MAJOR), pv.doubleValue(TGT_SEMI_MINOR), Units.METRE, getTargetDimensions() >= 3, EllipsoidToCentricTransform.TargetType.CARTESIAN);
try {
toGeographic = toGeographic.inverse();
} catch (NoninvertibleTransformException e) {
// Should never happen with SIS implementation.
throw new FactoryException(e);
}
/*
* The Geocentric → Affine → Geographic chain.
*/
return factory.createConcatenatedTransform(toGeocentric, factory.createConcatenatedTransform(affine, toGeographic));
}
use of org.apache.sis.parameter.Parameters in project sis by apache.
the class Geographic2Dto3D method createMathTransform.
/**
* Returns the transform.
*
* @param factory the factory for creating affine transforms.
* @param values the parameter values.
* @return the math transform for the given parameter values.
* @throws FactoryException if an error occurred while creating the transform.
*/
@Override
public MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup values) throws FactoryException {
final Parameters pv = Parameters.castOrWrap(values);
final MatrixSIS m = Matrices.createDiagonal(4, 3);
m.setElement(2, 2, pv.doubleValue(HEIGHT));
m.setElement(3, 2, 1);
return factory.createAffineTransform(m);
}
use of org.apache.sis.parameter.Parameters in project sis by apache.
the class MolodenskyFormula method getParameterValues.
/**
* Returns a copy of internal parameter values of this transform.
* The returned group contains parameters for the source ellipsoid semi-axis lengths
* and the differences between source and target ellipsoid parameters.
*
* <div class="note"><b>Note:</b>
* this method is mostly for {@linkplain org.apache.sis.io.wkt.Convention#INTERNAL debugging purposes}
* since the isolation of non-linear parameters in this class is highly implementation dependent.
* Most GIS applications will instead be interested in the {@linkplain #getContextualParameters()
* contextual parameters}.</div>
*
* @return a copy of the internal parameter values for this transform.
*/
@Debug
@Override
public ParameterValueGroup getParameterValues() {
final Unit<?> unit = context.getOrCreate(Molodensky.SRC_SEMI_MAJOR).getUnit();
final double semiMinor = context.getOrCreate(Molodensky.SRC_SEMI_MINOR).doubleValue(unit);
final Parameters pg = Parameters.castOrWrap(getParameterDescriptors().createValue());
pg.getOrCreate(Molodensky.SRC_SEMI_MAJOR).setValue(semiMajor, unit);
pg.getOrCreate(Molodensky.SRC_SEMI_MINOR).setValue(semiMinor, unit);
completeParameters(pg, semiMinor, unit, Double.NaN);
return pg;
}
Aggregations