本文整理汇总了Java中org.geotools.filter.text.cql2.CQLException类的典型用法代码示例。如果您正苦于以下问题:Java CQLException类的具体用法?Java CQLException怎么用?Java CQLException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CQLException类属于org.geotools.filter.text.cql2包,在下文中一共展示了CQLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: basicQuery
import org.geotools.filter.text.cql2.CQLException; //导入依赖的package包/类
/**
* Executes a basic bounding box query without any projections.
*
* @param simpleFeatureTypeName
* @param featureSource
*
* @throws IOException
* @throws CQLException
*/
static void basicQuery(String simpleFeatureTypeName, FeatureSource featureSource)
throws IOException, CQLException {
System.out.println("Submitting basic query with no projections\n");
// start with our basic filter to narrow the results
Filter cqlFilter = createBaseFilter();
// use the 2-arg constructor for the query - this will not restrict the attributes returned
Query query = new Query(simpleFeatureTypeName, cqlFilter);
// execute the query
FeatureCollection results = featureSource.getFeatures(query);
// loop through all results
FeatureIterator iterator = results.features();
try {
printResults(iterator);
} finally {
iterator.close();
}
}
示例2: testFidFilterQuery
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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());
}
示例3: testPidFilterQuery
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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);
}
示例4: testLike
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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);
}
示例5: createFilter
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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);
}
示例6: executeCQLQueryTest
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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);
}
}
示例7: getFilterFromParameters
import org.geotools.filter.text.cql2.CQLException; //导入依赖的package包/类
/**
* Gets the filter from parameters.
*
* @param wifParameters
* the wif parameters
* @return the filter from parameters
* @throws MismatchedDimensionException
* the mismatched dimension exception
* @throws TransformException
* the transform exception
* @throws NoSuchAuthorityCodeException
* the no such authority code exception
* @throws FactoryException
* the factory exception
* @throws ParseException
* the parse exception
* @throws CQLException
* the cQL exception
*/
public Filter getFilterFromParameters(final Map<String, Object> wifParameters)
throws MismatchedDimensionException, TransformException,
NoSuchAuthorityCodeException, FactoryException, ParseException,
CQLException {
LOGGER.debug("getFilterFromParameters...");
String queryTxt = "";
final String polyTxt = getIntersectionPolygon(wifParameters);
if (polyTxt == null) {
LOGGER
.info("no polygon query filter received, defaulting to including all the unified area zone!");
queryTxt = "include";
} else if (polyTxt.equals("")) {
LOGGER
.info("no polygon query filter received, defaulting to including all the unified area zone!");
queryTxt = "include";
} else {
queryTxt = polyTxt;
}
LOGGER.debug("query filter: {}", queryTxt);
return getFilter(queryTxt);
}
示例8: testGeoShapeIntersectsFilter
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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());
}
示例9: testGeoShapeIntersectsFilterReversed
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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());
}
示例10: testGeoPolygonFilter
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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());
}
示例11: testCompoundFilter
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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());
}
示例12: createFilter
import org.geotools.filter.text.cql2.CQLException; //导入依赖的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);
}
示例13: createExpressionList
import org.geotools.filter.text.cql2.CQLException; //导入依赖的package包/类
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;
}
示例14: getBboxFilter
import org.geotools.filter.text.cql2.CQLException; //导入依赖的package包/类
/**
* 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;
}
示例15: example5
import org.geotools.filter.text.cql2.CQLException; //导入依赖的package包/类
private static void example5() throws IOException, CQLException {
System.out.println("example5 start\n");
// example5 start
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("directory", directory);
DataStore store = DataStoreFinder.getDataStore(params);
SimpleFeatureSource featureSource = store.getFeatureSource("example");
Filter filter = CQL.toFilter("name = 'dave'");
SimpleFeatureCollection features = featureSource.getFeatures(filter);
System.out.println("found :" + features.size() + " feature");
SimpleFeatureIterator iterator = features.features();
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
System.out.println(feature.getID() + " location " + geometry);
}
} catch (Throwable t) {
iterator.close();
}
// example5 end
System.out.println("\nexample5 end\n");
}