org.opengis.filter.Filter Java Examples
The following examples show how to use
org.opengis.filter.Filter.
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: ExtractAttributesTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
@Test public void testMultiComparatorFilter() { DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2(); StyledLayerDescriptor sld = createTestSLD(dummy); List<Rule> ruleList = getRuleList(sld); Rule rule = DefaultSymbols.createNewRule(); // Try with something complex Filter filter = ff.and( ff.greater(ff.literal(42), ff.property("int")), ff.less(ff.literal(12), ff.property("abc"))); rule.setFilter(filter); ruleList.clear(); ruleList.add(rule); ExtractAttributes extract = new ExtractAttributes(); extract.extractDefaultFields(sld); // Check fields extracted ok List<DataSourceAttributeData> actualFieldnameList = extract.getFields(); assertEquals(2, actualFieldnameList.size()); DataSourceAttributeData dataSourceField = actualFieldnameList.get(0); assertEquals(Integer.class, dataSourceField.getType()); }
Example #2
Source File: HibernateFilterOneToManyTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void likeFilter() throws Exception { Filter wildCardFilter = filterCreator.createLikeFilter(ATTR__ONE_TO_MANY__DOT__TEXT, "*-1"); Iterator<?> it = layer.getElements(wildCardFilter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(3, t); Filter singleCharFilter = filterCreator.createLikeFilter(ATTR__ONE_TO_MANY__DOT__TEXT, "oneToMany-?"); it = layer.getElements(singleCharFilter, 0, 0); t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(4, t); }
Example #3
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testWithin() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format("WITHIN(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Envelope bounds = new Envelope(0, 10, 0, 25); final Geometry bbox = new GeometryFactory().toGeometry(bounds); assertTrue(bbox.equalsTopo(result.getGeometry())); assertTrue(result.getCompareOp() == CompareOperation.CONTAINS); }
Example #4
Source File: HibernateFilterAttributeTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void likeFilter() throws Exception { Filter filter = filterCreator.createLikeFilter(PARAM_TEXT_ATTR, "*name-_"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(4, t); // test case-insensitive (http://jira.geomajas.org/browse/HIB-33) filter = filterCreator.createLikeFilter(PARAM_TEXT_ATTR, "*NAME-_"); it = layer.getElements(filter, 0, 0); t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(4, t); }
Example #5
Source File: CQLFilterOptionProvider.java From geowave with Apache License 2.0 | 6 votes |
@Override public FilterParameter convert(String value) { Filter convertedFilter = null; if (value != null) { try { convertedFilter = asFilter(value); } // HP Fortify "Log Forging" false positive // What Fortify considers "user input" comes only // from users with OS-level access anyway catch (final CQLException e) { LOGGER.error("Cannot parse CQL expression '" + value + "'", e); // value = null; // convertedFilter = null; throw new ParameterException("Cannot parse CQL expression '" + value + "'", e); } } else { value = null; } return new FilterParameter(value, convertedFilter); }
Example #6
Source File: FilterOneToManyTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void likeFilter() throws Exception { Filter wildCardFilter = filterCreator.createLikeFilter(OTM_TEXT, "*-1"); Iterator<?> it = layer.getElements(wildCardFilter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a AssociationFeature", it.next() instanceof AssociationFeature); t++; } Assert.assertEquals(3, t); Filter singleCharFilter = filterCreator.createLikeFilter(OTM_TEXT, "oneToMany-?"); it = layer.getElements(singleCharFilter, 0, 0); t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a AssociationFeature", it.next() instanceof AssociationFeature); t++; } Assert.assertEquals(4, t); }
Example #7
Source File: GeoWaveGTQueryTest.java From rya with Apache License 2.0 | 6 votes |
@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); } }
Example #8
Source File: DWithin.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Creates the filter. * * @param parameterList the parameter list * @return the filter */ @Override public Filter createFilter(List<Expression> parameterList) { DWithinImpl filter = null; if ((parameterList == null) || ((parameterList.size() != 2) && (parameterList.size() != 4))) { filter = new DWithinExtended(); } else { if (parameterList.size() == 2) { parameterList.add(ff.literal(0.0)); parameterList.add(ff.literal("")); } filter = new DWithinExtended( parameterList.get(0), parameterList.get(1), parameterList.get(2), parameterList.get(3)); } return filter; }
Example #9
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testDisjoint() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "DISJOINT(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); // for non-inclusive filters we can't extract query geometry and // predicate // assertTrue(Double.isNaN(result.getGeometry().getArea())); assertTrue(result.getCompareOp() == null); }
Example #10
Source File: SearchFeatureCommandTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test @DirtiesContext // @todo need to check why this is necessary, otherwise next test fails? (GetVectorTileCommandTest) // probably cause by directly using the command service which has an injected security context public void createFilterTest() throws Exception { SearchFeatureRequest request = new SearchFeatureRequest(); request.setLayerId(LAYER_ID); request.setCrs("EPSG:4326"); SearchCriterion searchCriterion = new SearchCriterion(); Filter filter; // needs to be FidFilter when equals test on id searchCriterion.setAttributeName(ID_ATTRIBUTE); searchCriterion.setOperator("="); searchCriterion.setValue("'1'"); request.setCriteria(new SearchCriterion[] {searchCriterion}); filter = searchFeatureCommand.createFilter(request, LAYER_ID); Assert.assertTrue(filter instanceof Id); // but *not* when other test searchCriterion.setAttributeName(ID_ATTRIBUTE); searchCriterion.setOperator("like"); searchCriterion.setValue("'%a%'"); request.setCriteria(new SearchCriterion[] {searchCriterion}); filter = searchFeatureCommand.createFilter(request, LAYER_ID); Assert.assertFalse(filter instanceof Id); }
Example #11
Source File: CqlTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void toFilter() { Filter f; try { f = CQL.toFilter("a.b < 5"); } catch (CQLException e) { f = null; } Assert.notNull(f, "Filter should not be null"); // try { // f = CQL.toFilter("bookstore[1].book < 5"); // } catch (CQLException e) { // f = null; // } // Assert.notNull(f, "Filter should not be null"); }
Example #12
Source File: HibernateFilterAttributeTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void compareFilterOnDouble() throws Exception { Filter lt = filterCreator.createCompareFilter(PARAM_DOUBLE_ATTR, "<", "35"); Iterator<?> it = layer.getElements(lt, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(3, t); Filter ne = filterCreator.createCompareFilter(PARAM_DOUBLE_ATTR, "<>", "10"); it = layer.getElements(ne, 0, 0); t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(3, t); }
Example #13
Source File: GetFeaturesEachStepTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
private PipelineContext getPipelineContext(int offset, int limit, Boolean forcePaging) { PipelineContext pip = new PipelineContextImpl(); pip.put(PipelineCode.LAYER_KEY, testLayer); pip.put(PipelineCode.OFFSET_KEY, offset); pip.put(PipelineCode.MAX_RESULT_SIZE_KEY, limit); if(forcePaging != null) { pip.put(PipelineCode.FORCE_PAGING_KEY, forcePaging); } pip.put(PipelineCode.FILTER_KEY, Filter.INCLUDE); pip.put(PipelineCode.FEATURE_INCLUDES_KEY, 0); pip.put(PipelineCode.LAYER_ID_KEY, testLayer.getId()); pip.put(PipelineCode.STYLE_KEY, new NamedStyleInfo()); return pip; }
Example #14
Source File: PropertyIgnoringFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
@Override public Object visit(final During during, final Object extraData) { if (!usesProperty(during)) { return Filter.INCLUDE; } return super.visit(during, extraData); }
Example #15
Source File: ShapeInMemFilterTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void bboxFilter() throws LayerException { Envelope bbox = new Envelope(-0.4d, -0.2d, -0.3d, 0.1d); Filter filter = filterService.createBboxFilter("EPSG:4326", bbox, PARAM_GEOMETRY_ATTR); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { it.next(); t++; } Assert.assertEquals(3, t); }
Example #16
Source File: FilterManyToOneTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void ltFilterOnDate() throws Exception { DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date date; date = format.parse("01/01/2008"); Filter filter = filterCreator.createCompareFilter(MTO_DATE, "<", date); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a AssociationFeature", it.next() instanceof AssociationFeature); t++; } Assert.assertEquals(2, t); }
Example #17
Source File: NestedFeatureModelTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testGetAttributes() throws LayerException { Iterator it = layer.getElements(Filter.INCLUDE, 0, 1); Assert.assertTrue(it.hasNext()); Object f1 = it.next(); Assert.assertFalse(it.hasNext()); Attribute many = featureModel.getAttribute(f1, "many"); Assert.assertTrue(many instanceof OneToManyAttribute); Assert.assertNotNull(many.getValue()); Iterator<AssociationValue> it2 = ((OneToManyAttribute) many).getValue().iterator(); Assert.assertTrue(it2.hasNext()); AssociationValue v = it2.next(); Attribute<?> manyInMany = v.getAllAttributes().get("manyInMany"); Assert.assertNotNull(manyInMany); Assert.assertTrue(manyInMany instanceof OneToManyAttribute); Attribute<?> oneInMany = v.getAllAttributes().get("oneInMany"); Assert.assertNotNull(oneInMany); Assert.assertTrue(oneInMany instanceof ManyToOneAttribute); Attribute one = featureModel.getAttribute(f1, "one"); Assert.assertTrue(one instanceof ManyToOneAttribute); Assert.assertNotNull(one.getValue()); AssociationValue v2 = ((ManyToOneAttribute) one).getValue(); Attribute<?> oneInOne = v2.getAllAttributes().get("oneInOne"); Assert.assertNotNull(oneInOne); Assert.assertTrue(oneInOne instanceof ManyToOneAttribute); Attribute<?> manyInOne = v2.getAllAttributes().get("manyInOne"); Assert.assertNotNull(manyInOne); Assert.assertTrue(manyInOne instanceof OneToManyAttribute); }
Example #18
Source File: TestFilterPanelv2.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Test public void testIntersects() { TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null); testPanel.configure("test", String.class, false); ReferencedEnvelope bbox = new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84); Filter filter = ff2.intersects(ff.property("the_geom"), ff.literal(bbox)); String expected = filter.toString(); testPanel.filterDialog(String.class, filter); String actual = testPanel.getFilterString(); assertEquals(expected, actual); }
Example #19
Source File: FilterToCQLToolTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testDWithinFromCQLFilter() throws CQLException { final Filter filter = CQL.toFilter("DWITHIN(geom, POINT(-122.7668 0.4979), 233.7, meters)"); final String gtFilterStr = ECQL.toCQL(FilterToCQLTool.fixDWithin(filter)); System.out.println(gtFilterStr); assertTrue(gtFilterStr.contains("INTERSECTS(geom, POLYGON ((")); testFilter(FilterToCQLTool.toFilter(gtFilterStr)); }
Example #20
Source File: FilterField.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the filter. * * @return the filter */ public Filter getFilter() { FilterConfigInterface filterConfig = getFilterConfig(); Filter newFilter = null; if (filterConfig != null) { newFilter = filterConfig.createFilter(); } return newFilter; }
Example #21
Source File: HibernateFilterAttributeTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void betweenFilterOnDouble() throws Exception { Filter filter = filterCreator.createBetweenFilter(PARAM_DOUBLE_ATTR, "5.0", "25.0"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(2, t); }
Example #22
Source File: PropertyIgnoringFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
@Override public Object visit(final Within filter, final Object extraData) { if (!usesProperty(filter)) { return Filter.INCLUDE; } return super.visit(filter, extraData); }
Example #23
Source File: HibernateFilterOneToManyTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void leFilterOnDate() throws Exception { DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date date; date = format.parse("01/01/2007"); Filter filter = filterCreator.createCompareFilter(ATTR__ONE_TO_MANY__DOT__DATE, "<=", date); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(3, t); }
Example #24
Source File: ShapeInMemLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Retrieve the bounds of the specified features. * * @param filter filter * @return the bounds of the specified features * @throws LayerException cannot read features */ public Envelope getBounds(Filter filter) throws LayerException { try { FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureSource().getFeatures(filter); return fc.getBounds(); } catch (IOException ioe) { throw new LayerException(ioe, ExceptionCode.FEATURE_MODEL_PROBLEM); } }
Example #25
Source File: HibernateFilterManyToOneTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void neFilterOnFloat() throws Exception { Filter filter = filterCreator.createCompareFilter(ATTR__MANY_TO_ONE__DOT__FLOAT, "<>", "200"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue("Returned object must be a HibernateTestFeature", it.next() instanceof HibernateTestFeature); t++; } Assert.assertEquals(3, t); }
Example #26
Source File: PropertyIgnoringFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
@Override public Object visit(final Crosses filter, final Object extraData) { if (!usesProperty(filter)) { return Filter.INCLUDE; } return super.visit(filter, extraData); }
Example #27
Source File: VectorLayerServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test @DirtiesContext @SuppressWarnings("unchecked") public void testUpdate() throws Exception { Filter filter = filterService.createFidFilter(new String[]{"3"}); CoordinateReferenceSystem crs = geoService.getCrs(beanLayer.getLayerInfo().getCrs()); List<InternalFeature> oldFeatures = layerService.getFeatures(LAYER_ID, crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES); Assert.assertEquals(1, oldFeatures.size()); InternalFeature feature = oldFeatures.get(0); List<InternalFeature> newFeatures = new ArrayList<InternalFeature>(); feature = feature.clone(); feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed")); newFeatures.add(feature); layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures); Iterator<FeatureBean> iterator = (Iterator<FeatureBean>) beanLayer.getElements(filterService.createTrueFilter(), 0, 0); int count = 0; int check = 0; while (iterator.hasNext()) { FeatureBean featureBean = iterator.next(); count++; if (3 == featureBean.getId()) { Assert.assertEquals("changed", featureBean.getStringAttr()); } check |= 1 << (featureBean.getId() - 1); } Assert.assertEquals(3, count); Assert.assertEquals(7, check); }
Example #28
Source File: ElasticTemporalFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testTContains() throws Exception { init(); Period period = period("2004-19-06 03:44:56", "2004-20-06 03:44:58"); FilterFactory ff = dataStore.getFilterFactory(); Filter f = ff.tcontains(ff.literal(period), ff.property("installed_tdt")); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(1, features.size()); }
Example #29
Source File: GetFeaturesTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testFeaturesFilteredTransformed() throws Exception { List<InternalFeature> features; InternalFeature feature; Filter filter = filterService.createFidFilter(new String[] {"3"}); // first run, this should put things in the cache recorder.clear(); features = vectorLayerService.getFeatures(LAYER_BEANS, mercator, filter, null, GeomajasConstant.FEATURE_INCLUDE_GEOMETRY); Assert.assertNotNull(features); Assert.assertEquals(1, features.size()); feature = features.get(0); Assert.assertEquals(222638.98158654713, feature.getGeometry().getCoordinates()[0].x, DELTA); Assert.assertEquals(111325.14286638486, feature.getGeometry().getCoordinates()[0].y, DELTA); Assert.assertEquals("", recorder.matches(CacheCategory.FEATURE, "Put item in cache")); // get features again, the result should come from the cache and be the same recorder.clear(); features = vectorLayerService.getFeatures(LAYER_BEANS, mercator, filter, null, GeomajasConstant.FEATURE_INCLUDE_GEOMETRY); Assert.assertNotNull(features); Assert.assertEquals(1, features.size()); feature = features.get(0); Assert.assertEquals(222638.98158654713, feature.getGeometry().getCoordinates()[0].x, DELTA); Assert.assertEquals(111325.14286638486, feature.getGeometry().getCoordinates()[0].y, DELTA); Assert.assertEquals("", recorder.matches(CacheCategory.FEATURE, "Got item from cache")); }
Example #30
Source File: SceneFeatureIteratorTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testIterate() throws IOException, CQLException { final boolean onlyScenesSinceLastRun = false; final boolean useCachedScenes = true; final boolean nBestScenesByPathRow = false; final int nBestScenes = 1; final Filter cqlFilter = CQL.toFilter("BBOX(shape,-76.6,42.34,-76.4,42.54) and band='BQA'"); final String workspaceDir = Tests.WORKSPACE_DIR; final List<SimpleFeature> features = new ArrayList<>(); try (SceneFeatureIterator iterator = new SceneFeatureIterator( onlyScenesSinceLastRun, useCachedScenes, nBestScenesByPathRow, nBestScenes, cqlFilter, workspaceDir)) { while (iterator.hasNext()) { features.add(iterator.next()); } } assertEquals(features.size(), 1); assertThat( features, everyItem( allOf( hasProperties(), inBounds( new Envelope2D( new DirectPosition2D(-76.6, 42.34), new DirectPosition2D(-76.4, 42.54)))))); }