Search in sources :

Example 1 with BoundingBox

use of org.n52.io.crs.BoundingBox in project series-rest-api by 52North.

the class IoParameters method extendBy.

/**
     * Extends the bounding box with the given point. If point is contained by this instance nothing is
     * changed.
     *
     * @param point
     *        the point in CRS:84 which shall extend the bounding box.
     */
private void extendBy(Point point, BoundingBox bbox) {
    if (bbox.contains(point)) {
        return;
    }
    double llX = Math.min(point.getX(), bbox.getLowerLeft().getX());
    double llY = Math.max(point.getX(), bbox.getUpperRight().getX());
    double urX = Math.min(point.getY(), bbox.getLowerLeft().getY());
    double urY = Math.max(point.getY(), bbox.getUpperRight().getY());
    CRSUtils crsUtils = CRSUtils.createEpsgForcedXYAxisOrder();
    bbox.setLl(crsUtils.createPoint(llX, llY, bbox.getSrs()));
    bbox.setUr(crsUtils.createPoint(urX, urY, bbox.getSrs()));
}
Also used : CRSUtils(org.n52.io.crs.CRSUtils)

Example 2 with BoundingBox

use of org.n52.io.crs.BoundingBox in project series-rest-api by 52North.

the class IoParameters method mergeBounds.

private BoundingBox mergeBounds(BoundingBox bounds, BBox bboxBounds) {
    if (bboxBounds == null) {
        // nothing to merge
        return bounds;
    }
    CRSUtils crsUtils = CRSUtils.createEpsgForcedXYAxisOrder();
    Point lowerLeft = crsUtils.convertToPointFrom(bboxBounds.getLl());
    Point upperRight = crsUtils.convertToPointFrom(bboxBounds.getUr());
    if (bounds == null) {
        BoundingBox parsed = new BoundingBox(lowerLeft, upperRight, CRSUtils.DEFAULT_CRS);
        LOGGER.debug("Parsed bbox bounds: {}", parsed.toString());
        return parsed;
    } else {
        extendBy(lowerLeft, bounds);
        extendBy(upperRight, bounds);
        LOGGER.debug("Merged bounds: {}", bounds.toString());
        return bounds;
    }
}
Also used : BoundingBox(org.n52.io.crs.BoundingBox) CRSUtils(org.n52.io.crs.CRSUtils) Point(com.vividsolutions.jts.geom.Point) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint)

Example 3 with BoundingBox

use of org.n52.io.crs.BoundingBox in project series-rest-api by 52North.

the class IoParameters method getSpatialFilter.

/**
     * Creates a {@link BoundingBox} instance from given spatial request parameters. The resulting bounding
     * box is the merged extent of all spatial filters given. For example if {@value #NEAR} and {@value #BBOX}
     * exist, the returned bounding box includes both extents.
     *
     * @return a spatial filter created from given spatial parameters.
     * @throws IoParseException
     *         if parsing parameters fails, or if a requested {@value #CRS} object could not be created.
     */
public BoundingBox getSpatialFilter() {
    if (!containsParameter(NEAR) && !containsParameter(BBOX)) {
        return null;
    }
    BBox bboxBounds = createBbox();
    BoundingBox bounds = parseBoundsFromVicinity();
    return mergeBounds(bounds, bboxBounds);
}
Also used : BBox(org.n52.io.response.BBox) BoundingBox(org.n52.io.crs.BoundingBox)

Example 4 with BoundingBox

use of org.n52.io.crs.BoundingBox in project series-rest-api by 52North.

the class Vicinity method calculateBounds.

/**
     * Calculates bounding box with the given CRS context.
     *
     * @param crsUtils the reference context.
     * @return a bounding rectangle.
     * @throws IllegalStateException if invalid crs was set.
     */
public BoundingBox calculateBounds(CRSUtils crsUtils) {
    Point point = createPoint(this.center, crsUtils);
    double latInRad = Math.toRadians(point.getY());
    final double latitudeDelta = WGS84Util.getLatitudeDelta(radius);
    final double longitudeDelta = WGS84Util.getLongitudeDelta(latInRad, radius);
    double llEasting = WGS84Util.normalizeLongitude(point.getX() - longitudeDelta);
    double llNorthing = WGS84Util.normalizeLatitude(point.getY() - latitudeDelta);
    double urEasting = WGS84Util.normalizeLongitude(point.getX() + longitudeDelta);
    double urNorthing = WGS84Util.normalizeLatitude(point.getY() + latitudeDelta);
    try {
        if (crsUtils.isLatLonAxesOrder(crs)) {
            Point ll = crsUtils.createPoint(llNorthing, llEasting, crs);
            Point ur = crsUtils.createPoint(urNorthing, urEasting, crs);
            return new BoundingBox(ll, ur, crs);
        }
        Point ll = crsUtils.createPoint(llEasting, llNorthing, crs);
        Point ur = crsUtils.createPoint(urEasting, urNorthing, crs);
        return new BoundingBox(ll, ur, crs);
    } catch (FactoryException e) {
        throw new IllegalStateException("Illegal CRS parameter: " + crs, e);
    }
}
Also used : FactoryException(org.opengis.referencing.FactoryException) BoundingBox(org.n52.io.crs.BoundingBox) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint) Point(com.vividsolutions.jts.geom.Point)

Example 5 with BoundingBox

use of org.n52.io.crs.BoundingBox in project series-rest-api by 52North.

the class CRSUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    referenceHelper = CRSUtils.createEpsgStrictAxisOrder();
    Point ll = referenceHelper.createPoint(6.4, 51.9, DEFAULT_CRS);
    Point ur = referenceHelper.createPoint(8.9, 53.4, DEFAULT_CRS);
    //        EastingNorthing ll = new EastingNorthing(6.4, 51.9, DEFAULT_CRS);
    //        EastingNorthing ur = new EastingNorthing(8.9, 53.4, DEFAULT_CRS);
    bbox = new BoundingBox(ll, ur, DEFAULT_CRS);
}
Also used : Point(com.vividsolutions.jts.geom.Point) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint) Before(org.junit.Before)

Aggregations

BoundingBox (org.n52.io.crs.BoundingBox)9 Test (org.junit.Test)5 Point (com.vividsolutions.jts.geom.Point)3 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)3 CRSUtils (org.n52.io.crs.CRSUtils)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 Before (org.junit.Before)1 BBox (org.n52.io.response.BBox)1 FactoryException (org.opengis.referencing.FactoryException)1