Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureCollection


        reader.close();
    }

    private void testFilter(Filter filter, SimpleFeatureSource fsource, int expected)
            throws IOException {
        SimpleFeatureCollection fc = fsource.getFeatures(filter);

        SimpleFeatureIterator fi = fc.features();
        try {
            int numFeat = 0;
            while (fi.hasNext()) {
                fi.next();
                numFeat++;
View Full Code Here


    /**
     * @see FeatureSource#getFeatures(Query)
     */
    public final SimpleFeatureCollection getFeatures(final Query query) throws IOException {
        final Query namedQuery = namedQuery(query);
        SimpleFeatureCollection collection;
        SimpleFeatureType queryType = dataStore.getQueryType(namedQuery);
        collection = new ArcSdeFeatureCollection(this, queryType, namedQuery);
        return collection;
    }
View Full Code Here

        assertEquals(2, fs.getFeatures().size());
        assertNull(fs.getBounds());

        Filter filter = CQL.toFilter("INT_COL = 2000");

        SimpleFeatureCollection features = fs.getFeatures(filter);
        assertNotNull(features);
        assertEquals(1, features.size());
        assertNull(fs.getBounds());

        SimpleFeatureIterator iterator = features.features();
        assertTrue(iterator.hasNext());
        SimpleFeature next = iterator.next();
        assertNotNull(next);
        assertFalse(iterator.hasNext());
        iterator.close();
View Full Code Here

            builder.set("ROW_ID", Integer.valueOf(1000));
        }
        builder.set("INT_COL", Integer.valueOf(1000));
        builder.set("STRING_COL", Integer.valueOf(1000));

        SimpleFeatureCollection fc;
        fc = DataUtilities.collection(builder.buildFeature(null));

        List<FeatureId> fids = store.addFeatures(fc);
        assertNotNull(fids);
        assertEquals(1, fids.size());
View Full Code Here

        // we are going to use this feature source to check that the
        // public Transaction.AUTO_COMMIT view of the world
        // is as expected.
        assertEquals(8, origional.getCount(Query.ALL));
        final SortedSet<String> allFids = new TreeSet<String>();
        SimpleFeatureCollection collection = origional.getFeatures();
        TestProgressListener progress = new TestProgressListener();
        collection.accepts(new FeatureVisitor() {
            public void visit(Feature feature) {
                allFids.add(feature.getIdentifier().getID());
            }
        }, progress);
        assertTrue("visitor completed", progress.completed);
        assertEquals("visitor 100%", 100f, progress.progress);
        assertNull("visitor no problems", progress.exception);

        // we are going to use this transaction to modify and commit
        DefaultTransaction t1 = new DefaultTransaction("Transaction 1");
        SimpleFeatureStore featureStore1 = (SimpleFeatureStore) dataStore
                .getFeatureSource(typeName);
        featureStore1.setTransaction(t1);
        TestFeatureListener listener1 = new TestFeatureListener();
        featureStore1.addFeatureListener(listener1);
        // we are going to use this transaction to modify and rollback
        DefaultTransaction t2 = new DefaultTransaction("Transaction 2");
        SimpleFeatureStore featureStore2 = (SimpleFeatureStore) dataStore
                .getFeatureSource(typeName);
        featureStore2.setTransaction(t2);
        TestFeatureListener listener2 = new TestFeatureListener();
        featureStore2.addFeatureListener(listener2);

        // verify they are all working
        assertEquals(8, origional.getCount(Query.ALL));
        assertEquals(8, featureStore1.getCount(Query.ALL));
        assertEquals(8, featureStore2.getCount(Query.ALL));

        Query queryOneFeature = new Query();
        queryOneFeature.setTypeName(typeName);
        queryOneFeature.setFilter(Filter.INCLUDE);
        queryOneFeature.setMaxFeatures(1);
        queryOneFeature.setPropertyNames(Query.ALL_NAMES);

        collection = featureStore1.getFeatures(queryOneFeature);
        progress.reset();
        final SortedSet<String> fids = new TreeSet<String>();
        collection.accepts(new FeatureVisitor() {
            public void visit(Feature feature) {
                fids.add(feature.getIdentifier().getID());
            }
        }, progress);
        assertTrue("visitor completed", progress.completed);
View Full Code Here

        WKTReader reader = new WKTReader();
        build.add(reader.read("POINT(1 1)"));

        SimpleFeature newFeature = build.buildFeature(null);
        SimpleFeatureCollection newFeatures = DataUtilities.collection(newFeature);

        List<FeatureId> newFids = featureStore1.addFeatures(newFeatures);
        assertEquals(0, listener.list.size());
        assertEquals(1, listener1.list.size());
View Full Code Here

    public void testInsertTransaction() throws Exception {
        // start with an empty table
        testData.truncateTempTable();
        final String typeName = testData.getTempTableName();
        final int featureCount = 2;
        final SimpleFeatureCollection testFeatures;
        testFeatures = testData.createTestFeatures(LineString.class, featureCount);

        final DataStore ds = testData.getDataStore();

        final SimpleFeatureType ftype = testFeatures.getSchema();
        final SimpleFeatureIterator iterator = testFeatures.features();

        final Transaction transaction = new DefaultTransaction();
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
        writer = ds.getFeatureWriter(typeName, transaction);
View Full Code Here

    @Test
    public void testInsertTransactionAndQueryByFid() throws Exception {
        // start with an empty table
        final String typeName = testData.getTempTableName();
        final int featureCount = 2;
        final SimpleFeatureCollection testFeatures;
        testFeatures = testData.createTestFeatures(LineString.class, featureCount);

        final DataStore ds = testData.getDataStore();
        final SimpleFeatureStore fStore;
        fStore = (SimpleFeatureStore) ds.getFeatureSource(typeName);
        final Transaction transaction = new DefaultTransaction("testInsertTransactionAndQueryByFid");
        fStore.setTransaction(transaction);
        try {
            final List<FeatureId> addedFids = fStore.addFeatures(testFeatures);
            final FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

            final Set<FeatureId> fids = new HashSet<FeatureId>();
            for (FeatureId fid : addedFids) {
                fids.add(fid);
            }
            final Id newFidsFilter = ff.id(fids);

            SimpleFeatureCollection features;
            features = fStore.getFeatures(newFidsFilter);
            assertEquals(2, features.size());
            transaction.commit();
        } catch (Exception e) {
            transaction.rollback();
            throw e;
        } finally {
View Full Code Here

        assertFalse(ftype.getDescriptor("INT32_COL").isNillable());

        feature.setAttribute("INT32_COL", null);

        SimpleFeatureCollection collection = DataUtilities.collection(feature);
        try {
            store.addFeatures(collection);
            fail("Expected IAE");
        } catch (IllegalArgumentException e) {
            // note this should really be org.opengis.feature.IllegalAttributeException but
View Full Code Here

        store = (SimpleFeatureStore) ds.getFeatureSource(typeName);
        final SimpleFeatureType schema = store.getSchema();
        final Filter oldValueFilter = CQL.toFilter("INT32_COL = 3");
        final Filter newValueFilter = CQL.toFilter("INT32_COL = -1000");

        SimpleFeatureCollection features = store.getFeatures(oldValueFilter);
        final int initialSize = features.size();
        assertEquals(1, initialSize);// just to not go forward with bad data
        final SimpleFeature originalFeature;
        SimpleFeatureIterator iterator = features.features();
        try {
            originalFeature = iterator.next();
        } finally {
            iterator.close();
        }
View Full Code Here

TOP

Related Classes of org.geotools.data.simple.SimpleFeatureCollection

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.