Search in sources :

Example 1 with BBox

use of org.n52.io.response.BBox in project series-rest-api by 52North.

the class IoParameters method createBbox.

/**
     * @return a {@link BBox} instance or <code>null</code> if no {@link #BBOX} parameter is present.
     * @throws IoParseException
     *         if parsing parameter fails.
     * @throws IoParseException
     *         if a requested {@value #CRS} object could not be created
     */
private BBox createBbox() {
    if (!containsParameter(BBOX)) {
        return null;
    }
    String bboxValue = getAsString(BBOX);
    BBox bbox = parseJson(bboxValue, BBox.class);
    bbox.setLl(convertToCrs84(bbox.getLl()));
    bbox.setUr(convertToCrs84(bbox.getUr()));
    return bbox;
}
Also used : BBox(org.n52.io.response.BBox)

Example 2 with BBox

use of org.n52.io.response.BBox 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 3 with BBox

use of org.n52.io.response.BBox 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 4 with BBox

use of org.n52.io.response.BBox 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 5 with BBox

use of org.n52.io.response.BBox 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)3 Point (com.vividsolutions.jts.geom.Point)2 CRSUtils (org.n52.io.crs.CRSUtils)2 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)2 BBox (org.n52.io.response.BBox)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 Before (org.junit.Before)1 Test (org.junit.Test)1