本文整理汇总了Java中org.geotools.data.Query.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setFilter方法的具体用法?Java Query.setFilter怎么用?Java Query.setFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.data.Query
的用法示例。
在下文中一共展示了Query.setFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEncodedNativeTermQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testEncodedNativeTermQuery() throws Exception {
init("not-active");
Map<String, String> vparams = new HashMap<String, String>();
Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA"));
vparams.put("q", URLEncoder.encode(mapper.writeValueAsString(query), "UTF-8"));
Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams);
Query q = new Query(featureSource.getSchema().getTypeName());
q.setHints(hints);
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300"));
q.setFilter(filter);
ContentFeatureCollection features = featureSource.getFeatures(q);
assertEquals(1, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.12");
}
示例2: testGetFeaturesWithQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testGetFeaturesWithQuery() throws Exception {
init();
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("modem_b"), ff.literal(true));
Query query = new Query();
query.setPropertyNames(new String[] { "standard_ss", "security_ss" });
query.setFilter(filter);
SimpleFeatureCollection features = featureSource.getFeatures(query);
assertEquals(8, features.size());
SimpleFeatureIterator iterator = features.features();
try {
assertTrue(iterator.hasNext());
SimpleFeature feature = iterator.next();
assertEquals(2, feature.getAttributeCount());
String st = (String) feature.getAttribute("standard_ss");
// changed from "IEEE 802.11b" in SolrFeatureSourceTest
assertTrue(st.contains("IEEE 802.11b"));
} finally {
iterator.close();
}
}
示例3: getFeatures
import org.geotools.data.Query; //导入方法依赖的package包/类
private List<Object[]> getFeatures() throws Exception {
String layername = meta.getLayername();
Query q = new Query(layername);
FeatureSource<SimpleFeatureType, SimpleFeature> fs = ds
.getFeatureSource(layername);
SimpleFeatureType sft = fs.getSchema();
Filter f = buildFilter(sft);
if (f != null)
q.setFilter(f);
String maxFeatures = meta.getMaxFeatures();
if (!Const.isEmpty(maxFeatures))
q.setMaxFeatures(Integer.parseInt(maxFeatures));
String srs = meta.getSrs();
if (!Const.isEmpty(srs))
q.setCoordinateSystem(CRS.decode(srs));
return getRow(fs.getFeatures(q));
}
示例4: getElements
import org.geotools.data.Query; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
*/
@Transactional(readOnly = true)
public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException {
FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource();
try {
if (source instanceof FeatureStore<?, ?>) {
SimpleFeatureStore store = (SimpleFeatureStore) source;
transactionSynchronization.synchTransaction(store);
}
Query query = new Query();
query.setFilter(filter);
query.setMaxFeatures(maxResultSize > 0 ? maxResultSize : Integer.MAX_VALUE);
query.setStartIndex(offset);
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures(query);
FeatureIterator<SimpleFeature> it = fc.features();
transactionSynchronization.addIterator(it);
return new JavaIterator(it);
} catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well
throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM);
}
}
示例5: makeDefinitionQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
/**
* Takes a query and adapts it to match re definitionQuery filter
* configured for a feature type.
*
* @param query Query against this DataStore
* @param schema TODO
*
* @return Query restricted to the limits of definitionQuery
*
* @throws IOException See DataSourceException
* @throws DataSourceException If query could not meet the restrictions of
* definitionQuery
*/
protected Query makeDefinitionQuery(Query query, SimpleFeatureType schema) throws IOException {
if ((query == Query.ALL) || query.equals(Query.ALL)) {
return query;
}
try {
String[] propNames = extractAllowedAttributes(query, schema);
Filter filter = query.getFilter();
filter = makeDefinitionFilter(filter);
Query defQuery = new Query(query);
defQuery.setFilter(filter);
defQuery.setPropertyNames(propNames);
// set sort by
if (query.getSortBy() != null) {
defQuery.setSortBy(query.getSortBy());
}
// tell the data sources about the default linearization tolerance for curved
// geometries they might be reading
if (linearizationTolerance != null) {
query.getHints().put(Hints.LINEARIZATION_TOLERANCE, linearizationTolerance);
}
return defQuery;
} catch (Exception ex) {
throw new DataSourceException(
"Could not restrict the query to the definition criteria: " + ex.getMessage(), ex);
}
}
示例6: testInvertQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testInvertQuery() throws Exception {
Filter filter = ff.bbox("geom", 0, 0, 0, 0, "EPSG:4326");
ReferencedEnvelope env = new ReferencedEnvelope(0,1,2,3,DefaultGeographicCRS.WGS84);
Query query = new Query();
query.setFilter(filter);
Query queryOut = process.invertQuery(env, query, null);
assertEquals(ff.bbox("geom", 0, 2, 1, 3, "EPSG:4326"), queryOut.getFilter());
}
示例7: testInvertQueryAcrossDateline
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testInvertQueryAcrossDateline() throws Exception {
Filter filter = ff.bbox("geom", 0, 0, 0, 0, "EPSG:4326");
ReferencedEnvelope env = new ReferencedEnvelope(-179,179,2,3,DefaultGeographicCRS.WGS84);
Query query = new Query();
query.setFilter(filter);
Query queryOut = process.invertQuery(env, query, null);
assertEquals(ff.bbox("geom", -179, 2, 179, 3, "EPSG:4326"), queryOut.getFilter());
}
示例8: testInvertQueryNorthEastAxisOrder
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testInvertQueryNorthEastAxisOrder() throws Exception {
Filter filter = ff.bbox("geom", 0, 0, 0, 0, "EPSG:4326");
CRSAuthorityFactory factory = CRS.getAuthorityFactory(false);
CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("EPSG:4326");
ReferencedEnvelope env = new ReferencedEnvelope(2,3,0,1,crs);
Query query = new Query();
query.setFilter(filter);
Query queryOut = process.invertQuery(env, query, null);
assertEquals(ff.bbox("geom", 0, 2, 1, 3, "EPSG:4326"), queryOut.getFilter());
}
示例9: testInvertQueryWithOtherFilterElement
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testInvertQueryWithOtherFilterElement() {
Filter filter = ff.and(ff.equals(ff.property("key"), ff.literal("value")), ff.bbox("geom", 0, 0, 0, 0, "EPSG:4326"));
ReferencedEnvelope env = new ReferencedEnvelope(0,1,2,3,DefaultGeographicCRS.WGS84);
Query query = new Query();
query.setFilter(filter);
Query queryOut = process.invertQuery(env, query, null);
assertEquals(ff.and(ff.equals(ff.property("key"), ff.literal("value")), ff.bbox("geom", 0, 2, 1, 3, "EPSG:4326")), queryOut.getFilter());
}
示例10: testEncodeQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testEncodeQuery() {
Query query = new Query();
query.setFilter(Filter.INCLUDE);
builder.encode(query);
assertEquals(MATCH_ALL, builder.getQueryBuilder());
assertEquals(MATCH_ALL, builder.getNativeQueryBuilder());
assertNull(builder.getAggregations());
assertTrue(builder.getFullySupported());
}
示例11: testCountWithIsEqualFilter
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testCountWithIsEqualFilter() throws Exception {
init();
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("vendor_s"), ff.literal("D-Link"));
Query query = new Query();
query.setFilter(filter);
assertEquals(4, featureSource.getCount(query));
}
示例12: testCountWithIsNotEqualFilter
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testCountWithIsNotEqualFilter() throws Exception {
init();
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsNotEqualTo filter = ff.notEqual(ff.property("vendor_s"), ff.literal("D-Link"));
Query query = new Query();
query.setFilter(filter);
assertEquals(7, featureSource.getCount(query));
}
示例13: reprojectFilter
import org.geotools.data.Query; //导入方法依赖的package包/类
private Query reprojectFilter(Query query) throws IOException {
SimpleFeatureType nativeFeatureType = source.getSchema();
final GeometryDescriptor geom = nativeFeatureType.getGeometryDescriptor();
// if no geometry involved, no reprojection needed
if(geom == null)
return query;
try {
// default CRS: the CRS we can assume geometry and bbox elements in filter are
// that is, usually the declared one, but the native one in the leave case
CoordinateReferenceSystem defaultCRS = null;
// we need to reproject all bbox and geometries to a target crs, which is
// the native one usually, but it's the declared on in the force case (since in
// that case we completely ignore the native one)
CoordinateReferenceSystem targetCRS = null;
CoordinateReferenceSystem nativeCRS = geom.getCoordinateReferenceSystem();
if(srsHandling == ProjectionPolicy.FORCE_DECLARED) {
defaultCRS = declaredCRS;
targetCRS = declaredCRS;
nativeFeatureType = FeatureTypes.transform(nativeFeatureType, declaredCRS);
} else if(srsHandling == ProjectionPolicy.REPROJECT_TO_DECLARED) {
defaultCRS = declaredCRS;
targetCRS = nativeCRS;
} else { // FeatureTypeInfo.LEAVE
defaultCRS = nativeCRS;
targetCRS = nativeCRS;
}
// now we apply a default to all geometries and bbox in the filter
ISODefaultCRSFilterVisitor defaultCRSVisitor = new ISODefaultCRSFilterVisitor(ff, defaultCRS);
Filter filter = query.getFilter() != null ? query.getFilter() : Filter.INCLUDE;
Filter defaultedFilter = (Filter) filter.accept(defaultCRSVisitor, null);
// and then we reproject all geometries so that the datastore receives
// them in the native projection system (or the forced one, in case of force)
ISOReprojectingFilterVisitor reprojectingVisitor = new ISOReprojectingFilterVisitor(ff, nativeFeatureType);
Filter reprojectedFilter = (Filter) defaultedFilter.accept(reprojectingVisitor, null);
Query reprojectedQuery = new Query(query);
reprojectedQuery.setFilter(reprojectedFilter);
return reprojectedQuery;
} catch(Exception e) {
throw new DataSourceException("Had troubles handling filter reprojection...", e);
}
}
示例14: invertQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
public Query invertQuery(
@DescribeParameter(name = "outputBBOX", description = "Georeferenced bounding box of the output") ReferencedEnvelope envelope,
Query targetQuery, GridGeometry targetGridGeometry
) throws ProcessException {
final BBOXRemovingFilterVisitor visitor = new BBOXRemovingFilterVisitor();
Filter filter = (Filter) targetQuery.getFilter().accept(visitor, null);
final String geometryName = visitor.getGeometryPropertyName();
if (geometryName != null) {
final BBOX bbox;
try {
if (envelope.getCoordinateReferenceSystem() != null) {
envelope = envelope.transform(DefaultGeographicCRS.WGS84,false);
}
bbox = FILTER_FACTORY.bbox(geometryName, envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY(), "EPSG:4326");
} catch (Exception e) {
throw new ProcessException("Unable to create bbox filter for feature source", e);
}
filter = (Filter) FILTER_FACTORY.and(filter, bbox).accept(new SimplifyingFilterVisitor(), null);
targetQuery.setFilter(filter);
}
final List<PropertyName> properties = new ArrayList<>();
properties.add(FILTER_FACTORY.property("_aggregation"));
targetQuery.setProperties(properties);
return targetQuery;
}
示例15: testNativeBooleanQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testNativeBooleanQuery() throws Exception {
init();
Map<String, String> vparams = new HashMap<String, String>();
Map<String,Object> query = ImmutableMap.of("bool", ImmutableMap.of("must",
ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")),
"must_not", ImmutableMap.of("term", ImmutableMap.of("modem_b", true))));
vparams.put("q", mapper.writeValueAsString(query));
Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams);
Query q = new Query(featureSource.getSchema().getTypeName());
q.setHints(hints);
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300"));
q.setFilter(filter);
ContentFeatureCollection features = featureSource.getFeatures(q);
assertEquals(2, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getAttribute("modem_b"), false);
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getAttribute("modem_b"), false);
}