Java Code Examples for org.opengis.referencing.operation.MathTransform#isIdentity()

The following examples show how to use org.opengis.referencing.operation.MathTransform#isIdentity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcatenatedTransform.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of single {@linkplain MathTransform math transform} steps performed
 * by the given transform. As a special case, we returns 0 for the identity transform since
 * it should be omitted from the final chain.
 */
private static int getStepCount(final MathTransform transform) {
    if (transform.isIdentity()) {
        return 0;
    }
    if (!(transform instanceof ConcatenatedTransform)) {
        return 1;
    }
    return ((ConcatenatedTransform) transform).getStepCount();
}
 
Example 2
Source File: WraparoundAdjustment.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms {@link #domainOfValidity} to the same CRS than the Area Of Interest (AOI) or Point Of Interest (POI).
 * This method should be invoked only when the caller detected a wraparound axis. This method transforms the domain
 * the first time it is invoked, and does nothing on all subsequent calls.
 */
private void transformDomainToAOI() throws TransformException {
    if (!isDomainTransformed) {
        isDomainTransformed = true;
        MathTransform domainToGeographic = domainToAOI;
        if (domainToGeographic == null) {
            domainToGeographic = geographicToAOI;
        } else if (geographicToAOI != null) {
            domainToGeographic = MathTransforms.concatenate(domainToGeographic, geographicToAOI.inverse());
        }
        if (domainToGeographic != null && !domainToGeographic.isIdentity()) {
            domainOfValidity = Envelopes.transform(domainToGeographic, domainOfValidity);
        }
    }
}
 
Example 3
Source File: GridGeometry.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new grid geometry derived from the given grid geometry with a new extent and a modified transform.
 * This constructor is used for creating a grid geometry over a subregion (for example with the grid extent
 * computed by {@link GridDerivation#subgrid(Envelope, double...)}) or grid geometry for a subsampled raster.
 *
 * <p>If {@code toOther} is non-null, it should be a transform from the given {@code extent} coordinates to the
 * {@code other} grid coordinates. That transform should be merely a {@linkplain MathTransforms#scale(double...)
 * scale} and {@linkplain MathTransforms#translation(double...) translation} even if more complex transforms are
 * accepted. The {@link #cornerToCRS} transform of the new grid geometry will be set to the following concatenation:</p>
 *
 * <blockquote>{@code this.cornerToCRS} = {@code toOther} → {@code other.cornerToCRS}</blockquote>
 *
 * The new {@linkplain #getEnvelope() grid geometry envelope} will be {@linkplain GeneralEnvelope#intersect(Envelope)
 * clipped} to the envelope of the other grid geometry. This is for preventing the envelope to become larger under the
 * effect of subsampling (because {@link GridExtent#subsample(int[]) each cell become larger}).
 *
 * @param  other    the other grid geometry to copy.
 * @param  extent   the new extent for the grid geometry to construct, or {@code null} if none.
 * @param  toOther  transform from this grid coordinates to {@code other} grid coordinates, or {@code null} if none.
 * @throws NullPointerException if {@code extent} is {@code null} and the other grid geometry contains no other information.
 * @throws TransformException if the math transform can not compute the geospatial envelope from the grid extent.
 *
 * @see GridDerivation#subgrid(Envelope, double...)
 */
GridGeometry(final GridGeometry other, final GridExtent extent, final MathTransform toOther) throws TransformException {
    final int dimension = other.getDimension();
    this.extent = extent;
    ensureDimensionMatches(dimension, extent);
    if (toOther == null || toOther.isIdentity()) {
        gridToCRS   = other.gridToCRS;
        cornerToCRS = other.cornerToCRS;
        resolution  = other.resolution;
        nonLinears  = other.nonLinears;
    } else {
        /*
         * The `toOther` transform applies on `cornerToCRS` because the corner of upper-left pixel before scaling
         * is still the corner of upper-left pixel after scaling, while "pixel center" is no longer the center of
         * the same pixel. We adjust `toOther` instead than invoking `PixelTranslation.translate(cornerToCRS, …)`
         * because we do not know which of `cornerToCRS` or `gridToCRS` has less NaN values.
         */
        final MathTransform centerShift = MathTransforms.concatenate(
                MathTransforms.uniformTranslation(dimension, +0.5), toOther,
                MathTransforms.uniformTranslation(dimension, -0.5));
        cornerToCRS = MathTransforms.concatenate(toOther, other.cornerToCRS);
        gridToCRS   = MathTransforms.concatenate(centerShift, other.gridToCRS);
        resolution  = resolution(gridToCRS, extent);
        nonLinears  = findNonLinearTargets(gridToCRS);
    }
    ImmutableEnvelope envelope = other.envelope;            // We will share the same instance if possible.
    ImmutableEnvelope computed = computeEnvelope(gridToCRS, getCoordinateReferenceSystem(envelope), envelope);
    if (computed == null || !computed.equals(envelope)) {
        envelope = computed;
    }
    this.envelope = envelope;
    if (envelope == null && gridToCRS == null) {
        ArgumentChecks.ensureNonNull("extent", extent);
    }
}
 
Example 4
Source File: GeoWaveRasterReader.java    From geowave with Apache License 2.0 4 votes vote down vote up
/**
 * transforms (if necessary) the requested envelope into the CRS used by this reader.
 *
 * @throws DataSourceException
 */
public static void transformRequestEnvelope(
    final GeoWaveRasterReaderState state,
    final CoordinateReferenceSystem crs) throws DataSourceException {

  if (CRS.equalsIgnoreMetadata(
      state.getRequestedEnvelope().getCoordinateReferenceSystem(),
      crs)) {
    state.setRequestEnvelopeXformed(state.getRequestedEnvelope());

    return; // and finish
  }

  try {
    /** Buffered factory for coordinate operations. */

    // transforming the envelope back to the dataset crs in
    final MathTransform transform =
        OPERATION_FACTORY.createOperation(
            state.getRequestedEnvelope().getCoordinateReferenceSystem(),
            crs).getMathTransform();

    if (transform.isIdentity()) { // Identity Transform ?
      state.setRequestEnvelopeXformed(state.getRequestedEnvelope());
      return; // and finish
    }

    state.setRequestEnvelopeXformed(CRS.transform(transform, state.getRequestedEnvelope()));
    state.getRequestEnvelopeXformed().setCoordinateReferenceSystem(crs);

    // if (config.getIgnoreAxisOrder() == false) { // check for axis
    // order
    // required
    final int indexX = indexOfX(crs);
    final int indexY = indexOfY(crs);
    final int indexRequestedX =
        indexOfX(state.getRequestedEnvelope().getCoordinateReferenceSystem());
    final int indexRequestedY =
        indexOfY(state.getRequestedEnvelope().getCoordinateReferenceSystem());

    // x Axis problem ???
    if ((indexX == indexRequestedY) && (indexY == indexRequestedX)) {
      state.setAxisSwap(true);
      final Rectangle2D tmp =
          new Rectangle2D.Double(
              state.getRequestEnvelopeXformed().getMinimum(1),
              state.getRequestEnvelopeXformed().getMinimum(0),
              state.getRequestEnvelopeXformed().getSpan(1),
              state.getRequestEnvelopeXformed().getSpan(0));
      state.setRequestEnvelopeXformed(new GeneralEnvelope(tmp));
      state.getRequestEnvelopeXformed().setCoordinateReferenceSystem(crs);
    } else if ((indexX == indexRequestedX) && (indexY == indexRequestedY)) {
      // everything is fine
    } else {
      throw new DataSourceException("Unable to resolve the X Axis problem");
    }
    // }
  } catch (final Exception e) {
    throw new DataSourceException("Unable to create a coverage for this source", e);
  }
}
 
Example 5
Source File: MathTransforms.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a transform which passes through a subset of coordinates to another transform.
 * This method returns a transform having the following dimensions:
 *
 * {@preformat java
 *     Source: firstAffectedCoordinate + subTransform.getSourceDimensions() + numTrailingCoordinates
 *     Target: firstAffectedCoordinate + subTransform.getTargetDimensions() + numTrailingCoordinates
 * }
 *
 * Affected coordinates will range from {@code firstAffectedCoordinate} inclusive to
 * {@code dimTarget - numTrailingCoordinates} exclusive.
 *
 * @param  firstAffectedCoordinate  index of the first affected coordinate.
 * @param  subTransform             the sub-transform to apply on modified coordinates.
 * @param  numTrailingCoordinates   number of trailing coordinates to pass through.
 * @return a pass-through transform, potentially as a {@link PassThroughTransform} instance but not necessarily.
 *
 * @since 1.0
 */
public static MathTransform passThrough(final int firstAffectedCoordinate,
                                        final MathTransform subTransform,
                                        final int numTrailingCoordinates)
{
    ArgumentChecks.ensureNonNull ("subTransform",            subTransform);
    ArgumentChecks.ensurePositive("firstAffectedCoordinate", firstAffectedCoordinate);
    ArgumentChecks.ensurePositive("numTrailingCoordinates",  numTrailingCoordinates);
    if (firstAffectedCoordinate == 0 && numTrailingCoordinates == 0) {
        return subTransform;
    }
    if (subTransform.isIdentity()) {
        final int dimension = subTransform.getSourceDimensions();
        if (dimension == subTransform.getTargetDimensions()) {
            return IdentityTransform.create(firstAffectedCoordinate + dimension + numTrailingCoordinates);
        }
    }
    return PassThroughTransform.create(firstAffectedCoordinate, subTransform, numTrailingCoordinates);
}