Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureStore


        final File shapeDir = Files.createTempDir();
        File shapeFile = new File(shapeDir, shpName + ".shp");
        LOG.debug("writing out shapefile {}", shapeFile);
        ShapefileDataStore outStore = new ShapefileDataStore(shapeFile.toURI().toURL());
        outStore.createSchema(contourSchema);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) outStore.getFeatureSource();
        featureStore.addFeatures(contourFeatures);
        shapeDir.deleteOnExit(); // Note: the order is important
        for (File f : shapeDir.listFiles())
            f.deleteOnExit();
        /* Zip up the shapefile components */
        StreamingOutput output = new DirectoryZipper(shapeDir);
View Full Code Here


        ShapefileDataStore outStore = new ShapefileDataStore(shapeFile.toURI().toURL());
        outStore.createSchema(contourSchema);
        /* "FeatureSource is used to read features, the subclass FeatureStore is used for
         * read/write access. The way to tell if a File can be written to in GeoTools is to use an
         * instanceof check. */
        SimpleFeatureStore featureStore = (SimpleFeatureStore) outStore.getFeatureSource();
        featureStore.addFeatures(contourFeatures);
        // close?
        shapeDir.deleteOnExit(); // Note: the order is important
        for (File f : shapeDir.listFiles())
            f.deleteOnExit();
        /* Zip up the shapefile components */ 
View Full Code Here

        testMultiVersionSupport(transaction);
    }

    private void testMultiVersionSupport(final Transaction transaction) throws IOException {
        final int initialCount = 8;// as per TestData.insertData
        SimpleFeatureStore storeDefault;
        SimpleFeatureStore storeV1;
        SimpleFeatureStore storeV2;

        storeDefault = store(defaultVersionDataStore, typeName, transaction);
        storeV1 = store(version1DataStore, typeName, transaction);
        storeV2 = store(version2DataStore, typeName, transaction);
View Full Code Here

        return store.getCount(Query.ALL);
    }

    private SimpleFeatureStore store(final DataStore ds, final String typeName,
            final Transaction transaction) throws IOException {
        SimpleFeatureStore store;
        store = (SimpleFeatureStore) ds.getFeatureSource(typeName);
        store.setTransaction(transaction);
        return store;
    }
View Full Code Here

    private List<FeatureId> testFeatureStore(final String tableName, final Transaction transaction)
            throws IOException, UnavailableConnectionException {
        testData.truncateTestTable(tableName);

        SimpleFeatureStore store;
        store = (SimpleFeatureStore) ds.getFeatureSource(tableName);
        assertNotNull(store);

        store.setTransaction(transaction);

        SimpleFeatureType schema = store.getSchema();
        assertNotNull(schema);

        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
        if (schema.getDescriptor("ROW_ID") != null) {
            // it's user managed...
            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());
        return fids;
    }
View Full Code Here

        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);
View Full Code Here

        // is as expected.
        assertEquals(8, origional.getCount(Query.ALL));

        // 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);

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

        SimpleFeatureType schema = origional.getSchema();
        SimpleFeatureBuilder build = new SimpleFeatureBuilder(schema);

        int value = 24;
        build.add(Integer.valueOf(value));
        build.add(Short.valueOf((short) value));
        build.add(new Float(value / 10.0F));
        build.add(new Double(value / 10D));
        build.add("FEATURE_" + value);

        Calendar cal = Calendar.getInstance();
        cal.set(2004, 06, value, 0, 0, 0);
        build.add(cal);

        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());

        FeatureEvent e = listener1.list.get(0);
        Id id = (Id) e.getFilter();
View Full Code Here

        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;
View Full Code Here

        SimpleFeature feature;
        feature = testData.createTestFeatures(LineString.class, featureCount).features().next();

        final DataStore ds = testData.getDataStore();

        SimpleFeatureStore store = (SimpleFeatureStore) ds.getFeatureSource(typeName);

        SimpleFeatureType ftype = store.getSchema();

        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
            // Types.validate throws IllegalArgumentException instead
            assertTrue(true);
View Full Code Here

    public void testModifyFeaturesTransaction() throws Exception {
        testData.insertTestData();

        final String typeName = testData.getTempTableName();
        final DataStore ds = testData.getDataStore();
        final SimpleFeatureStore store;
        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();
        }

        {
            final Transaction transaction = new DefaultTransaction("testModifyFeaturesTransaction");
            store.setTransaction(transaction);

            try {
                final AttributeDescriptor propDescriptor = schema.getDescriptor("INT32_COL");
                store.modifyFeatures(propDescriptor.getName(), Integer.valueOf(-1000),
                        oldValueFilter);
                transaction.commit();
            } catch (Exception e) {
                transaction.rollback();
            } finally {
                transaction.close();
            }
        }
        store.setTransaction(Transaction.AUTO_COMMIT);

        final Query oldValueQuery = new Query(typeName, oldValueFilter);
        final Query newValueQuery = new Query(typeName, newValueFilter);

        assertEquals(0, store.getCount(oldValueQuery));
        assertEquals(1, store.getCount(newValueQuery));

        final SimpleFeatureIterator newFeatures = store.getFeatures(newValueQuery).features();
        final SimpleFeature modifiedFeature;
        try {
            modifiedFeature = newFeatures.next();
        } finally {
            newFeatures.close();
View Full Code Here

TOP

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

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.