Package org.geotools.feature

Examples of org.geotools.feature.DefaultFeatureCollection


    public void testAddFeaturesUseProvidedFid() throws IOException {
        // check we advertise the ability to reuse feature ids
        assertTrue(featureStore.getQueryCapabilities().isUseProvidedFIDSupported());
       
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
        DefaultFeatureCollection collection = new DefaultFeatureCollection(null,
                featureStore.getSchema());
       
        String typeName = b.getFeatureType().getTypeName();
        for (int i = 3; i < 6; i++) {
            b.set(aname("intProperty"), new Integer(i));
            b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i)));
            b.featureUserData(Hints.USE_PROVIDED_FID, Boolean.TRUE);
            collection.add(b.buildFeature(typeName + "." + (i * 10)));
        }
        List<FeatureId> fids = featureStore.addFeatures((SimpleFeatureCollection)collection);
       
        assertEquals(3, fids.size());
        assertTrue(fids.contains(SimpleFeatureBuilder.createDefaultFeatureIdentifier(typeName + ".30")));
View Full Code Here


        }
    }
   
    public void testAddInTransaction() throws IOException {
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
        DefaultFeatureCollection collection = new DefaultFeatureCollection(null,
                featureStore.getSchema());
       
        b.set(aname("intProperty"), new Integer(3));
        b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(3, 3)));
        collection.add(b.buildFeature(null));

        FeatureEventWatcher watcher = new FeatureEventWatcher();
        Transaction t = new DefaultTransaction();
        featureStore.setTransaction(t);
        featureStore.addFeatureListener(watcher);
View Full Code Here

        t.close();
    }
   
    public void testExternalConnection() throws IOException, SQLException {
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
        DefaultFeatureCollection collection = new DefaultFeatureCollection(null,
                featureStore.getSchema());
       
        b.set(aname("intProperty"), new Integer(3));
        b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(3, 3)));
        collection.add(b.buildFeature(null));

        FeatureEventWatcher watcher = new FeatureEventWatcher();
       
        Connection conn = setup.getDataSource().getConnection();
        conn.setAutoCommit(false);
View Full Code Here

        featureStore.modifyFeatures(attributeNames, nulls, Filter.INCLUDE);
    }

    public void testSetFeatures() throws IOException {
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
        DefaultFeatureCollection collection = new DefaultFeatureCollection(null,
                featureStore.getSchema());

        for (int i = 3; i < 6; i++) {
            b.set(aname("intProperty"), new Integer(i));
            b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i)));
            collection.add(b.buildFeature(null));
        }

        FeatureReader<SimpleFeatureType, SimpleFeature> reader = new CollectionFeatureReader((SimpleFeatureCollection)collection, collection.getSchema());
        featureStore.setFeatures(reader);

        SimpleFeatureCollection features = featureStore.getFeatures();
        assertEquals(3, features.size());
View Full Code Here

    FeatureCollectionType fc;
   
    @Override
    protected void setUp() throws Exception {
        fc = WfsFactory.eINSTANCE.createFeatureCollectionType();
        DefaultFeatureCollection features = new DefaultFeatureCollection();
       
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName( "feature" );
        tb.setNamespaceURI( "http://geotools.org");
        tb.add( "geometry", Point.class );
        tb.add( "integer", Integer.class );
       
        SimpleFeatureBuilder b = new SimpleFeatureBuilder( tb.buildFeatureType() );
        b.add( new GeometryFactory().createPoint( new Coordinate( 0, 0 ) ) );
        b.add( 0 );
        features.add( b.buildFeature( "zero" ) );
       
        b.add( new GeometryFactory().createPoint( new Coordinate( 1, 1 ) ) );
        b.add( 1 );
        features.add( b.buildFeature( "one" ) );
       
        fc.getFeature().add( features );
    }
View Full Code Here

        assertEquals( 2, d.getElementsByTagName( "geotools:feature" ).getLength() );
        assertNotNull( ((Element)d.getElementsByTagName( "geotools:feature").item( 0 )).getAttribute("gml:id") );
    }
   
    public void testEncodeFeatureCollectionMultipleFeatureTypes() throws Exception {
        DefaultFeatureCollection features = new DefaultFeatureCollection();
       
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName( "feature2" );
        tb.setNamespaceURI( "http://geotools.org/geotools2");
        tb.add( "geometry", Point.class );
        tb.add( "integer", Integer.class );
       
        SimpleFeatureBuilder b = new SimpleFeatureBuilder( tb.buildFeatureType() );
        b.add( new GeometryFactory().createPoint( new Coordinate( 0, 0 ) ) );
        b.add( 0 );
        features.add( b.buildFeature( "zero" ) );
       
        b.add( new GeometryFactory().createPoint( new Coordinate( 1, 1 ) ) );
        b.add( 1 );
        features.add( b.buildFeature( "one" ) );
       
        fc.getFeature().add( features );
       
        Encoder e = new Encoder( new org.geotools.wfs.v1_1.WFSConfiguration() );
        e.getNamespaces().declarePrefix( "geotools", "http://geotools.org");
View Full Code Here

        SimpleFeatureStore st = (SimpleFeatureStore) dataStore.getFeatureSource( tname("ft1") );
       
        SimpleFeatureBuilder b = new SimpleFeatureBuilder(st.getSchema());
        b.set(aname("intProperty"), new Integer(100));
        SimpleFeature f1 = b.buildFeature(null);
        DefaultFeatureCollection features = new DefaultFeatureCollection(null,null);
        features.add( f1 );

        Transaction tx1 = new DefaultTransaction();
        st.setTransaction(tx1);
        st.addFeatures( features );
        tx1.commit();
View Full Code Here

        float scale = 100f / features.size();
        monitor.started();
       
        //create the result feature collection
        SimpleFeatureType targetSchema = getTargetSchema((SimpleFeatureType) features.getSchema(), input);
        DefaultFeatureCollection result = new DefaultFeatureCollection(null, targetSchema);

        SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) result.getSchema());
        FeatureIterator fi = features.features();
        try {
            int counter = 0;
            while( fi.hasNext() ) {
                //copy the feature
                fb.init((SimpleFeature) fi.next());
                SimpleFeature feature = fb.buildFeature(null);
               
                //buffer the geometry
                try {
                    processFeature( feature, input );
                }
                catch( Exception e ) {
                    monitor.exceptionOccurred( e );
                }
               
                monitor.progress( scale * counter++);
                result.add( feature );   
            }
        }
        finally {
            fi.close();
        }
View Full Code Here

        DataStore store = DataStoreFinder.getDataStore(params);

        final SimpleFeatureType type = store.getSchema("example");
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
        SimpleFeature f;
        DefaultFeatureCollection collection = new DefaultFeatureCollection();
        f = SimpleFeatureBuilder
                .build(type, new Object[] { 1, "jody" }, "fid1");
        collection.add(f);
        f = SimpleFeatureBuilder.build(type, new Object[] { 2, "brent" },
                "fid3");
        collection.add(f);
        f = SimpleFeatureBuilder
                .build(type, new Object[] { 3, "dave" }, "fid3");
        collection.add(f);
        f = SimpleFeatureBuilder.build(type, new Object[] { 4, "justin" },
                "fid4");
        collection.add(f);

        writer = store.getFeatureWriter("road", Transaction.AUTO_COMMIT);
        try {
            // remove all features
            while (writer.hasNext()) {
                writer.next();
                writer.remove();
            }
            // copy new features in
            SimpleFeatureIterator iterator = collection.features();
            while (iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                SimpleFeature newFeature = writer.next(); // new blank feature
                newFeature.setAttributes(feature.getAttributes());
                writer.write();
View Full Code Here

    @Test
    public void testEncodeGML2Legacy() throws Exception {
        SimpleFeatureType TYPE = DataUtilities.createType("Location", "geom:Point,name:String");

        DefaultFeatureCollection collection = new DefaultFeatureCollection();
        WKTReader2 wkt = new WKTReader2();

        collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT (1 2)"),
                "name1" }, null));
        collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT (4 4)"),
                "name2" }, null));

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GML encode = new GML(Version.GML2);
        encode.setNamespace("Location", "http://localhost/Location.xsd");
View Full Code Here

TOP

Related Classes of org.geotools.feature.DefaultFeatureCollection

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.