Java Code Examples for org.geotools.data.Query#setFilter()
The following examples show how to use
org.geotools.data.Query#setFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeTermQuery() throws Exception { init("not-active"); Map<String, String> vparams = new HashMap<>(); Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA")); 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(1, features.size()); SimpleFeatureIterator fsi = features.features(); assertTrue(fsi.hasNext()); assertEquals(fsi.next().getID(), "active.12"); }
Example 2
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testEncodedNativeTermQuery() throws Exception { init("not-active"); Map<String, String> vparams = new HashMap<>(); 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"); }
Example 3
Source File: ElasticViewParametersFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testNativeBooleanQuery() throws Exception { init(); Map<String, String> vparams = new HashMap<>(); 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); }
Example 4
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@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()); try (SimpleFeatureIterator iterator = features.features()) { 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")); } }
Example 5
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * {@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); } }
Example 6
Source File: GeoHashGridProcessTest.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testInvertQuery() { 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()); }
Example 7
Source File: GeoHashGridProcessTest.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testInvertQueryAcrossDateline() { 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()); }
Example 8
Source File: GeoHashGridProcessTest.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@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()); }
Example 9
Source File: GeoHashGridProcessTest.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@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()); }
Example 10
Source File: ElasticFilterTest.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@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()); }
Example 11
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@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)); }
Example 12
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@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)); }