All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mysema.query.spatial.GeometryExpressions Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mysema.query.spatial;

import org.geolatte.geom.Geometry;
import org.geolatte.geom.GeometryCollection;

import com.mysema.query.types.ConstantImpl;
import com.mysema.query.types.Expression;
import com.mysema.query.types.expr.*;

/**
 * GeometryExpressions contains static functions for GEO operations
 */
public final class GeometryExpressions {

    /**
     * Return a specified ST_Geometry value from Extended Well-Known Text representation (EWKT).
     *
     * @param expr
     * @return
     */
    public static StringExpression asEWKT(GeometryExpression expr) {
        return StringOperation.create(SpatialOps.AS_EWKT, expr);
    }

    /**
     * Return a specified ST_Geometry value from Well-Known Text representation (WKT).
     *
     * @param text
     * @return
     */
    public static GeometryExpression fromText(String text) {
        return GeometryOperation.create(Geometry.class, SpatialOps.GEOM_FROM_TEXT, ConstantImpl.create(text));
    }

    /**
     * Return a specified ST_Geometry value from Well-Known Text representation (WKT).
     *
     * @param text
     * @return
     */
    public static GeometryExpression fromText(Expression text) {
        return GeometryOperation.create(Geometry.class, SpatialOps.GEOM_FROM_TEXT, text);
    }

    /**
     * Sets the SRID on a geometry to a particular integer value.
     *
     * @param expr
     * @param srid
     * @param 
     * @return
     */
    public static  GeometryExpression setSRID(Expression expr, int srid) {
        return (GeometryExpression)GeometryOperation.create(expr.getType(), SpatialOps.SET_SRID,
                expr, ConstantImpl.create(srid));
    }

    /**
     * Returns X minima of a bounding box 2d or 3d or a geometry.
     *
     * @param expr
     * @return
     */
    public static NumberExpression xmin(GeometryExpression expr) {
        return NumberOperation.create(Double.class, SpatialOps.XMIN, expr);
    }

    /**
     * Returns X maxima of a bounding box 2d or 3d or a geometry.
     *
     * @param expr
     * @return
     */
    public static NumberExpression xmax(GeometryExpression expr) {
        return NumberOperation.create(Double.class, SpatialOps.XMAX, expr);
    }

    /**
     * Returns Y minima of a bounding box 2d or 3d or a geometry.
     *
     * @param expr
     * @return
     */
    public static NumberExpression ymin(GeometryExpression expr) {
        return NumberOperation.create(Double.class, SpatialOps.YMIN, expr);
    }

    /**
     * Returns Y maxima of a bounding box 2d or 3d or a geometry.
     *
     * @param expr
     * @return
     */
    public static NumberExpression ymax(GeometryExpression expr) {
        return NumberOperation.create(Double.class, SpatialOps.YMAX, expr);
    }

    /**
     * Returns true if the geometries are within the specified distance of one another.
     * For geometry units are in those of spatial reference and For geography units are in meters.
     *
     * @param expr1
     * @param expr2
     * @param distance
     * @return
     */
    public static BooleanExpression dwithin(Expression expr1,
                                            Expression expr2, Expression distance) {
        return BooleanOperation.create(SpatialOps.DWITHIN, expr1, expr2, distance);
    }

    /**
     * Returns true if the geometries are within the specified distance of one another.
     * For geometry units are in those of spatial reference and For geography units are in meters.
     *
     * @param expr1
     * @param expr2
     * @param distance
     * @return
     */
    public static BooleanExpression dwithin(Expression expr1,
                                            Expression expr2, double distance) {
        return BooleanOperation.create(SpatialOps.DWITHIN, expr1, expr2, ConstantImpl.create(distance));
    }

    /**
     *  Returns the bounding box that bounds rows of geometries.
     *
     * @param collection
     * @return
     */
    public static GeometryExpression extent(Expression collection) {
        return GeometryOperation.create(Geometry.class, SpatialOps.EXTENT, collection);
    }

    /**
     * Return a specified ST_Geometry value from a collection of other geometries.
     *
     * @param collection
     * @return
     */
    public static GeometryExpression collect(Expression collection) {
        return GeometryOperation.create(Geometry.class, SpatialOps.COLLECT, collection);
    }

    /**
     * Return a specified ST_Geometry value from a collection of other geometries.
     *
     * @param expr1
     * @param expr2
     * @return
     */
    public static GeometryExpression collect(Expression expr1, Expression expr2) {
        return GeometryOperation.create(Geometry.class, SpatialOps.COLLECT2, expr1, expr2);
    }

    /**
     * Translates the geometry to a new location using the numeric parameters as offsets.
     *
     * @param expr
     * @param deltax
     * @param deltay
     * @param 
     * @return
     */
    public static  GeometryExpression translate(Expression expr, float deltax, float deltay) {
        return (GeometryExpression)GeometryOperation.create(expr.getType(), SpatialOps.TRANSLATE,
                expr, ConstantImpl.create(deltax), ConstantImpl.create(deltay));
    }

    /**
     * Translates the geometry to a new location using the numeric parameters as offsets.
     *
     * @param expr
     * @param deltax
     * @param deltay
     * @param deltaz
     * @param 
     * @return
     */
    public static  GeometryExpression translate(Expression expr, float deltax, float deltay, float deltaz) {
        return (GeometryExpression)GeometryOperation.create(expr.getType(), SpatialOps.TRANSLATE2,
                expr, ConstantImpl.create(deltax), ConstantImpl.create(deltay), ConstantImpl.create(deltaz));
    }

    private GeometryExpressions() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy