org.geotools.filter.text.cql2.CQL Java Examples

The following examples show how to use org.geotools.filter.text.cql2.CQL. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntesectAndCrossesAndLike()
    throws CQLException, TransformException, ParseException {

  // we are testing to see if we are able to combine dissimilar geometric
  // relations correctly
  // to extract query geometry. Note, that returned predicate is null
  // since we can't represent
  // CQL expression fully into single query geometry and predicate
  final Filter filter =
      CQL.toFilter(
          String.format(
              "CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0))) AND location == 'abc'",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == null);
}
 
Example #2
Source File: CqlTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
	public void toFilter() {
		Filter f;
		try {
			f = CQL.toFilter("a.b < 5");
		} catch (CQLException e) {
			f = null;
		}
		Assert.notNull(f, "Filter should not be null");

//		try {
//	        f = CQL.toFilter("bookstore[1].book < 5");
//        } catch (CQLException e) {
//        	f = null;
//        }
//		Assert.notNull(f, "Filter should not be null");
	}
 
Example #3
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/** @inheritDoc */
public Filter parseFilter(String filter) throws GeomajasException {
	if (null == filter || filter.length() == 0) {
		return createTrueFilter();
	}
	try {
		if (idReplacer.shouldParse(filter)) {
			return idReplacer.parse(filter);
		} else {
			return ECQL.toFilter(filter, FF);
		}
	} catch (CQLException e) {
		// ECQL should be a superset of CQL, but there are apparently extra key words like "id"
		// fall back to CQL for backwards compatibility
		log.warn("Filter not parsable by ECQL, falling back to CQL", e);
		try {
			return CQL.toFilter(filter, FF);
		} catch (CQLException ce) {
			throw new GeomajasException(ce, ExceptionCode.FILTER_PARSE_PROBLEM, filter);
		}
	}
}
 
Example #4
Source File: WFSTemporalQueryTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testTemporal() throws CQLException, IOException, ParseException {

  populate();
  final Transaction transaction2 = new DefaultTransaction();
  final Query query =
      new Query(
          "geostuff",
          CQL.toFilter(
              "BBOX(geometry,44,27,42,30) and start during 2005-05-16T20:32:56Z/2005-05-20T21:32:56Z and end during 2005-05-18T20:32:56Z/2005-05-22T21:32:56Z"),
          new String[] {"geometry", "start", "end", "pid"});
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      dataStore.getFeatureReader(query, transaction2);
  int c = 0;
  while (reader.hasNext()) {
    reader.next();
    c++;
  }
  reader.close();
  transaction2.commit();
  transaction2.close();
  assertEquals(2, c);
}
 
Example #5
Source File: GeoToolsAttributesSubsetTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubsetAttributes() throws CQLException, IOException {
  final Query query =
      new Query(
          typeName,
          CQL.toFilter(cqlPredicate),
          new String[] {geometry_attribute, string_attribute});
  final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
      geotoolsDataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
  int count = 0;
  while (reader.hasNext()) {
    final SimpleFeature feature = reader.next();
    count++;
    Assert.assertTrue(feature.getAttribute(geometry_attribute) != null);
    Assert.assertTrue(feature.getAttribute(long_attribute) == null);
    Assert.assertTrue(feature.getAttribute(string_attribute) != null);
  }
  Assert.assertTrue(count == 3);
}
 
Example #6
Source File: GeoWaveFeatureSourceTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
public void testPartial(final Populater populater, final String ext)
    throws CQLException, Exception {
  final String typeName = "GeoWaveFeatureSourceTest_p" + ext;
  final SimpleFeatureType type =
      DataUtilities.createType(
          typeName,
          "geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date");
  final DataStore dataStore = createDataStore();
  populater.populate(type, dataStore);
  final SimpleFeatureSource source = dataStore.getFeatureSource(typeName);

  final Query query =
      new Query(
          typeName,
          CQL.toFilter(
              "BBOX(geometry,42,28,44,30) and when during 2005-05-01T20:32:56Z/2005-05-29T21:32:56Z"),
          new String[] {"geometry", "when", "pid"});
  final ReferencedEnvelope env = source.getBounds(query);
  assertEquals(43.454, env.getMaxX(), 0.0001);
  assertEquals(28.232, env.getMinY(), 0.0001);
  assertEquals(28.242, env.getMaxY(), 0.0001);
  assertEquals(2, source.getCount(query));
}
 
Example #7
Source File: WFSSpatialTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws SchemaException, CQLException, IOException, GeoWavePluginException {
  dataStore = createDataStore();
  type =
      DataUtilities.createType(
          "geostuff",
          "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String");

  dataStore.createSchema(type);
  query =
      new Query(
          "geostuff",
          CQL.toFilter(
              "BBOX(geometry,27.20,41.30,27.30,41.20) and when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"),
          new String[] {"geometry", "pid"});
}
 
Example #8
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotBetween() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Date sTime2 = new Date(DateUtilities.parseISO("2005-05-19T20:32:56Z").getTime() + 1);
  final Date eTime1 = new Date(DateUtilities.parseISO("2005-05-17T20:32:56Z").getTime() - 1);
  final Filter filter =
      CQL.toFilter("not (when before 2005-05-17T20:32:56Z or when after 2005-05-19T20:32:56Z)");
  final Query query = new Query("type", filter);
  final TemporalConstraintsSet rangeSet =
      (TemporalConstraintsSet) query.getFilter().accept(visitor, null);
  assertNotNull(rangeSet);
  assertEquals(eTime1, rangeSet.getConstraintsFor("when").getStartRange().getStartTime());
  assertEquals(
      new Date(sTime2.getTime() - 1),
      rangeSet.getConstraintsFor("when").getStartRange().getEndTime());
}
 
Example #9
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuringOrAfter() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Date stime = new Date(DateUtilities.parseISO("2005-05-19T20:32:56Z").getTime() + 1);
  final Filter filter =
      CQL.toFilter("when DURING OR AFTER 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z");
  final Query query = new Query("type", filter);
  TemporalConstraintsSet rangeSet =
      (TemporalConstraintsSet) query.getFilter().accept(visitor, null);
  assertNotNull(rangeSet);
  assertEquals(stime, rangeSet.getConstraintsFor("when").getStartRange().getStartTime());
  assertEquals(
      TemporalRange.END_TIME,
      rangeSet.getConstraintsFor("when").getEndRange().getEndTime());

  rangeSet = (TemporalConstraintsSet) query.getFilter().accept(visitorWithDescriptor, null);
  assertNotNull(rangeSet);
  assertEquals(stime, rangeSet.getConstraintsFor("when").getStartRange().getStartTime());
  assertEquals(
      TemporalRange.END_TIME,
      rangeSet.getConstraintsFor("when").getEndRange().getEndTime());
}
 
Example #10
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testBeforeOrDuring() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Date stime = new Date(DateUtilities.parseISO("2005-05-19T21:32:56Z").getTime() - 1);
  final Filter filter =
      CQL.toFilter("when BEFORE OR DURING 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z");
  final Query query = new Query("type", filter);
  TemporalConstraintsSet rangeSet =
      (TemporalConstraintsSet) query.getFilter().accept(visitor, null);
  assertNotNull(rangeSet);
  assertEquals(
      TemporalRange.START_TIME,
      rangeSet.getConstraintsFor("when").getStartRange().getStartTime());
  assertEquals(stime, rangeSet.getConstraintsFor("when").getEndRange().getEndTime());

  rangeSet = (TemporalConstraintsSet) query.getFilter().accept(visitorWithDescriptor, null);
  assertNotNull(rangeSet);
  assertEquals(
      TemporalRange.START_TIME,
      rangeSet.getConstraintsFor("when").getStartRange().getStartTime());
  assertEquals(stime, rangeSet.getConstraintsFor("when").getEndRange().getEndTime());
}
 
Example #11
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testBefore() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Date etime = new Date(DateUtilities.parseISO("2005-05-19T20:32:56Z").getTime() - 1);
  final Filter filter = CQL.toFilter("when before 2005-05-19T20:32:56Z");
  final Query query = new Query("type", filter);
  TemporalConstraints range = (TemporalConstraints) query.getFilter().accept(visitor, null);
  assertNotNull(range);
  assertEquals(TemporalRange.START_TIME, range.getStartRange().getStartTime());
  assertEquals(etime, range.getStartRange().getEndTime());

  range = (TemporalConstraints) query.getFilter().accept(visitorWithDescriptor, null);
  assertNotNull(range);
  assertEquals(TemporalRange.START_TIME, range.getStartRange().getStartTime());
  assertEquals(etime, range.getStartRange().getEndTime());
}
 
Example #12
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuring() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Date stime = new Date(DateUtilities.parseISO("2005-05-19T20:32:56Z").getTime() + 1);
  final Date etime = new Date(DateUtilities.parseISO("2005-05-19T21:32:56Z").getTime() - 1);
  final Filter filter = CQL.toFilter("when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z");
  final Query query = new Query("type", filter);
  TemporalConstraints range = (TemporalConstraints) query.getFilter().accept(visitor, null);
  assertNotNull(range);
  assertEquals(stime, range.getStartRange().getStartTime());
  assertEquals(etime, range.getStartRange().getEndTime());

  range = (TemporalConstraints) query.getFilter().accept(visitor, null);
  assertNotNull(range);
  assertEquals(stime, range.getStartRange().getStartTime());
  assertEquals(etime, range.getStartRange().getEndTime());
}
 
Example #13
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithMultipleAttributes() throws CQLException, TransformException, ParseException {

  // In this test query, we have constrains over multiple geometric
  // attributes.
  // The ExtractGeometryFilterVisitor class should only extracts
  // geometric constrains associated with the specified attribute name and
  // ignore others.
  final Filter filter =
      CQL.toFilter(
          String.format(
              "INTERSECTS(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0))) AND INTERSECTS(geomOtherAttr, POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == null);
}
 
Example #14
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntesectAndBBox() throws CQLException, TransformException, ParseException {

  // BBOX geometry is completely contained within Intersects geometry
  // we are testing to see if we are able to combine simple geometric
  // relations with similar predicates
  // into a single query geometry/predicate
  final Filter filter =
      CQL.toFilter(
          String.format(
              "INTERSECTS(%s, POLYGON((0 0, 0 50, 20 50, 20 0, 0 0))) AND BBOX(%s, 0, 0, 10, 25)",
              geomAttributeName,
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.INTERSECTS);
}
 
Example #15
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisjoint() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "DISJOINT(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
  // for non-inclusive filters we can't extract query geometry and
  // predicate
  // assertTrue(Double.isNaN(result.getGeometry().getArea()));
  assertTrue(result.getCompareOp() == null);
}
 
Example #16
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithin() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format("WITHIN(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.CONTAINS);
}
 
Example #17
Source File: OmsVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private List<Expression> createExpressionList( String expressionString ) {
    List<Expression> list = new ArrayList<Expression>();

    String definition = expressionString.replaceAll("\r", "\n").replaceAll("[\n\r][\n\r]", "\n");
    for( String line : definition.split("\n") ) {
        int mark = line.indexOf("=");
        if (mark != -1) {
            String expressionDefinition = line.substring(mark + 1).trim();

            Expression expression;
            try {
                expression = CQL.toExpression(expressionDefinition);
            } catch (CQLException e) {
                throw new ModelsRuntimeException(e.toString(), this);
            }
            list.add(expression);
        }
    }
    return list;
}
 
Example #18
Source File: FilterUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a bounding box filter from the bounds coordinates.
 * 
 * @param attribute the geometry attribute or null in the case of default "the_geom".
 * @param west western bound coordinate.
 * @param east eastern bound coordinate.
 * @param south southern bound coordinate.
 * @param north northern bound coordinate.
 * @return the filter.
 * @throws CQLException
 */
public static Filter getBboxFilter( String attribute, double west, double east, double south, double north )
        throws CQLException {

    if (attribute == null) {
        attribute = "the_geom";
    }

    StringBuilder sB = new StringBuilder();
    sB.append("BBOX(");
    sB.append(attribute);
    sB.append(",");
    sB.append(west);
    sB.append(",");
    sB.append(south);
    sB.append(",");
    sB.append(east);
    sB.append(",");
    sB.append(north);
    sB.append(")");

    Filter bboxFilter = CQL.toFilter(sB.toString());

    return bboxFilter;
}
 
Example #19
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testDWithin() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "DWITHIN(%s, POINT(-122.7668 0.4979), 233.7, meters)",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
  final Geometry geometry = result.getGeometry();
  assertNotNull(geometry);
  for (final Coordinate coord : geometry.getCoordinates()) {

    assertEquals(
        233.7,
        JTS.orthodromicDistance(
            coord,
            new Coordinate(-122.7668, 0.4979),
            GeometryUtils.getDefaultCRS()),
        2);
  }
}
 
Example #20
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testDWithinDateLine() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "DWITHIN(%s, POINT(179.9998 0.79), 13.7, kilometers)",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
  final Geometry geometry = result.getGeometry();
  assertNotNull(geometry);
  for (final Coordinate coord : geometry.getCoordinates()) {

    assertEquals(
        13707.1,
        JTS.orthodromicDistance(
            coord,
            new Coordinate(179.9999, 0.79),
            GeometryUtils.getDefaultCRS()),
        2000);
  }
}
 
Example #21
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntersects() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "INTERSECTS(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.INTERSECTS);
}
 
Example #22
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testOverlaps() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "OVERLAPS(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.OVERLAPS);
}
 
Example #23
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "EQUALS(geom, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.EQUALS);
}
 
Example #24
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testCrosses() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.CROSSES);
}
 
Example #25
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testContains() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "CONTAINS(geom, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.WITHIN);
}
 
Example #26
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testTouches() throws CQLException, TransformException, ParseException {

  final Filter filter =
      CQL.toFilter(
          String.format(
              "TOUCHES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.TOUCHES);
}
 
Example #27
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testBBOX() throws CQLException, TransformException, ParseException {

  final Filter filter = CQL.toFilter(String.format("BBOX(%s, 0, 0, 10, 25)", geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == CompareOperation.INTERSECTS);
}
 
Example #28
Source File: ExtractTimeFilterVisitorTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testAndNoOverlap() throws CQLException, ParseException {
  final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
  final Filter filter =
      CQL.toFilter("when before 2005-05-17T20:32:56Z and when after 2005-05-19T20:32:56Z");
  final Query query = new Query("type", filter);
  final TemporalConstraintsSet rangeSet =
      (TemporalConstraintsSet) query.getFilter().accept(visitor, null);
  assertNotNull(rangeSet);
  assertTrue(rangeSet.isEmpty());
}
 
Example #29
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverlapsOrCrosses() throws CQLException, TransformException, ParseException {

  // TOUCHES geometry is completely contained within OVERLAPS geometry
  // we are testing to see if we are able to combine dissimilar geometric
  // relations correctly
  // to extract query geometry. Note, we can't combine two different
  // predicates into one but
  // we can combine geometries for the purpose of deriving linear
  // constraints
  final Filter filter =
      CQL.toFilter(
          String.format(
              "OVERLAPS(%s, POLYGON((0 0, 0 50, 20 50, 20 0, 0 0))) OR TOUCHES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName,
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 20, 0, 50);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == null);
}
 
Example #30
Source File: ExtractGeometryFilterVisitorTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntesectAndCrosses() throws CQLException, TransformException, ParseException {

  // CROSSES geometry is completely contained within INTERSECT geometry
  // we are testing to see if we are able to combine dissimilar geometric
  // relations correctly
  // to extract query geometry. Note, we can't combine two different
  // predicates into one but
  // we can combine geometries for the purpose of deriving linear
  // constraints
  final Filter filter =
      CQL.toFilter(
          String.format(
              "INTERSECTS(%s, POLYGON((0 0, 0 50, 20 50, 20 0, 0 0))) AND CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))",
              geomAttributeName,
              geomAttributeName));
  final Query query = new Query("type", filter);

  final ExtractGeometryFilterVisitorResult result =
      (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);

  final Envelope bounds = new Envelope(0, 10, 0, 25);
  final Geometry bbox = new GeometryFactory().toGeometry(bounds);

  assertTrue(bbox.equalsTopo(result.getGeometry()));
  assertTrue(result.getCompareOp() == null);
}