use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.
the class EllipsoidToCentricTransformTest method testDerivative.
/**
* Executes the derivative test using the given ellipsoid.
*
* @param ellipsoid the ellipsoid to use for the test.
* @param hasHeight {@code true} if geographic coordinates include an ellipsoidal height (i.e. are 3-D),
* or {@code false} if they are only 2-D.
* @throws FactoryException if an error occurred while creating a transform.
* @throws TransformException should never happen.
*/
private void testDerivative(final Ellipsoid ellipsoid, final boolean hasHeight) throws FactoryException, TransformException {
createGeodeticConversion(ellipsoid, hasHeight);
DirectPosition point = hasHeight ? new GeneralDirectPosition(-10, 40, 200) : new DirectPosition2D(-10, 40);
/*
* Derivative of the direct transform.
*/
tolerance = 1E-2;
// Approximatively one metre.
derivativeDeltas = new double[] { toRadians(1.0 / 60) / 1852 };
verifyDerivative(point.getCoordinate());
/*
* Derivative of the inverse transform.
*/
point = transform.transform(point, null);
transform = transform.inverse();
tolerance = 1E-8;
// Approximatively one metre.
derivativeDeltas = new double[] { 1 };
verifyDerivative(point.getCoordinate());
}
use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.
the class AbstractLocation method getPosition.
/**
* Returns coordinates of a representative point for the location instance.
* This is typically (but not necessarily) the centroid of the location instance.
*
* <p>The default implementation returns the {@linkplain #getEnvelope()} median position.</p>
*
* @return coordinates of a representative point for the location instance, or {@code null} if none.
*/
public Position getPosition() {
final Envelope envelope = getEnvelope();
if (envelope == null) {
return null;
}
final int dimension = envelope.getDimension();
final GeneralDirectPosition pos = new GeneralDirectPosition(dimension);
pos.setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem());
for (int i = 0; i < dimension; i++) {
pos.setOrdinate(i, envelope.getMedian(i));
}
return pos;
}
use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.
the class ReferencingAssert method assertContains.
/**
* Tests if the given {@code outer} envelope contains the given {@code inner} envelope.
* This method will also verify class consistency by invoking the {@code intersects}
* method, and by interchanging the arguments.
*
* @param outer the envelope which is expected to contains the given inner envelope.
* @param inner the envelope which should be contained by the outer envelope.
*/
public static void assertContains(final AbstractEnvelope outer, final Envelope inner) {
assertTrue("outer.contains(inner)", outer.contains(inner, true));
assertTrue("outer.contains(inner)", outer.contains(inner, false));
assertTrue("outer.intersects(inner)", outer.intersects(inner, true));
assertTrue("outer.intersects(inner)", outer.intersects(inner, false));
if (inner instanceof AbstractEnvelope) {
final AbstractEnvelope ai = (AbstractEnvelope) inner;
assertTrue("inner.intersects(outer)", ai.intersects(outer, true));
assertTrue("inner.intersects(outer)", ai.intersects(outer, false));
assertFalse("inner.contains(outer)", ai.contains(outer, true));
assertFalse("inner.contains(outer)", ai.contains(outer, false));
}
final GeneralDirectPosition median = new GeneralDirectPosition(inner.getDimension());
for (int i = median.getDimension(); --i >= 0; ) {
median.setOrdinate(i, inner.getMedian(i));
}
assertTrue("outer.contains(median)", outer.contains(median));
}
use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.
the class PassThroughTransform method derivative.
/**
* Gets the derivative of this transform at a point.
*
* @return {@inheritDoc}
* @throws TransformException if the {@linkplain #subTransform sub-transform} failed.
*/
@Override
public Matrix derivative(final DirectPosition point) throws TransformException {
final int nSkipped = firstAffectedOrdinate + numTrailingOrdinates;
final int transDim = subTransform.getSourceDimensions();
ensureDimensionMatches("point", transDim + nSkipped, point);
final GeneralDirectPosition subPoint = new GeneralDirectPosition(transDim);
for (int i = 0; i < transDim; i++) {
subPoint.ordinates[i] = point.getOrdinate(i + firstAffectedOrdinate);
}
return expand(MatrixSIS.castOrCopy(subTransform.derivative(subPoint)), firstAffectedOrdinate, numTrailingOrdinates, 0);
}
use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.
the class AbstractMathTransform method transform.
/**
* Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}.
* The default implementation performs the following steps:
*
* <ul>
* <li>Ensures that the dimension of the given points are consistent with the
* {@linkplain #getSourceDimensions() source} and {@linkplain #getTargetDimensions()
* target dimensions} of this math transform.</li>
* <li>Delegates to the {@link #transform(double[], int, double[], int, boolean)} method.</li>
* </ul>
*
* This method does not update the associated {@link org.opengis.referencing.crs.CoordinateReferenceSystem} value.
*
* @param ptSrc the coordinate point to be transformed.
* @param ptDst the coordinate point that stores the result of transforming {@code ptSrc}, or {@code null}.
* @return the coordinate point after transforming {@code ptSrc} and storing the result in {@code ptDst},
* or a newly created point if {@code ptDst} was null.
* @throws MismatchedDimensionException if {@code ptSrc} or {@code ptDst} doesn't have the expected dimension.
* @throws TransformException if the point can not be transformed.
*/
@Override
public DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) throws TransformException {
final int dimSource = getSourceDimensions();
final int dimTarget = getTargetDimensions();
ensureDimensionMatches("ptSrc", dimSource, ptSrc);
if (ptDst != null) {
ensureDimensionMatches("ptDst", dimTarget, ptDst);
/*
* Transforms the coordinates using a temporary 'double[]' buffer,
* and copies the transformation result in the destination position.
*/
final double[] array;
if (dimSource >= dimTarget) {
array = ptSrc.getCoordinate();
} else {
array = new double[dimTarget];
for (int i = dimSource; --i >= 0; ) {
array[i] = ptSrc.getOrdinate(i);
}
}
transform(array, 0, array, 0, false);
for (int i = 0; i < dimTarget; i++) {
ptDst.setOrdinate(i, array[i]);
}
} else {
/*
* Destination not set. We are going to create the destination here. Since we know that the
* destination will be the SIS implementation, write directly into the 'ordinates' array.
*/
final GeneralDirectPosition destination = new GeneralDirectPosition(dimTarget);
final double[] source;
if (dimSource <= dimTarget) {
source = destination.ordinates;
for (int i = 0; i < dimSource; i++) {
source[i] = ptSrc.getOrdinate(i);
}
} else {
source = ptSrc.getCoordinate();
}
transform(source, 0, destination.ordinates, 0, false);
ptDst = destination;
}
return ptDst;
}
Aggregations