Search in sources :

Example 6 with Envelope

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

the class BBOXType method getMinY.

@Override
public double getMinY() {
    Object candidate = getAny();
    if (candidate instanceof JAXBElement) {
        candidate = ((JAXBElement) candidate).getValue();
    }
    if (candidate instanceof Envelope) {
        final Envelope env = (Envelope) candidate;
        final DirectPosition pos = env.getLowerCorner();
        if (pos != null && pos.getCoordinate() != null && pos.getCoordinate().length > 1) {
            return pos.getCoordinate()[1];
        }
    }
    return -1;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) JAXBElement(javax.xml.bind.JAXBElement) Envelope(org.geotoolkit.gml.xml.Envelope)

Example 7 with Envelope

use of org.geotoolkit.gml.xml.Envelope 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)

Example 8 with Envelope

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

the class GeoSpatialBound method extractBoundary.

private void extractBoundary(final AbstractGeometry geom) {
    if (geom instanceof Point) {
        final Point p = (Point) geom;
        if (p.getPos() != null) {
            addXCoordinate(p.getPos().getOrdinate(0));
            addYCoordinate(p.getPos().getOrdinate(1));
        }
    } else if (geom instanceof LineString) {
        final LineString ls = (LineString) geom;
        final Envelope env = ls.getBounds();
        if (env != null) {
            addXCoordinate(env.getMinimum(0));
            addXCoordinate(env.getMaximum(0));
            addYCoordinate(env.getMinimum(1));
            addYCoordinate(env.getMaximum(1));
        }
    } else if (geom instanceof Polygon) {
        final Polygon p = (Polygon) geom;
        AbstractRing ext = p.getExterior().getAbstractRing();
    // TODO
    }
}
Also used : AbstractRing(org.geotoolkit.gml.xml.AbstractRing) LineString(org.geotoolkit.gml.xml.LineString) Point(org.geotoolkit.gml.xml.Point) Envelope(org.geotoolkit.gml.xml.Envelope) Polygon(org.geotoolkit.gml.xml.Polygon)

Aggregations

Envelope (org.geotoolkit.gml.xml.Envelope)8 DirectPosition (org.opengis.geometry.DirectPosition)5 JAXBElement (javax.xml.bind.JAXBElement)4 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 Consumer (java.util.function.Consumer)1 DoubleFunction (java.util.function.DoubleFunction)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Logger (java.util.logging.Logger)1