Search in sources :

Example 11 with PropertyIsEqualTo

use of org.opengis.filter.PropertyIsEqualTo in project polymap4-core by Polymap4.

the class FilterTest method visiblePoint.

@Test
public void visiblePoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    assertTrue(point.visibleIf.get() instanceof ConstantFilter);
    point.visibleIf.createValue(initializeFilter(ff.equals(ff.property("prop"), ff.literal("literal"))));
    point.diameter.createValue(ConstantNumber.defaults(23.0));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    org.geotools.styling.Style style = repo.serializedFeatureStyle(fs.id(), org.geotools.styling.Style.class).get();
    Rule rule = style.featureTypeStyles().get(0).rules().get(0);
    assertTrue(rule.getFilter() instanceof PropertyIsEqualTo);
    PropertyIsEqualTo filter = (PropertyIsEqualTo) rule.getFilter();
    assertTrue(filter.getExpression1() instanceof PropertyName);
    assertEquals("prop", ((PropertyName) filter.getExpression1()).getPropertyName());
    assertTrue(filter.getExpression2() instanceof Literal);
    assertEquals("literal", ((Literal) filter.getExpression2()).getValue());
    PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
    assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Literal(org.opengis.filter.expression.Literal) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 12 with PropertyIsEqualTo

use of org.opengis.filter.PropertyIsEqualTo in project coastal-hazards by USGS-CIDA.

the class FeatureCollectionExportTest method splitterTest.

@Test
// for now
@Ignore
public void splitterTest() throws Exception {
    // get geometry
    HttpComponentsWFSClient wfs1 = new HttpComponentsWFSClient();
    wfs1.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
    FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    PropertyIsEqualTo equals = filterFactory.equals(filterFactory.property("STATEFP"), filterFactory.literal(37));
    SimpleFeatureCollection featureCollection = wfs1.getFeatureCollection("splitter:tl_2013_coastal_states", equals);
    SimpleFeatureIterator features = featureCollection.features();
    // only deal with one
    Geometry geom = null;
    if (features.hasNext()) {
        SimpleFeature next = features.next();
        geom = (Geometry) next.getDefaultGeometry();
    }
    // then use geometry as filter
    HttpComponentsWFSClient wfs2 = new HttpComponentsWFSClient();
    wfs2.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
    FilterFactory2 filterFactory2 = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    Contains contains = filterFactory2.contains(filterFactory2.property("the_geom"), filterFactory2.literal(geom));
    SimpleFeatureCollection featureCollection2 = wfs2.getFeatureCollection("proxied:atl_cvi", contains);
    SimpleFeatureType schema = GMLStreamingFeatureCollection.unwrapSchema(featureCollection2.getSchema());
    FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
    Map datastoreConfig = new HashMap<>();
    datastoreConfig.put("url", FileUtils.getFile(FileUtils.getTempDirectory(), "splitter.shp").toURI().toURL());
    ShapefileDataStore shpfileDataStore = (ShapefileDataStore) factory.createNewDataStore(datastoreConfig);
    shpfileDataStore.createSchema(schema);
    shpfileDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
    SimpleFeatureStore featureStore = (SimpleFeatureStore) shpfileDataStore.getFeatureSource();
    Transaction t = new DefaultTransaction();
    // Copied directly from Import process
    featureStore.setTransaction(t);
    Query query = new Query();
    query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
    SimpleFeatureIterator fi = featureCollection2.features();
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
    while (fi.hasNext()) {
        SimpleFeature source = fi.next();
        fb.reset();
        for (AttributeDescriptor desc : schema.getAttributeDescriptors()) {
            fb.set(desc.getName(), source.getAttribute(desc.getName()));
        }
        SimpleFeature target = fb.buildFeature(null);
        target.setDefaultGeometry(source.getDefaultGeometry());
        featureStore.addFeatures(DataUtilities.collection(target));
    }
    t.commit();
    t.close();
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Query(org.geotools.data.Query) HashMap(java.util.HashMap) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(com.vividsolutions.jts.geom.Geometry) FileDataStoreFactorySpi(org.geotools.data.FileDataStoreFactorySpi) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) Contains(org.opengis.filter.spatial.Contains) FilterFactory2(org.opengis.filter.FilterFactory2) HashMap(java.util.HashMap) Map(java.util.Map) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with PropertyIsEqualTo

use of org.opengis.filter.PropertyIsEqualTo in project ddf by codice.

the class OpenSearchFilterVisitorTest method testPropertyEqualToNotIdAttribute.

@Test
public void testPropertyEqualToNotIdAttribute() {
    PropertyIsEqualTo propertyIsEqualToFilter = (PropertyIsEqualTo) geotoolsFilterBuilder.attribute("not id attribute").is().equalTo().text(TEST_STRING);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(propertyIsEqualToFilter, openSearchFilterVisitorObject);
    assertThat(result.getId(), is(nullValue()));
}
Also used : PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Test(org.junit.Test)

Example 14 with PropertyIsEqualTo

use of org.opengis.filter.PropertyIsEqualTo in project ddf by codice.

the class OpenSearchFilterVisitorTest method testPropertyIsEqualToLiteral.

@Test
public void testPropertyIsEqualToLiteral() {
    PropertyIsEqualTo propertyIsEqualToLiteralFilter = new PropertyIsEqualToLiteral(new PropertyNameImpl(ID_ATTRIBUTE_NAME), new LiteralImpl(TEST_STRING));
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(propertyIsEqualToLiteralFilter, openSearchFilterVisitorObject);
    assertThat(result.getId(), is(TEST_STRING));
}
Also used : LiteralImpl(ddf.catalog.filter.impl.LiteralImpl) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) Test(org.junit.Test)

Example 15 with PropertyIsEqualTo

use of org.opengis.filter.PropertyIsEqualTo in project ddf by codice.

the class OpenSearchFilterVisitorTest method testPropertyEqualTo.

@Test
public void testPropertyEqualTo() {
    PropertyIsEqualTo propertyIsEqualToFilter = (PropertyIsEqualTo) geotoolsFilterBuilder.attribute(ID_ATTRIBUTE_NAME).is().equalTo().text(TEST_STRING);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(propertyIsEqualToFilter, openSearchFilterVisitorObject);
    assertThat(result.getId(), is(TEST_STRING));
}
Also used : PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Test(org.junit.Test)

Aggregations

PropertyIsEqualTo (org.opengis.filter.PropertyIsEqualTo)18 Test (org.junit.Test)15 Expression (org.opengis.filter.expression.Expression)7 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)6 Filter (org.opengis.filter.Filter)5 Literal (org.opengis.filter.expression.Literal)4 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 Function (org.opengis.filter.expression.Function)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 FilterDelegate (ddf.catalog.filter.FilterDelegate)1 LiteralImpl (ddf.catalog.filter.impl.LiteralImpl)1 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)1 PropertyNameImpl (ddf.catalog.filter.impl.PropertyNameImpl)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1