Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureCollection


            transaction.close();
        }
        store.setTransaction(Transaction.AUTO_COMMIT);

        try {
            SimpleFeatureCollection features;
            SimpleFeatureIterator iterator;

            features = store.getFeatures(fid1Filter);
            iterator = features.features();
            final SimpleFeature feature1 = iterator.next();
            iterator.close();

            features = store.getFeatures(fid2Filter);
            iterator = features.features();
            final SimpleFeature feature2 = iterator.next();
            iterator.close();

            // Note that for tables that are ambiguous about what types of geometries
            // they store (as this table is), ArcSDE will "compress" a stored geometry
View Full Code Here


     *
     */
    private void testInsertAutoCommit(Class<? extends Geometry> geometryClass) throws Exception {
        final String typeName = testData.getTempTableName();
        final int insertCount = 2;
        final SimpleFeatureCollection testFeatures;
        testFeatures = testData.createTestFeatures(geometryClass, insertCount);

        final DataStore ds = testData.getDataStore();
        final SimpleFeatureSource fsource = ds.getFeatureSource(typeName);

        // incremented on each feature added event to
        // ensure events are being raised as expected
        // (the count is wraped inside an array to be able of declaring
        // the variable as final and accessing it from inside the anonymous
        // inner class)
        /*
         * final int[] featureAddedEventCount = { 0 };
         *
         * fsource.addFeatureListener(new FeatureListener() { public void changed(FeatureEvent evt)
         * { if (evt.getEventType() != FeatureEvent.FEATURES_ADDED) { throw new
         * IllegalArgumentException( "Expected FEATURES_ADDED event, got " + evt.getEventType()); }
         *
         * ++featureAddedEventCount[0]; } });
         */

        final int initialCount = fsource.getCount(Query.ALL);

        FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriterAppend(
                typeName, Transaction.AUTO_COMMIT);

        SimpleFeature source;
        SimpleFeature dest;

        try {
            for (SimpleFeatureIterator fi = testFeatures.features(); fi.hasNext();) {
                source = fi.next();
                dest = writer.next();
                dest.setAttributes(source.getAttributes());
                writer.write();
            }
        } finally {
            writer.close();
        }

        // was the features really inserted?
        int fcount = fsource.getCount(Query.ALL);
        assertEquals(testFeatures.size() + initialCount, fcount);

        /*
         * String msg = "a FEATURES_ADDED event should have been called " + features.size() + "
         * times"; assertEquals(msg, features.size(), featureAddedEventCount[0]);
         */
 
View Full Code Here

        final DataStore ds = testData.getDataStore();
        final SimpleFeatureSource fsource = ds.getFeatureSource(typeName);

        final int initialCount = fsource.getCount(Query.ALL);
        final int writeCount = initialCount + 2;
        final SimpleFeatureCollection testFeatures = testData.createTestFeatures(LineString.class,
                writeCount);

        // incremented on each feature added event to
        // ensure events are being raised as expected
        // (the count is wraped inside an array to be able of declaring
        // the variable as final and accessing it from inside the anonymous
        // inner class)
        // final int[] featureAddedEventCount = { 0 };

        final Transaction transaction = new DefaultTransaction();
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriter(
                typeName, Filter.INCLUDE, transaction);

        SimpleFeature source;
        SimpleFeature dest;

        int count = 0;
        try {
            for (SimpleFeatureIterator fi = testFeatures.features(); fi.hasNext(); count++) {
                if (count < initialCount) {
                    assertTrue("at index " + count, writer.hasNext());
                } else {
                    assertFalse("at index " + count, writer.hasNext());
                }
View Full Code Here

        // the table populated here is test friendly since it can hold
        // any kind of geometries.
        testData.insertTestData();

        final String typeName = testData.getTempTableName();
        final SimpleFeatureCollection testFeatures = testData.createTestFeatures(LineString.class,
                2);

        final DataStore ds = testData.getDataStore();
        final SimpleFeatureSource fsource = ds.getFeatureSource(typeName);
        final int initialCount = fsource.getCount(Query.ALL);

        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriterAppend(
                typeName, Transaction.AUTO_COMMIT);

        SimpleFeature source;
        SimpleFeature dest;

        for (SimpleFeatureIterator fi = testFeatures.features(); fi.hasNext();) {
            assertFalse(writer.hasNext());
            source = fi.next();
            dest = writer.next();
            dest.setAttributes(source.getAttributes());
            writer.write();
        }

        writer.close();

        // were the features really inserted?
        int fcount = fsource.getCount(Query.ALL);
        assertEquals(testFeatures.size() + initialCount, fcount);
    }
View Full Code Here

            // now confirm for that transaction the feature is fetched, and outside
            // it it's not.
            final Filter filterNewFeature = CQL.toFilter("INT32_COL = 1000");
            final Query newFeatureQuery = new Query(typeName, filterNewFeature);

            SimpleFeatureCollection features;
            features = transFs.getFeatures(filterNewFeature);
            int size = features.size();
            assertEquals(1, size);

            // ok transaction respected, assert the feature does not exist outside
            // it (except is the db is MS SQL Server)
            {
View Full Code Here

    }

    @Test
    public void testSetFeaturesAutoCommit() throws Exception {
        testData.insertTestData();
        final SimpleFeatureCollection featuresToSet = testData.createTestFeatures(Point.class, 5);
        final DataStore ds = testData.getDataStore();
        final String typeName = testData.getTempTableName();

        final SimpleFeatureStore store;
        store = (SimpleFeatureStore) ds.getFeatureSource(typeName);
View Full Code Here

    }

    @Test
    public void testSetFeaturesTransaction() throws Exception {
        testData.insertTestData();
        final SimpleFeatureCollection featuresToSet = testData.createTestFeatures(Point.class, 5);
        final DataStore ds = testData.getDataStore();
        final String typeName = testData.getTempTableName();

        final Transaction transaction = new DefaultTransaction("testSetFeaturesTransaction handle");
        final SimpleFeatureStore store;
View Full Code Here

    public void testAttributesWritingSqliteWithSorting() throws Exception {
        if (!ogrSupports("SQLite")) {
            System.out.println("Skipping SQLite writing test as OGR was not built to support it");

        }
        SimpleFeatureCollection features = createFeatureCollection();
        File tmpFile = getTempFile("test-sql", ".sqlite");
        tmpFile.delete();
        OGRDataStore s = new OGRDataStore(tmpFile.getAbsolutePath(), "SQLite", null, ogr);
        s.createSchema(features, true, null);
        assertEquals(1, s.getTypeNames().length);
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Query query = new Query();
        query.setSortBy(new org.opengis.filter.sort.SortBy[] {
            ff.sort("f", org.opengis.filter.sort.SortOrder.ASCENDING)
        });
        SimpleFeatureCollection fc = s.getFeatureSource("junk").getFeatures(query);
        assertEquals(features.size(), fc.size());
        // Read
        int c = 0;
        SimpleFeatureIterator it = fc.features();
        try {
            while (it.hasNext()) {
                SimpleFeature f = it.next();
                assertNotNull(f);
                assertNotNull(f.getDefaultGeometry());
                c++;
            }
        } finally {
            it.close();
        }
        assertEquals(fc.size(), c);
    }
View Full Code Here

    public void testAttributesWritingSqliteFromUpperCaseAttributes() throws Exception {
        if(!ogrSupports("SQLite")) {
            System.out.println("Skipping SQLite writing test as OGR was not built to support it");
        }
        SimpleFeatureCollection features = createFeatureCollectionWithUpperCaseAttributes();
        File tmpFile = getTempFile("test-sqlite", ".db");
        tmpFile.delete();
        OGRDataStore s = new OGRDataStore(tmpFile.getAbsolutePath(), "SQLite", null, ogr);
        s.createSchema(features, true, null);
        assertEquals(1, s.getTypeNames().length);
        SimpleFeatureCollection fc = s.getFeatureSource("points").getFeatures();
        assertEquals(features.size(), fc.size());
        // Read
        int c = 0;
        SimpleFeatureIterator it = fc.features();
        try {
            while(it.hasNext()) {
                SimpleFeature f = it.next();
                assertNotNull(f);
                assertNotNull(f.getDefaultGeometry());
                assertNotNull(f.getAttribute("name"));
                c++;
            }
        } finally {
            it.close();
        }
        assertEquals(fc.size(), c);
    }
View Full Code Here

        store.registerView(InProcessViewSupportTestData.typeName, (PlainSelect) select);

        SimpleFeatureSource fs = store.getFeatureSource(InProcessViewSupportTestData.typeName);

        Query query = new Query(InProcessViewSupportTestData.typeName, Filter.INCLUDE, Query.ALL_PROPERTIES);
        SimpleFeatureCollection fc = fs.getFeatures(query);
        int fcCount = fc.size();
        int itCount = 0;
        final int expectedCount = 7;
        SimpleFeatureIterator it = fc.features();
        try {
            while (it.hasNext()) {
                SimpleFeature f = (SimpleFeature) it.next();
                assertNotNull(f);
                itCount++;
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.