Java Code Examples for org.geotools.filter.text.cql2.CQL#toFilter()
The following examples show how to use
org.geotools.filter.text.cql2.CQL#toFilter() .
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: FilterUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example 2
Source File: WFSSpatialTest.java From geowave with Apache License 2.0 | 6 votes |
@Before public void setup() throws SchemaException, CQLException, IOException, GeoWavePluginException { dataStore = createDataStore(); type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String"); dataStore.createSchema(type); query = new Query( "geostuff", CQL.toFilter( "BBOX(geometry,27.20,41.30,27.30,41.20) and when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"), new String[] {"geometry", "pid"}); }
Example 3
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testIntesectAndCrossesAndLike() throws CQLException, TransformException, ParseException { // we are testing to see if we are able to combine dissimilar geometric // relations correctly // to extract query geometry. Note, that returned predicate is null // since we can't represent // CQL expression fully into single query geometry and predicate final Filter filter = CQL.toFilter( String.format( "CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0))) AND location == 'abc'", 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() == null); }
Example 4
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 5
Source File: ExtractTimeFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testDuring() throws CQLException, ParseException { final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor(); final Date stime = new Date(DateUtilities.parseISO("2005-05-19T20:32:56Z").getTime() + 1); final Date etime = new Date(DateUtilities.parseISO("2005-05-19T21:32:56Z").getTime() - 1); final Filter filter = CQL.toFilter("when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"); final Query query = new Query("type", filter); TemporalConstraints range = (TemporalConstraints) query.getFilter().accept(visitor, null); assertNotNull(range); assertEquals(stime, range.getStartRange().getStartTime()); assertEquals(etime, range.getStartRange().getEndTime()); range = (TemporalConstraints) query.getFilter().accept(visitor, null); assertNotNull(range); assertEquals(stime, range.getStartRange().getStartTime()); assertEquals(etime, range.getStartRange().getEndTime()); }
Example 6
Source File: GeoToolsAttributesSubsetTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testSubsetAttributes() throws CQLException, IOException { final Query query = new Query( typeName, CQL.toFilter(cqlPredicate), new String[] {geometry_attribute, string_attribute}); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = geotoolsDataStore.getFeatureReader(query, Transaction.AUTO_COMMIT); int count = 0; while (reader.hasNext()) { final SimpleFeature feature = reader.next(); count++; Assert.assertTrue(feature.getAttribute(geometry_attribute) != null); Assert.assertTrue(feature.getAttribute(long_attribute) == null); Assert.assertTrue(feature.getAttribute(string_attribute) != null); } Assert.assertTrue(count == 3); }
Example 7
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testEquals() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "EQUALS(geom, 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.EQUALS); }
Example 8
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testOverlaps() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "OVERLAPS(%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.OVERLAPS); }
Example 9
Source File: WFSTemporalQueryTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testTemporal() throws CQLException, IOException, ParseException { populate(); final Transaction transaction2 = new DefaultTransaction(); final Query query = new Query( "geostuff", CQL.toFilter( "BBOX(geometry,44,27,42,30) and start during 2005-05-16T20:32:56Z/2005-05-20T21:32:56Z and end during 2005-05-18T20:32:56Z/2005-05-22T21:32:56Z"), new String[] {"geometry", "start", "end", "pid"}); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, transaction2); int c = 0; while (reader.hasNext()) { reader.next(); c++; } reader.close(); transaction2.commit(); transaction2.close(); assertEquals(2, c); }
Example 10
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testDWithinDateLine() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "DWITHIN(%s, POINT(179.9998 0.79), 13.7, kilometers)", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Geometry geometry = result.getGeometry(); assertNotNull(geometry); for (final Coordinate coord : geometry.getCoordinates()) { assertEquals( 13707.1, JTS.orthodromicDistance( coord, new Coordinate(179.9999, 0.79), GeometryUtils.getDefaultCRS()), 2000); } }
Example 11
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testDWithin() throws CQLException, TransformException, ParseException { final Filter filter = CQL.toFilter( String.format( "DWITHIN(%s, POINT(-122.7668 0.4979), 233.7, meters)", geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Geometry geometry = result.getGeometry(); assertNotNull(geometry); for (final Coordinate coord : geometry.getCoordinates()) { assertEquals( 233.7, JTS.orthodromicDistance( coord, new Coordinate(-122.7668, 0.4979), GeometryUtils.getDefaultCRS()), 2); } }
Example 12
Source File: GeoWaveFeatureSourceTest.java From geowave with Apache License 2.0 | 6 votes |
public void testPartial(final Populater populater, final String ext) throws CQLException, Exception { final String typeName = "GeoWaveFeatureSourceTest_p" + ext; final SimpleFeatureType type = DataUtilities.createType( typeName, "geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date"); final DataStore dataStore = createDataStore(); populater.populate(type, dataStore); final SimpleFeatureSource source = dataStore.getFeatureSource(typeName); final Query query = new Query( typeName, CQL.toFilter( "BBOX(geometry,42,28,44,30) and when during 2005-05-01T20:32:56Z/2005-05-29T21:32:56Z"), new String[] {"geometry", "when", "pid"}); final ReferencedEnvelope env = source.getBounds(query); assertEquals(43.454, env.getMaxX(), 0.0001); assertEquals(28.232, env.getMinY(), 0.0001); assertEquals(28.242, env.getMaxY(), 0.0001); assertEquals(2, source.getCount(query)); }
Example 13
Source File: LayerFilterAuthorizationInfo.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Override public Filter getFeatureFilter(String layerId) { try { String filter = info.getFilters().get(layerId); if (filter == null) { return Filter.INCLUDE; } return CQL.toFilter(filter); } catch (CQLException cqlException) { info.log.error(cqlException.getMessage(), cqlException); return Filter.EXCLUDE; } }
Example 14
Source File: WFSTransactionTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, IOException, GeoWavePluginException { dataStore = createDataStore(); type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String"); dataStore.createSchema(type); query = new Query( "geostuff", CQL.toFilter("BBOX(geometry,27.20,41.20,27.30,41.30)"), new String[] {"geometry", "pid"}); }
Example 15
Source File: GeoToolsAttributesSubsetTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testAllAttributes() throws CQLException, IOException { final Query query = new Query(typeName, CQL.toFilter(cqlPredicate), Query.ALL_PROPERTIES); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = geotoolsDataStore.getFeatureReader(query, Transaction.AUTO_COMMIT); int count = 0; while (reader.hasNext()) { final SimpleFeature feature = reader.next(); count++; Assert.assertTrue(feature.getAttribute(geometry_attribute) != null); Assert.assertTrue(feature.getAttribute(long_attribute) != null); Assert.assertTrue(feature.getAttribute(string_attribute) != null); } Assert.assertTrue(count == 3); }
Example 16
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testIntesectAndCrosses() throws CQLException, TransformException, ParseException { // CROSSES geometry is completely contained within INTERSECT geometry // we are testing to see if we are able to combine dissimilar geometric // relations correctly // to extract query geometry. Note, we can't combine two different // predicates into one but // we can combine geometries for the purpose of deriving linear // constraints final Filter filter = CQL.toFilter( String.format( "INTERSECTS(%s, POLYGON((0 0, 0 50, 20 50, 20 0, 0 0))) AND CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName, 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() == null); }
Example 17
Source File: ExtractGeometryFilterVisitorTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testOverlapsOrCrosses() throws CQLException, TransformException, ParseException { // TOUCHES geometry is completely contained within OVERLAPS geometry // we are testing to see if we are able to combine dissimilar geometric // relations correctly // to extract query geometry. Note, we can't combine two different // predicates into one but // we can combine geometries for the purpose of deriving linear // constraints final Filter filter = CQL.toFilter( String.format( "OVERLAPS(%s, POLYGON((0 0, 0 50, 20 50, 20 0, 0 0))) OR TOUCHES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName, geomAttributeName)); final Query query = new Query("type", filter); final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null); final Envelope bounds = new Envelope(0, 20, 0, 50); final Geometry bbox = new GeometryFactory().toGeometry(bounds); assertTrue(bbox.equalsTopo(result.getGeometry())); assertTrue(result.getCompareOp() == null); }
Example 18
Source File: RuleDetails.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Update filter. * * @return the filter */ private Filter updateFilter() { String filterText = fieldConfigVisitor.getText(FieldIdEnum.FILTER); Filter filter = originalFilter; if (originalFilter == null) { try { if (!filterText.isEmpty()) { filter = CQL.toFilter(filterText); } } catch (CQLException e) { ConsoleManager.getInstance().exception(this, e); } } return filter; }
Example 19
Source File: ExtractTimeFilterVisitorTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testAfter() throws CQLException, ParseException { final ExtractTimeFilterVisitor visitor = new ExtractTimeFilterVisitor(); final Date time = DateUtilities.parseISO("2005-05-19T20:32:56Z"); final Filter filter = CQL.toFilter("when after 2005-05-19T20:32:56Z"); final Query query = new Query("type", filter); TemporalConstraints range = (TemporalConstraints) query.getFilter().accept(visitor, null); assertNotNull(range); assertEquals(new Date(time.getTime() + 1), range.getStartRange().getStartTime()); range = (TemporalConstraints) query.getFilter().accept(visitorWithDescriptor, null); assertNotNull(range); assertEquals(new Date(time.getTime() + 1), range.getStartRange().getStartTime()); assertEquals("when", range.getName()); }
Example 20
Source File: SceneFeatureIteratorTest.java From geowave with Apache License 2.0 | 4 votes |
public void testIterate(final String providerName) throws IOException, CQLException, ParseException, NoSuchAuthorityCodeException, FactoryException, MalformedURLException, GeneralSecurityException { final Sentinel2ImageryProvider provider = Sentinel2ImageryProvider.getProvider(providerName); if (provider == null) { throw new RuntimeException("Unable to find '" + providerName + "' Sentinel2 provider"); } final String collection = provider.collections()[0]; final String platform = ""; final String location = "T30TWM"; final Date startDate = DateUtilities.parseISO("2018-01-28T00:00:00Z"); final Date endDate = DateUtilities.parseISO("2018-01-30T00:00:00Z"); final int orbitNumber = 0; final int relativeOrbitNumber = 0; final Filter cqlFilter = CQL.toFilter("BBOX(shape,-1.8274,42.3253,-1.6256,42.4735)"); final String workspaceDir = Tests.WORKSPACE_DIR; final List<SimpleFeature> features = new ArrayList<>(); try (SceneFeatureIterator iterator = new SceneFeatureIterator( providerName, collection, platform, location, startDate, endDate, orbitNumber, relativeOrbitNumber, cqlFilter, workspaceDir)) { while (iterator.hasNext()) { features.add(iterator.next()); } } assertEquals(features.size(), 1); assertThat( features, everyItem( allOf( hasProperties(), inBounds( new Envelope2D( new DirectPosition2D(-1.828, 42.325), new DirectPosition2D(-1.624, 42.474)))))); }