本文整理汇总了Java中org.geotools.filter.text.ecql.ECQL.toFilter方法的典型用法代码示例。如果您正苦于以下问题:Java ECQL.toFilter方法的具体用法?Java ECQL.toFilter怎么用?Java ECQL.toFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.filter.text.ecql.ECQL
的用法示例。
在下文中一共展示了ECQL.toFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFidFilterQuery
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testFidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
final String fidsString = fids.stream().collect(Collectors.joining("','", "'", "'"));
final Filter filter = ECQL.toFilter("IN (" + fidsString + ")");
final Query query = new Query(
"GeoWaveFeatureReaderTest",
filter,
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertTrue(count == fids.size());
}
示例2: testPidFilterQuery
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testPidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
// Filter it so that it only queries for everything but the first pid.
// There's only 2 pids total so it should just return the second one.
final String pidsString = pids.subList(1, pids.size()).stream().collect(Collectors.joining("','", "'", "'"));
final Filter filter = ECQL.toFilter("pid IN (" + pidsString + ")");
final Query query = new Query(
"GeoWaveFeatureReaderTest",
filter,
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertTrue(count == pids.size() - 1);
}
示例3: testLike
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testLike() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
final Query query = new Query(
"GeoWaveFeatureReaderTest",
ECQL.toFilter("pid like '" + pids.get(
0).substring(
0,
1) + "%'"),
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertEquals(1, count);
}
示例4: executeCQLQueryTest
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void executeCQLQueryTest() throws IOException, CQLException {
System.out.println("Executing query, expecting to match two points...");
final Filter cqlFilter = ECQL.toFilter("BBOX(geometry,-77.6167,38.6833,-76.6,38.9200) and locationName like 'W%'");
final QueryOptions queryOptions = new QueryOptions(ADAPTER, INDEX);
final CQLQuery cqlQuery = new CQLQuery(null, cqlFilter, ADAPTER);
try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(queryOptions, cqlQuery)) {
int count = 0;
while (iterator.hasNext()) {
System.out.println("Query match: " + iterator.next().getID());
count++;
}
System.out.println("executeCQLQueryTest count: " + count);
// Should match "Washington Monument" and "White House"
assertEquals(2, count);
}
}
示例5: testGeoShapeIntersectsFilter
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testGeoShapeIntersectsFilter() throws CQLException, IOException {
Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(\"geom\", LINESTRING(0 0,1.1 1.1))");
List<List<Double>> coords = new ArrayList<>();
coords.add(ImmutableList.of(0.,0.));
coords.add(ImmutableList.of(1.1,1.1));
Map<String,Object> expected = ImmutableMap.of("bool",
ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape",
ImmutableMap.of("geom", ImmutableMap.of("shape",
ImmutableMap.of("coordinates", coords, "type", "LineString"),
"relation", "INTERSECTS")))));
builder.visit(filter, null);
assertTrue(builder.createFilterCapabilities().fullySupports(filter));
// TODO: Why doesn't equality check on objects work here
assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
示例6: testGeoShapeIntersectsFilterReversed
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testGeoShapeIntersectsFilterReversed() throws CQLException, IOException {
Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(LINESTRING(0 0,1.1 1.1), \"geom\")");
List<List<Double>> coords = new ArrayList<>();
coords.add(ImmutableList.of(0.,0.));
coords.add(ImmutableList.of(1.1,1.1));
Map<String,Object> expected = ImmutableMap.of("bool",
ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape",
ImmutableMap.of("geom", ImmutableMap.of("shape",
ImmutableMap.of("coordinates", coords, "type", "LineString"),
"relation", "INTERSECTS")))));
builder.visit(filter, null);
assertTrue(builder.createFilterCapabilities().fullySupports(filter));
assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
示例7: testGeoPolygonFilter
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testGeoPolygonFilter() throws CQLException {
Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(\"geo_point\", POLYGON((0 0, 0 1.1, 1.1 1.1, 1.1 0, 0 0)))");
List<List<Double>> points = ImmutableList.of(
ImmutableList.of(0.,0.),
ImmutableList.of(0.,1.1),
ImmutableList.of(1.1,1.1),
ImmutableList.of(1.1,0.),
ImmutableList.of(0.,0.));
Map<String,Object> expected = ImmutableMap.of("bool",
ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_polygon",
ImmutableMap.of("geo_point", ImmutableMap.of("points", points)))));
builder.visit(filter, null);
assertTrue(builder.createFilterCapabilities().fullySupports(filter));
assertEquals(expected, builder.getQueryBuilder());
}
示例8: testCompoundFilter
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testCompoundFilter() throws CQLException, IOException {
Filter filter = ECQL.toFilter("time > \"1970-01-01\" and INTERSECTS(\"geom\", LINESTRING(0 0,1.1 1.1))");
List<List<Double>> coords = new ArrayList<>();
coords.add(ImmutableList.of(0.,0.));
coords.add(ImmutableList.of(1.1,1.1));
Map<String,Object> expected = ImmutableMap.of("bool",
ImmutableMap.of("must", ImmutableList.of(ImmutableMap.of("range", ImmutableMap.of("time", ImmutableMap.of("gt", "1970-01-01"))),
ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL,
"filter", ImmutableMap.of("geo_shape",
ImmutableMap.of("geom", ImmutableMap.of("shape",
ImmutableMap.of("coordinates", coords, "type", "LineString"),
"relation", "INTERSECTS"))))))));
builder.encode(filter);
assertTrue(builder.createFilterCapabilities().fullySupports(filter));
assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
示例9: utcTimeZone
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
private static void utcTimeZone() throws Exception{
// utcTimeZone start
Filter filter = ECQL.toFilter("2006-11-30T01:00:00+03:00 DURING 2006-11-30T00:30:00+03:00/2006-11-30T01:30:00+03:00 ");
// utcTimeZone end
Utility.prittyPrintFilter(filter);
Boolean result = filter.evaluate(null);
System.out.println("Result of filter evaluation: " + result);
During during = (During) filter;
Literal literal = (Literal)during.getExpression1();
Date date = (Date)literal.getValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
TimeZone tz = TimeZone.getTimeZone("GMT+0300");
sdf.setTimeZone(tz);
System.out.println("Expression 1 as Date: " +sdf.format(date));
}
示例10: duringPredicateWithLefHandtAttribute
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
private static void duringPredicateWithLefHandtAttribute() throws Exception{
// duringPredicateWithLefHandtAttribute start
During filter = (During) ECQL.toFilter("lastEarthQuake DURING 1700-01-01T00:00:00Z/2011-01-01T00:00:00Z");
// duringPredicateWithLefHandtAttribute 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);
}
示例11: comparisonPredicateCQLCompatibility
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的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 );
}
}
示例12: comparisonUsingExpressions
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
/**
* Comparison between persons under 18 years old and over 65 years old
* @throws Exception
*/
static private void comparisonUsingExpressions() throws Exception {
// comparisonUsingExpressions start
Filter filter = ECQL.toFilter("(under18YearsOld * 19541453 / 100 ) < (over65YearsOld * 19541453 / 100 )");
// comparisonUsingExpressions end
SimpleFeature city = DataExamples.getInstanceOfCity();
Utility.prittyPrintFilter(filter);
PropertyIsLessThan lessThan =(PropertyIsLessThan) filter;
Expression leftExpr = lessThan.getExpression1();
Expression rightExpr = lessThan.getExpression2();
System.out.println("left expression value: " + leftExpr.evaluate(city));
System.out.println("right expression value: " + rightExpr.evaluate(city));
Boolean result = lessThan.evaluate(city);
System.out.println("Result of filter evaluation: " + result);
}
示例13: testEqual
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
@Test
public void testEqual()
throws CQLException,
ParseException {
final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor();
final Date etime = DateUtilities.parseISO("2005-05-19T21:32:56Z");
Filter filter = ECQL.toFilter("when = 2005-05-19T21:32:56Z");
Query query = new Query(
"type",
filter);
TemporalConstraints range = (TemporalConstraints) query.getFilter().accept(
visitor,
null);
assertNotNull(range);
assertEquals(
etime,
range.getStartRange().getStartTime());
assertEquals(
etime,
range.getEndRange().getEndTime());
}
示例14: parseFilter
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的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);
}
}
}
示例15: doProduceEcqlFilters
import org.geotools.filter.text.ecql.ECQL; //导入方法依赖的package包/类
/**
* Generate the eCQL-Filter.
* (based on the query list that has been establish)
*/
private void doProduceEcqlFilters() throws CQLException {
ArrayList<Query> queryList = new ArrayList<>();
if (complexQueries != null && complexQueries.size() > 0) {
for (Query query: complexQueries) {
try {
Filter filter = ECQL.toFilter(query.getValue());
Configuration configuration =
new org.geotools.filter.v2_0.FESConfiguration();
Encoder encoder = new Encoder(configuration);
encoder.setIndenting(true);
encoder.setIndentSize(INDENTSIZE);
encoder.setOmitXMLDeclaration(true);
String filterString = null;
filterString = encoder.encodeAsString(filter, FES.Filter);
if (filterString != null) {
eCQLFilters.add(filterString);
query.seteCQLFilter(filterString);
queryList.add(query);
}
} catch (IOException e) {
// log.log(log.getLevel(), e.getMessage(), e.getCause());
e.printStackTrace();
}
}
complexQueries = queryList;
}
}