Package org.geotools.filter.text.cql2

Source Code of org.geotools.filter.text.cql2.CQLGeoOperationTest

/*
*    GeoTools - The Open Source Java GIS Toolkit
*    http://geotools.org
*
*    (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
*
*    This library is free software; you can redistribute it and/or
*    modify it under the terms of the GNU Lesser General Public
*    License as published by the Free Software Foundation;
*    version 2.1 of the License.
*
*    This library is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*    Lesser General Public License for more details.
*/

package org.geotools.filter.text.cql2;


import org.geotools.filter.function.FilterFunction_relatePattern;
import org.geotools.filter.text.commons.CompilerUtil;
import org.geotools.filter.text.commons.Language;
import org.junit.Assert;
import org.junit.Test;
import org.opengis.filter.Filter;
import org.opengis.filter.PropertyIsEqualTo;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.spatial.BBOX;
import org.opengis.filter.spatial.Contains;
import org.opengis.filter.spatial.Crosses;
import org.opengis.filter.spatial.Disjoint;
import org.opengis.filter.spatial.Equals;
import org.opengis.filter.spatial.Intersects;
import org.opengis.filter.spatial.Overlaps;
import org.opengis.filter.spatial.Touches;
import org.opengis.filter.spatial.Within;


/**
* Test Geo Operations.
* <p>
*
* <pre>
*   &lt;routine invocation &gt; ::=
*           &lt;geoop name &gt; &lt;georoutine argument list &gt;[*]
*       |   &lt;relgeoop name &gt; &lt;relgeoop argument list &gt;
*       |   &lt;routine name &gt; &lt;argument list &gt;
*       |   &lt;relate geoop &gt;
*   &lt;geoop name &gt; ::=
*           EQUALS | DISJOINT | INTERSECTS | TOUCHES | CROSSES | [*]
*           WITHIN | CONTAINS |OVERLAPS
*  
*   &lt;relate geoop &gt; ::=  &lt;RELATE>&gt; &quot;(&quot; Attribute()&quot;,&quot; &lt;geometry literal&gt; &quot;,&quot; &lt;DE9IM_PATTERN&gt; &quot;)&quot;
*   &lt;DE9IM_PATTERN&gt; ::= &lt;DE9IM_CHAR&gt;&lt;DE9IM_CHAR&gt;&lt;DE9IM_CHAR&gt; ...
*   &lt;DE9IM_CHAR&gt; ::= *| T | F | 0 | 1 | 2
*  
*   That rule is extended with bbox for convenience.
*   &lt;bbox argument list &gt;::=
*       &quot;(&quot;  &lt;attribute &gt; &quot;,&quot; &lt;min X &gt; &quot;,&quot; &lt;min Y &gt; &quot;,&quot; &lt;max X &gt; &quot;,&quot; &lt;max Y &gt;[&quot;,&quot;  &lt;srs &gt;] &quot;)&quot;
*       &lt;min X &gt; ::=  &lt;signed numerical literal &gt;
*       &lt;min Y &gt; ::=  &lt;signed numerical literal &gt;
*       &lt;max X &gt; ::=  &lt;signed numerical literal &gt;
*       &lt;max Y &gt; ::=  &lt;signed numerical literal &gt;
*       &lt;srs &gt; ::=
* </pre>
*
* </p>
*
* @author Mauricio Pazos (Axios Engineering)
* @since 2.6
*
*
*
* @source $URL$
*/

public class CQLGeoOperationTest {

   
    protected final Language language;

    /**
     * New instance of CQLTemporalPredicateTest
     */
    public CQLGeoOperationTest(){
       
        this(Language.CQL);

    }

    /**
     * New instance of CQLTemporalPredicateTest
     * @param language
     */
    protected CQLGeoOperationTest(final Language language){
       
        assert language != null: "language cannot be null value";
       
        this.language = language;
    }
       

    @Test
    public void disjoint() throws CQLException{
       

        Filter resultFilter = CompilerUtil.parseFilter(language, "DISJOINT(ATTR1, POINT(1 2))");

        Assert.assertTrue("Disjoint was expected", resultFilter instanceof Disjoint);
    }

    /**
     * Intersects geooperation
     *
     * @see intersects
     * @throws CQLException
     */
    @Test
    public void Intersects() throws CQLException {
       
        Filter resultFilter;
       
        resultFilter = CompilerUtil.parseFilter(language,"INTERSECTS(ATTR1, POINT(1 2))");

        Assert.assertTrue("Intersects was expected", resultFilter instanceof Intersects);
       
        //test bug GEOT-1980
        resultFilter= CompilerUtil.parseFilter(language,"INTERSECTS(GEOLOC, POINT(615358 312185))");
       
        Assert.assertTrue("Intersects was expected", resultFilter instanceof Intersects);

    }
   
    /**
     *
     * @throws CQLException
     */
    @Test
    public void relate() throws CQLException {
       
        PropertyIsEqualTo resultFilter;
       
        resultFilter = (PropertyIsEqualTo) CompilerUtil.parseFilter(language,"RELATE(the_geom, LINESTRING (-134.921387 58.687767, -135.303391 59.092838), T*****FF*)");

        Expression relateFunction = resultFilter.getExpression1();
        Assert.assertTrue(relateFunction instanceof FilterFunction_relatePattern);
       
        Literal trueLiteral = (Literal) resultFilter.getExpression2();
        Assert.assertTrue(trueLiteral.getValue() instanceof Boolean);
    }

    @Test
    public void relatePatterns() throws CQLException {
       
        testRelatePatten("T******F*");

        testRelatePatten("T012**FF*");
           
        testRelatePatten("100000001");

        testRelatePatten("200000000");
    }
   
    private void testRelatePatten(final String pattern) throws CQLException {
       
        PropertyIsEqualTo resultFilter;
       
        resultFilter = (PropertyIsEqualTo) CompilerUtil.parseFilter(language,"RELATE(the_geom, LINESTRING (-134.921387 58.687767, -135.303391 59.092838), "+pattern+")");

        Expression relateFunction = resultFilter.getExpression1();
        Assert.assertTrue(relateFunction instanceof FilterFunction_relatePattern);
       
        Literal trueLiteral = (Literal) resultFilter.getExpression2();
        Assert.assertTrue(trueLiteral.getValue() instanceof Boolean);
    }

   
   
    /**
     * The length of relate pattern must be 9 (nine) dimension characters
     * @throws CQLException
     */
    @Test(expected=CQLException.class)
    public void relateBadLongitudInPattern() throws CQLException {
        CQL.toFilter( "RELATE(geometry, LINESTRING (-134.921387 58.687767, -135.303391 59.092838), **1******T)");
    }
   
    /**
     * The illegal dimension character in relate pattern
     * @throws CQLException
     */
    @Test(expected=CQLException.class)
    public void relateIlegalPattern() throws CQLException {
        CQL.toFilter( "RELATE(geometry, LINESTRING (-134.921387 58.687767, -135.303391 59.092838), **1*****X)");
    }

    /**
     * Invalid Geooperation Test
     * @throws CQLException
     */
    @Test(expected = CQLException.class
    public void invalidGeoOperation() throws CQLException{
        CompilerUtil.parseFilter(this.language,"INTERSECT(ATTR1, POINT(1 2))"); // should be "intersects"
    }
   
    @Test
    public void invalidSyntaxMessage() throws CQLException{
        try{
          CompilerUtil.parseFilter(this.language,"INTERSECT(ATTR1, POINT(1 2))"); // should be "intersects"
          Assert.fail("CQLException is expected");
        } catch (CQLException e){
          final String error = e.getSyntaxError() ;
          Assert.assertNotNull(error);
          Assert.assertFalse("".equals(error));
        }
       
       
    }
   
   
    /**
     * TOUCHES geooperation
     *
     * @throws CQLException
     */
    @Test
    public void touches() throws CQLException{

        Filter resultFilter;
       
        // TOUCHES
        resultFilter = CompilerUtil.parseFilter(language,"TOUCHES(ATTR1, POINT(1 2))");

        Assert.assertTrue("Touches was expected", resultFilter instanceof Touches);

    }

    /**
     * CROSSES geooperation operation
     *
     * @throws CQLException
     */
    @Test
    public void crosses() throws CQLException {

        Filter resultFilter;
       
        resultFilter = CompilerUtil.parseFilter(language,"CROSSES(ATTR1, POINT(1 2))");

        Assert.assertTrue("Crosses was expected", resultFilter instanceof Crosses);

       
    }
    @Test
    public void contains() throws CQLException      {
        Filter resultFilter = CompilerUtil.parseFilter(language,"CONTAINS(ATTR1, POINT(1 2))");

        Assert.assertTrue("Contains was expected", resultFilter instanceof Contains);
       
    }
   
    /**
     * OVERLAPS geooperation operation test
     *
     * @throws CQLException
     */
    @Test
    public void overlaps() throws Exception {
        Filter resultFilter;

        resultFilter = CompilerUtil.parseFilter(language,"OVERLAPS(ATTR1, POINT(1 2))");

        Assert.assertTrue("Overlaps was expected", resultFilter instanceof Overlaps);

    }
   
    /**
     * EQULS geooperation operation test
     *
     * @throws CQLException
     */
    @Test
    public void equals() throws CQLException{
        Filter resultFilter;
       
        // EQUALS
        resultFilter = CompilerUtil.parseFilter(language,"EQUALS(ATTR1, POINT(1 2))");

        Assert.assertTrue("not an instance of Equals", resultFilter instanceof Equals);

    }
   
    /**
     * WITHIN test
     *
     * @throws CQLException
     */
    @Test
    public void within() throws CQLException{
       
        Filter resultFilter = CompilerUtil.parseFilter(language,"WITHIN(ATTR1, POLYGON((1 2, 1 10, 5 10, 1 2)) )");

        Assert.assertTrue("Within was expected", resultFilter instanceof Within);
    }

    /**
     * BBOX test
     * @throws CQLException
     */
    @Test
    public void bbox() throws CQLException{
       
        Filter resultFilter;
       
        // BBOX
        resultFilter = CompilerUtil.parseFilter(language,"BBOX(ATTR1, 10.0,20.0,30.0,40.0)");
        Assert.assertTrue("BBox was expected", resultFilter instanceof BBOX);
        BBOX bboxFilter = (BBOX) resultFilter;
        Assert.assertEquals(bboxFilter.getMinX(), 10.0, 0.1);
        Assert.assertEquals(bboxFilter.getMinY(), 20.0, 0.1);
        Assert.assertEquals(bboxFilter.getMaxX(), 30.0, 0.1);
        Assert.assertEquals(bboxFilter.getMaxY(), 40.0, 0.1);
        Assert.assertEquals(null, bboxFilter.getSRS());

        // BBOX using EPSG
        resultFilter = CompilerUtil.parseFilter(language,"BBOX(ATTR1, 10.0,20.0,30.0,40.0, 'EPSG:4326')");
        Assert.assertTrue("BBox was expected", resultFilter instanceof BBOX);
        bboxFilter = (BBOX) resultFilter;
        Assert.assertEquals("EPSG:4326", bboxFilter.getSRS());
       
    }
   
}
TOP

Related Classes of org.geotools.filter.text.cql2.CQLGeoOperationTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.