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;
}
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;
}
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() };
}
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;
}
Aggregations