Package org.opengis.filter

Examples of org.opengis.filter.FilterFactory2


                + "FROM \"road\" "
                + "WHERE  \"geom\".Filter(geometry::STGeomFromText('POLYGON ((2 -1, 2 5, 4 5, 4 -1, 2 -1))', 4326)) = 1 "
                + "AND geometry::STGeomFromText('POLYGON ((2 -1, 2 5, 4 5, 4 -1, 2 -1))', 4326).STContains(\"geom\") = 1");
       
        // the filter for the Query
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        GeometryFactory gf = new GeometryFactory();
        PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
        LinearRing shell = gf.createLinearRing(sf.create(new double[] { 2, -1, 2, 5, 4, 5, 4, -1,
                2, -1 }, 2));
        Polygon polygon = gf.createPolygon(shell, null);
        Contains cs = ff.contains(ff.literal(polygon), ff.property(aname("geom")));

       
        SimpleFeatureType roadSchema = dataStore.getSchema("road");
        dialect.handleSelectHints(sql, roadSchema, new Query("road", cs));
        return sql;
View Full Code Here


        SimpleFeatureIterator indexIter = features.features();

        Set<String> expectedFids = new LinkedHashSet<String>();
        final Filter fidFilter;
        try {
            FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
            Set<FeatureId> fids = new HashSet<FeatureId>();
            while (indexIter.hasNext()) {
                SimpleFeature newFeature = indexIter.next();
                String id = newFeature.getID();
                expectedFids.add(id);
                fids.add(ff.featureId(id));
            }
            fidFilter = ff.id(fids);
        } finally {
            indexIter.close();
        }

        Set<String> actualFids = new HashSet<String>();
View Full Code Here

                "SELECT \"fid\",\"id\",\"geom\".STAsBinary() as \"geom\",\"name\" "
                        + "FROM \"road\" "
                        + "WHERE \"name\" = 'XXX')");

        // the filter for the Query
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        Filter filter = ff.equal(ff.property("name"), ff.literal("XXX"), true);

        SimpleFeatureType roadSchema = dataStore.getSchema("road");
        dialect.handleSelectHints(sql, roadSchema, new Query("road", filter));

        assertFalse(sql.toString().contains("WITH"));
View Full Code Here

            ShapefileDataStore baselineDS, ReferencedEnvelope newBounds)
            throws FactoryRegistryException, IllegalFilterException,
            IOException {
        SimpleFeatureCollection features;
        SimpleFeatureIterator indexIter;
        FilterFactory2 fac = CommonFactoryFinder.getFilterFactory2(null);
        String geometryName = indexedDS.getSchema().getGeometryDescriptor()
                .getLocalName();

        Filter filter = fac.bbox(fac.property(geometryName), newBounds);

        features = indexedDS.getFeatureSource().getFeatures(filter);
        SimpleFeatureCollection features2 = baselineDS.getFeatureSource()
                .getFeatures(filter);
View Full Code Here

            assertFalse(features.isEmpty());

           
            // execute Query that returns all features
           
            FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
            SimpleFeatureType schema = featureSource.getSchema();
            String geomName = schema.getGeometryDescriptor().getName().getLocalPart();
           
            Query query = new Query(schema.getTypeName());
            query.setPropertyNames(Query.ALL_NAMES);           
            ReferencedEnvelope bounds = features.getBounds();
            query.setFilter(ff.bbox(ff.property(geomName), bounds));

            features = featureSource.getFeatures(query);
            // check SimpleFeatureCollection size
            assertEquals(count, features.size());
            assertFalse(features.isEmpty());

           
            // execute Query that doesn't return any feature
           
            bounds = new ReferencedEnvelope(bounds.getMaxX() + 1, bounds.getMaxX() + 2,
                    bounds.getMaxY() + 1, bounds.getMaxY() + 2, bounds.getCoordinateReferenceSystem());
            query.setFilter(ff.bbox(ff.property(geomName), bounds));           

            features = featureSource.getFeatures(query);
            // check SimpleFeatureCollection size
            assertEquals(0, features.size());
            assertTrue(features.isEmpty());
View Full Code Here

        StringBuffer sql = new StringBuffer(
                "SELECT \"fid\",\"id\",\"geom\".STAsBinary() as \"geom\",\"name\" "
                        + "FROM \"road\" " + "WHERE \"name\" = 'XXX')");

        // the filter for the Query
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        Filter filter = ff.equal(ff.property("name"), ff.literal("XXX"), true);

        SimpleFeatureType roadSchema = dataStore.getSchema("road");
        dialect.handleSelectHints(sql, roadSchema, new Query("road", filter));

        assertTrue(sql.toString().contains("WITH(NOLOCK)"));
View Full Code Here

            validFid2 = features.next().getID();
            invalidFid1 = "_" + features.next().getID();
            invalidFid2 = features.next().getID() + "abc";
            features.close();
        }
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        Set<Identifier> ids = new HashSet<Identifier>();
        ids.add(ff.featureId(validFid1));
        ids.add(ff.featureId(validFid2));
        ids.add(ff.featureId(invalidFid1));
        ids.add(ff.featureId(invalidFid2));
        Filter fidFilter = ff.id(ids);

        final SimpleFeatureType schema = store.getSchema();
        final String typeName = schema.getTypeName();
        //get a property of type String to update its value by the given filter
        final AttributeDescriptor attribute = schema.getDescriptor("f");
       
        assertEquals(2, count(ds, typeName, fidFilter));

        store.modifyFeatures(attribute, "modified", fidFilter);
        Filter modifiedFilter = ff.equals(ff.property("f"), ff.literal("modified"));
        assertEquals(2, count(ds, typeName, modifiedFilter));
       
        final int initialCount = store.getCount(Query.ALL);
        store.removeFeatures(fidFilter);
        final int afterCount = store.getCount(Query.ALL);
View Full Code Here

                "SELECT \"fid\",\"id\",\"geom\".STAsBinary() as \"geom\",\"name\" "
                        + "FROM \"schema\".\"road\" "
                        + "WHERE \"name\" = 'XXX')");

        // the filter for the Query
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        Filter filter = ff.equal(ff.property("name"), ff.literal("XXX"), true);

        SimpleFeatureType roadSchema = dataStore.getSchema("road");
        originalSchema = dataStore.getDatabaseSchema();
        dataStore.setDatabaseSchema("schema");
        dialect.handleSelectHints(sql, roadSchema, new Query("road", filter));
View Full Code Here

    private void performSpatialQuery(ShapefileDataStore ds) throws IOException {
        SimpleFeatureSource featureSource = ds.getFeatureSource();
        SimpleFeatureType schema = featureSource.getSchema();
        Query query = new Query( schema.getTypeName() );
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
        String geomName = schema.getGeometryDescriptor().getName().getLocalPart();
        ReferencedEnvelope bounds = featureSource.getBounds();
        bounds.expandBy(-bounds.getWidth() / 2, -bounds.getHeight() / 2);
        query.setFilter( ff.bbox( ff.property(geomName), bounds) );
        SimpleFeatureCollection features = featureSource.getFeatures( query );
        SimpleFeatureIterator iterator = features.features();
        try {
            iterator.next();
        } finally {
View Full Code Here

        Object result = resultMap.get(BufferFactory.RESULT.key);
        Geometry bufferedGeom = geom1.buffer(buffer);
    }

    public static void example3() {
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName("featureType");
        tb.add("geometry", Point.class);
        tb.add("integer", Integer.class);

        GeometryFactory gf = new GeometryFactory();
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType());

        DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType());
        for (int i = 0; i < 2; i++) {
            b.add(gf.createPoint(new Coordinate(i, i)));
            b.add(i);
            features.add(b.buildFeature(i + ""));
        }

        Map<String, Object> input = new HashMap();
        input.put(BufferFeatureCollectionFactory.FEATURES.key, features);
        input.put(BufferFeatureCollectionFactory.BUFFER.key, 10d);

        BufferFeatureCollectionFactory factory = new BufferFeatureCollectionFactory();
        BufferFeatureCollectionProcess process = factory.create();
        Map<String, Object> output = process.execute(input, null);

        FeatureCollection buffered = (FeatureCollection) output
                .get(BufferFeatureCollectionFactory.RESULT.key);

        assertEquals(2, buffered.size());
        for (int i = 0; i < 2; i++) {
            Geometry expected = gf.createPoint(new Coordinate(i, i)).buffer(10d);
            FeatureCollection sub = buffered.subCollection(ff.equals(ff.property("integer"),
                    ff.literal(i)));
            assertEquals(1, sub.size());
            FeatureIterator iterator = sub.features();
            SimpleFeature sf = (SimpleFeature) iterator.next();
            assertTrue(expected.equals((Geometry) sf.getDefaultGeometry()));
            iterator.close();
View Full Code Here

TOP

Related Classes of org.opengis.filter.FilterFactory2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.