Search in sources :

Example 11 with GeneralEnvelope

use of org.apache.sis.geometry.GeneralEnvelope in project sis by apache.

the class Geometries method toString.

/**
 * If the given object is one of the recognized types, returns a short string representation
 * (typically the class name and the bounds). Otherwise returns {@code null}.
 *
 * @param  geometry  the geometry from which to get a string representation, or {@code null}.
 * @return a short string representation of the given geometry, or {@code null} if the given
 *         object is not a recognized geometry.
 */
public static String toString(final Object geometry) {
    for (Geometries<?> g = implementation; g != null; g = g.fallback) {
        String s = g.tryGetLabel(geometry);
        if (s != null) {
            GeneralEnvelope env = g.tryGetEnvelope(geometry);
            if (env != null) {
                final String bbox = env.toString();
                s += bbox.substring(bbox.indexOf('('));
            }
            return s;
        }
    }
    return null;
}
Also used : GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope)

Example 12 with GeneralEnvelope

use of org.apache.sis.geometry.GeneralEnvelope in project sis by apache.

the class JTS method tryGetEnvelope.

/**
 * If the given object is a JTS geometry and its envelope is non-empty, returns
 * that envelope as an Apache SIS implementation. Otherwise returns {@code null}.
 *
 * @param  geometry  the geometry from which to get the envelope, or {@code null}.
 * @return the envelope of the given object, or {@code null} if the object is not
 *         a recognized geometry or its envelope is empty.
 */
@Override
final GeneralEnvelope tryGetEnvelope(final Object geometry) {
    final double xmin, ymin, xmax, ymax;
    if (rootClass.isInstance(geometry)) {
        try {
            final Object env = getEnvelopeInternal.invoke(geometry, (Object[]) null);
            xmin = (Double) getMinX.invoke(env, (Object[]) null);
            ymin = (Double) getMinY.invoke(env, (Object[]) null);
            xmax = (Double) getMaxX.invoke(env, (Object[]) null);
            ymax = (Double) getMaxY.invoke(env, (Object[]) null);
        } catch (ReflectiveOperationException e) {
            if (e instanceof InvocationTargetException) {
                final Throwable cause = e.getCause();
                if (cause instanceof RuntimeException) {
                    throw (RuntimeException) cause;
                }
                if (cause instanceof Error) {
                    throw (Error) cause;
                }
            }
            // Should never happen unless JTS's API changed.
            throw (Error) new IncompatibleClassChangeError(e.toString()).initCause(e);
        }
        final GeneralEnvelope env = new GeneralEnvelope(2);
        env.setRange(0, xmin, xmax);
        env.setRange(1, ymin, ymax);
        return env;
    }
    return null;
}
Also used : GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with GeneralEnvelope

use of org.apache.sis.geometry.GeneralEnvelope in project sis by apache.

the class Transformer method transformEnvelope.

/**
 * Transforms the given envelope.
 */
final double[][] transformEnvelope(final double[][] points) throws TransformException {
    final double[] min = new double[operation.getMathTransform().getSourceDimensions()];
    final double[] max = new double[min.length];
    Arrays.fill(min, Double.POSITIVE_INFINITY);
    Arrays.fill(max, Double.NEGATIVE_INFINITY);
    for (final double[] p : points) {
        if (p != null) {
            // Paranoiac check.
            for (int i = Math.min(min.length, p.length); --i >= 0; ) {
                final double v = p[i];
                if (v < min[i])
                    min[i] = v;
                if (v > max[i])
                    max[i] = v;
            }
        }
    }
    final GeneralEnvelope result = Envelopes.transform(operation, new GeneralEnvelope(min, max));
    return new double[][] { result.getLowerCorner().getCoordinate(), result.getUpperCorner().getCoordinate() };
}
Also used : GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope)

Example 14 with GeneralEnvelope

use of org.apache.sis.geometry.GeneralEnvelope in project sis by apache.

the class LinearTransformBuilder method envelope.

/**
 * Implementation of {@link #getSourceEnvelope()} and {@link #getTargetEnvelope()}.
 */
private static Envelope envelope(final double[][] points) {
    if (points == null) {
        throw new IllegalStateException(noData());
    }
    final int dim = points.length;
    final GeneralEnvelope envelope = new GeneralEnvelope(dim);
    for (int i = 0; i < dim; i++) {
        final double[] data = points[i];
        double lower = Double.POSITIVE_INFINITY;
        double upper = Double.NEGATIVE_INFINITY;
        for (final double value : data) {
            if (value < lower)
                lower = value;
            if (value > upper)
                upper = value;
        }
        if (lower > upper) {
            lower = upper = Double.NaN;
        }
        envelope.setRange(i, lower, upper);
    }
    return envelope;
}
Also used : GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope)

Aggregations

GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)14 Envelope2D (org.apache.sis.geometry.Envelope2D)3 Test (org.junit.Test)3 Envelope (org.opengis.geometry.Envelope)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Envelope2D (com.esri.core.geometry.Envelope2D)1 Geometry (com.esri.core.geometry.Geometry)1 Point (com.esri.core.geometry.Point)1 Polygon (com.esri.core.geometry.Polygon)1 Shape (java.awt.Shape)1 Rectangle2D (java.awt.geom.Rectangle2D)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Instant (java.time.Instant)1 Time (javax.measure.quantity.Time)1 GeodeticObjectBuilder (org.apache.sis.internal.referencing.GeodeticObjectBuilder)1 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)1 DefaultGeographicCRS (org.apache.sis.referencing.crs.DefaultGeographicCRS)1 DataStoreReferencingException (org.apache.sis.storage.DataStoreReferencingException)1 GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1