当前位置: 首页>>代码示例>>Java>>正文


Java CQL.toFilter方法代码示例

本文整理汇总了Java中org.geotools.filter.text.cql2.CQL.toFilter方法的典型用法代码示例。如果您正苦于以下问题:Java CQL.toFilter方法的具体用法?Java CQL.toFilter怎么用?Java CQL.toFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.geotools.filter.text.cql2.CQL的用法示例。


在下文中一共展示了CQL.toFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFilter

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
static Filter createFilter(String geomField, double x0, double y0, double x1, double y1,
                           String dateField, String t0, String t1,
                           String attributesQuery)
        throws CQLException, IOException {

    // there are many different geometric predicates that might be used;
    // here, we just use a bounding-box (BBOX) predicate as an example.
    // this is useful for a rectangular query area
    String cqlGeometry = "BBOX(" + geomField + ", " +
            x0 + ", " + y0 + ", " + x1 + ", " + y1 + ")";

    // there are also quite a few temporal predicates; here, we use a
    // "DURING" predicate, because we have a fixed range of times that
    // we want to query
    String cqlDates = "(" + dateField + " DURING " + t0 + "/" + t1 + ")";

    // there are quite a few predicates that can operate on other attribute
    // types; the GeoTools Filter constant "INCLUDE" is a default that means
    // to accept everything
    String cqlAttributes = attributesQuery == null ? "INCLUDE" : attributesQuery;

    String cql = cqlGeometry + " AND " + cqlDates  + " AND " + cqlAttributes;
    return CQL.toFilter(cql);
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:25,代码来源:FeatureLevelVisibility.java

示例2: setup

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@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"
			});
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:22,代码来源:WFSSpatialTest.java

示例3: beforePredicate

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
private static void beforePredicate() throws Exception{
   	
   	// cql_beforePredicate start
       Before filter = (Before) CQL.toFilter("lastEarthQuake BEFORE 2006-11-30T01:30:00Z");
   	// cql_beforePredicate end
       Utility.prittyPrintFilter(filter);
       
       final SimpleFeature city = DataExamples.getInstanceOfCity();
       Expression leftExpr = filter.getExpression1();
       Expression rightExpr = filter.getExpression2();
       System.out.println("left expression value: " + leftExpr.evaluate(city));
       System.out.println("right expression value: " + rightExpr.evaluate(city));
       
       Boolean result = filter.evaluate(city);
       System.out.println("Result of filter evaluation: " + result);        
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:17,代码来源:CQLExamples.java

示例4: afterPredicateGMT3

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
private static void afterPredicateGMT3() throws Exception{
   	
   	// cql_afterPredicateGMT3 start
       After filter = (After) CQL.toFilter("lastEarthQuake AFTER 2006-11-30T01:30:00+03:00");
   	// cql_afterPredicateGMT3 end
       Utility.prittyPrintFilter(filter);
       
       final SimpleFeature city = DataExamples.getInstanceOfCity();
       Expression leftExpr = filter.getExpression1();
       Expression rightExpr = filter.getExpression2();
       System.out.println("left expression value: " + leftExpr.evaluate(city));
       System.out.println("right expression value: " + rightExpr.evaluate(city));
       
       Boolean result = filter.evaluate(city);
       System.out.println("Result of filter evaluation: " + result);        
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:17,代码来源:CQLExamples.java

示例5: comparisonPredicateCQLCompatibility

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
/**
 * This example shows that ECQL syntax is compatible with CQL.
 * 
 * @throws Exception
 */
static private void comparisonPredicateCQLCompatibility() throws Exception {

    // comparisonCQLCompatibility start
    Filter filter = ECQL.toFilter("POPULTATION >= 1000");
    // comparisonCQLCompatibility end

    // the same syntax, now using CQL parser will produce the same filter
    Filter filterFromCQL = CQL.toFilter("POPULTATION >= 1000");

    if (!filter.equals(filterFromCQL)) {
        throw new Exception("uncompatible ECQL Syntax");
    } else {
        System.out.println("CQL and ECQL have produced the same filter for the predicate \"POPULTATION >= 1000\"");
        Utility.prittyPrintFilter( filter );
    }
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:22,代码来源:ECQLExamples.java

示例6: testAllAttributes

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@Test
public void testAllAttributes()
		throws CQLException,
		IOException {
	final Query query = new Query(
			typeName,
			CQL.toFilter(cqlPredicate),
			Query.ALL_PROPERTIES);
	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);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:22,代码来源:GeoToolsAttributesSubsetTest.java

示例7: parseFilter

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
/** @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);
		}
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:23,代码来源:FilterServiceImpl.java

示例8: toFilter

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@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");
	}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:18,代码来源:CqlTest.java

示例9: secondaryIndexExample

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
static void secondaryIndexExample(String simpleFeatureTypeName,
                                  DataStore dataStore,
                                  String[] attributeFields,
                                  String attributesQuery,
                                  int maxFeatures,
                                  String sortByField)
        throws CQLException, IOException {

    // construct a (E)CQL filter from the search parameters,
    // and use that as the basis for the query
    Filter cqlFilter = CQL.toFilter(attributesQuery);
    Query query = new Query(simpleFeatureTypeName, cqlFilter);

    query.setPropertyNames(attributeFields);
    query.setMaxFeatures(maxFeatures);

    if (!sortByField.equals("")) {
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        SortBy[] sort = new SortBy[]{ff.sort(sortByField, SortOrder.DESCENDING)};
        query.setSortBy(sort);
    }

    // submit the query, and get back an iterator over matching features
    FeatureSource featureSource = dataStore.getFeatureSource(simpleFeatureTypeName);
    FeatureIterator featureItr = featureSource.getFeatures(query).features();

    // loop through all results
    int n = 0;
    while (featureItr.hasNext()) {
        Feature feature = featureItr.next();
        StringBuilder sb = new StringBuilder();
        sb.append("Feature ID ").append(feature.getIdentifier());

        for (String field : attributeFields) {
            sb.append(" | ").append(field).append(": ").append(feature.getProperty(field).getValue());
        }
        System.out.println(sb.toString());
    }
    featureItr.close();
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:41,代码来源:FeatureLevelVisibility.java

示例10: secondaryIndexExample

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
static void secondaryIndexExample(String simpleFeatureTypeName,
                                  DataStore dataStore,
                                  String[] attributeFields,
                                  String attributesQuery,
                                  int maxFeatures,
                                  String sortByField)
        throws CQLException, IOException {

    // construct a (E)CQL filter from the search parameters,
    // and use that as the basis for the query
    Filter cqlFilter = CQL.toFilter(attributesQuery);
    Query query = new Query(simpleFeatureTypeName, cqlFilter);

    query.setPropertyNames(attributeFields);
    query.setMaxFeatures(maxFeatures);

    if (!sortByField.equals("")) {
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        SortBy[] sort = new SortBy[]{ff.sort(sortByField, SortOrder.DESCENDING)};
        query.setSortBy(sort);
    }

    // submit the query, and get back an iterator over matching features
    FeatureSource featureSource = dataStore.getFeatureSource(simpleFeatureTypeName);
    FeatureIterator featureItr = featureSource.getFeatures(query).features();

    // loop through all results
    while (featureItr.hasNext()) {
        Feature feature = featureItr.next();
        StringBuilder sb = new StringBuilder();
        sb.append("Feature ID ").append(feature.getIdentifier());

        for (String field : attributeFields) {
            sb.append(" | ").append(field).append(": ").append(feature.getProperty(field).getValue());
        }
        System.out.println(sb.toString());
    }
    featureItr.close();
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:40,代码来源:AccumuloQuickStart.java

示例11: testWithin

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@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);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:30,代码来源:ExtractGeometryFilterVisitorTest.java

示例12: testPartial

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
public void testPartial(
		Populater populater,
		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",
				"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));

}
 
开发者ID:locationtech,项目名称:geowave,代码行数:41,代码来源:GeoWaveFeatureSourceTest.java

示例13: testTemporal

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@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",
				"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);

}
 
开发者ID:locationtech,项目名称:geowave,代码行数:33,代码来源:WFSTemporalQueryTest.java

示例14: testCrosses

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@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);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:30,代码来源:ExtractGeometryFilterVisitorTest.java

示例15: testEquals

import org.geotools.filter.text.cql2.CQL; //导入方法依赖的package包/类
@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);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:30,代码来源:ExtractGeometryFilterVisitorTest.java


注:本文中的org.geotools.filter.text.cql2.CQL.toFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。