本文整理汇总了Java中org.geotools.filter.text.ecql.ECQL类的典型用法代码示例。如果您正苦于以下问题:Java ECQL类的具体用法?Java ECQL怎么用?Java ECQL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECQL类属于org.geotools.filter.text.ecql包,在下文中一共展示了ECQL类的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: expressionLessThanOrEqualToProperty
import org.geotools.filter.text.ecql.ECQL; //导入依赖的package包/类
/**
* ECQL allows expressions in the left hand of comparison predicate.
*
* @throws Exception
*/
static private void expressionLessThanOrEqualToProperty() throws Exception {
// ecql expressionLessThanOrEqualToProperty start
Filter filter = ECQL.toFilter("1000 <= population");
// ecql expressionLessThanOrEqualToProperty end
Utility.prittyPrintFilter(filter);
SimpleFeature usa = DataExamples.getInstanceOfCountry();
System.out.println("Country: " + usa.getProperty("countryName").getValue());
System.out.println("Population: " + usa.getProperty("population").getValue());
Boolean result = filter.evaluate(usa);
System.out.println("Result of filter evaluation: " + result);
}
示例13: 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);
}
示例14: initialize
import org.geotools.filter.text.ecql.ECQL; //导入依赖的package包/类
@Override
public void initialize(InputSplit split, TaskAttemptContext context) throws IOException,
InterruptedException
{
delegateReader.initialize(split, context);
// No need to initialize the delegateReader since it was already done in the
// GeoWaveInputFormat.createRecordReader method
strCqlFilter = context.getConfiguration().get(CQL_FILTER);
if (strCqlFilter != null && !strCqlFilter.isEmpty())
{
try
{
log.info("Creating the CQL filter");
cqlFilter = ECQL.toFilter(strCqlFilter);
log.info("Done creating the CQL filter");
}
catch (CQLException e)
{
throw new IOException("Unable to instantiate CQL filter for: " + strCqlFilter, e);
}
}
}
示例15: toBinary
import org.geotools.filter.text.ecql.ECQL; //导入依赖的package包/类
@Override
public byte[] toBinary() {
byte[] filterBytes;
if (filter == null) {
LOGGER.warn("CQL filter is null");
filterBytes = new byte[] {};
}
else {
filterBytes = StringUtils.stringToBinary(ECQL.toCQL(filter));
}
byte[] adapterBytes;
if (adapter != null) {
adapterBytes = PersistenceUtils.toBinary(adapter);
}
else {
LOGGER.warn("Feature Data Adapter is null");
adapterBytes = new byte[] {};
}
final ByteBuffer buf = ByteBuffer.allocate(filterBytes.length + adapterBytes.length + 4);
buf.putInt(filterBytes.length);
buf.put(filterBytes);
buf.put(adapterBytes);
return buf.array();
}