Search in sources :

Example 1 with AbstractFeature

use of org.geotoolkit.gml.xml.AbstractFeature in project geotoolkit by Geomatys.

the class OMUtils method getCollectionBound.

/**
 * Return an envelope containing all the Observation member of the collection.
 *
 * @param version
 * @param observations
 * @param srsName
 * @return
 */
public static Envelope getCollectionBound(final String version, final List<Observation> observations, final String srsName) {
    double minx = Double.MAX_VALUE;
    double miny = Double.MAX_VALUE;
    double maxx = -Double.MAX_VALUE;
    double maxy = -Double.MAX_VALUE;
    for (Observation observation : observations) {
        final AbstractFeature feature = (AbstractFeature) observation.getFeatureOfInterest();
        if (feature != null) {
            if (feature.getBoundedBy() != null) {
                final BoundingShape bound = feature.getBoundedBy();
                if (bound.getEnvelope() != null) {
                    if (bound.getEnvelope().getLowerCorner() != null && bound.getEnvelope().getLowerCorner().getCoordinate() != null && bound.getEnvelope().getLowerCorner().getCoordinate().length == 2) {
                        final double[] lower = bound.getEnvelope().getLowerCorner().getCoordinate();
                        if (lower[0] < minx) {
                            minx = lower[0];
                        }
                        if (lower[1] < miny) {
                            miny = lower[1];
                        }
                    }
                    if (bound.getEnvelope().getUpperCorner() != null && bound.getEnvelope().getUpperCorner().getCoordinate() != null && bound.getEnvelope().getUpperCorner().getCoordinate().length == 2) {
                        final double[] upper = bound.getEnvelope().getUpperCorner().getCoordinate();
                        if (upper[0] > maxx) {
                            maxx = upper[0];
                        }
                        if (upper[1] > maxy) {
                            maxy = upper[1];
                        }
                    }
                }
            }
        }
    }
    if (minx == Double.MAX_VALUE) {
        minx = -180.0;
    }
    if (miny == Double.MAX_VALUE) {
        miny = -90.0;
    }
    if (maxx == (-Double.MAX_VALUE)) {
        maxx = 180.0;
    }
    if (maxy == (-Double.MAX_VALUE)) {
        maxy = 90.0;
    }
    final Envelope env = SOSXmlFactory.buildEnvelope(version, null, minx, miny, maxx, maxy, srsName);
    env.setSrsDimension(2);
    env.setAxisLabels(Arrays.asList("Y X"));
    return env;
}
Also used : BoundingShape(org.geotoolkit.gml.xml.BoundingShape) Observation(org.opengis.observation.Observation) AbstractObservation(org.geotoolkit.observation.xml.AbstractObservation) AbstractFeature(org.geotoolkit.gml.xml.AbstractFeature) Envelope(org.geotoolkit.gml.xml.Envelope)

Aggregations

AbstractFeature (org.geotoolkit.gml.xml.AbstractFeature)1 BoundingShape (org.geotoolkit.gml.xml.BoundingShape)1 Envelope (org.geotoolkit.gml.xml.Envelope)1 AbstractObservation (org.geotoolkit.observation.xml.AbstractObservation)1 Observation (org.opengis.observation.Observation)1