Example usage for org.hibernate.spatial.criterion SpatialRestrictions filter

List of usage examples for org.hibernate.spatial.criterion SpatialRestrictions filter

Introduction

In this page you can find the example usage for org.hibernate.spatial.criterion SpatialRestrictions filter.

Prototype

public static SpatialFilter filter(String propertyName, Envelope envelope, int srid) 

Source Link

Document

Apply a bounding box overlap constraint to the named property

Usage

From source file:org.n52.series.db.dao.DbQuery.java

License:Open Source License

public Criteria addSpatialFilterTo(Criteria criteria, DbQuery query) {
    BoundingBox spatialFilter = parameters.getSpatialFilter();
    if (spatialFilter != null) {
        try {//w w  w  . j  a v  a2s  .  c om
            CRSUtils crsUtils = CRSUtils.createEpsgForcedXYAxisOrder();
            int databaseSrid = crsUtils.getSrsIdFrom(sridAuthorityCode);
            Point ll = (Point) crsUtils.transformInnerToOuter(spatialFilter.getLowerLeft(), sridAuthorityCode);
            Point ur = (Point) crsUtils.transformInnerToOuter(spatialFilter.getUpperRight(), sridAuthorityCode);
            Envelope envelope = new Envelope(ll.getCoordinate(), ur.getCoordinate());
            criteria.add(SpatialRestrictions.filter("geometryEntity.geometry", envelope, databaseSrid));

            // TODO intersect with linestring

            // XXX do sampling filter only on generated line strings stored in FOI table,
            // otherwise we would have to check each observation row

        } catch (FactoryException e) {
            LOGGER.error("Could not create transformation facilities.", e);
        } catch (TransformException e) {
            LOGGER.error("Could not perform transformation.", e);
        }
    }

    Set<String> geometryTypes = parameters.getGeometryTypes();
    for (String geometryType : geometryTypes) {
        if (!geometryType.isEmpty()) {
            Type type = getGeometryType(geometryType);
            if (type != null) {
                criteria.add(SpatialRestrictions.geometryType("geometryEntity.geometry", type));
            }
        }
    }
    return criteria;
}