Examples of FeatureWriter


Examples of org.geotools.data.FeatureWriter

    public void testUpdate() throws Exception {
        if (!isGeographySupportAvailable()) {
            return;
        }

        FeatureWriter fw = dataStore.getFeatureWriter(tname("geopoint"), Transaction.AUTO_COMMIT);

        Point p = gf.createPoint(new Coordinate(1, 1));

        assertTrue(fw.hasNext());
        while (fw.hasNext()) {
            SimpleFeature f = (SimpleFeature) fw.next();
            f.setDefaultGeometry(p);
            fw.write();
        }
        fw.close();

        FeatureReader fr = dataStore.getFeatureReader(new Query(tname("geopoint")),
                Transaction.AUTO_COMMIT);
        while (fr.hasNext()) {
            SimpleFeature f = (SimpleFeature) fr.next();
View Full Code Here

Examples of org.geotools.data.FeatureWriter

    public void testAppend() throws Exception {
        if (!isGeographySupportAvailable()) {
            return;
        }

        FeatureWriter fw = dataStore.getFeatureWriterAppend(tname("geopoint"),
                Transaction.AUTO_COMMIT);

        assertFalse(fw.hasNext());
        SimpleFeature f = (SimpleFeature) fw.next();

        Point point = gf.createPoint(new Coordinate(10, 10));
        f.setAttribute("name", "append");
        f.setDefaultGeometry(point);

        fw.write();
        fw.close();

        Filter filter = ff.equals(ff.property("name"), ff.literal("append"));
        Query q = new Query(tname("geopoint"), filter);

        FeatureReader fr = dataStore.getFeatureReader(q, Transaction.AUTO_COMMIT);
View Full Code Here

Examples of org.geotools.data.FeatureWriter

        // -- Distance calculation using GEOGRAPHY (122.2km)
        // SELECT ST_Distance('LINESTRING(-122.33 47.606, 0.0 51.5)'::geography, 'POINT(-21.96
        // 64.15)':: geography);

        // adding Reykjavik
        FeatureWriter fw = dataStore.getFeatureWriterAppend(tname("geopoint"),
                Transaction.AUTO_COMMIT);
        SimpleFeature f = (SimpleFeature) fw.next();
        Point point = gf.createPoint(new Coordinate(-21.96, 64.15));
        f.setAttribute("name", "Reykjavik");
        f.setDefaultGeometry(point);
        fw.write();
        fw.close();

        // testing distance filter
        LineString line = gf.createLineString(new Coordinate[] { new Coordinate(-122.33, 47.606),
                new Coordinate(0.0, 51.5) });
        DWithin filter = ff.dwithin(ff.property(aname("geo")), ff.literal(line), 130000d, "metre");
View Full Code Here

Examples of org.geotools.data.FeatureWriter

    public void write() throws IOException {
        writer.write();
    }
   
    public void close() throws IOException {
        FeatureWriter w = writer;
        while( w instanceof DelegatingFeatureWriter ) {
            if ( w instanceof JDBCFeatureReader ) {
                break;
            }
           
View Full Code Here

Examples of org.geotools.data.FeatureWriter

    }

    public void testWrite() throws Exception {
        int count = dataStore.getFeatureSource(tname("udt")).getCount(Query.ALL);
       
        FeatureWriter w = dataStore.getFeatureWriterAppend(tname("udt"), Transaction.AUTO_COMMIT);
        w.hasNext();
       
        SimpleFeature f = (SimpleFeature) w.next();
        f.setAttribute(aname("ut"), "abcd");
        try {
            w.write();
            fail("Write should have failed with UDT constraint failure");
        }
        catch(Exception e) {
        }
       
        f.setAttribute(aname("ut"), "34cd");
        w.write();
        w.close();
       
        assertEquals(count+1, dataStore.getFeatureSource(tname("udt")).getCount(Query.ALL));
    }
View Full Code Here

Examples of org.geotools.data.FeatureWriter

        dataStore.createSchema(zipCodeSchema);
        assertFeatureTypesEqual(zipCodeSchema, dataStore.getSchema(tname(ZIPCODE)));
    }
   
    public void testWriteFeatures() throws Exception {
        FeatureWriter fw = dataStore.getFeatureWriterAppend(tname(PERSON),Transaction.AUTO_COMMIT);
       
        SimpleFeature f = (SimpleFeature) fw.next();
        f.setAttribute(aname("name"), "Joe");
        f.setAttribute(aname("age"), 27 );
        fw.write();
        fw.close();
       
        FeatureCollection fc = dataStore.getFeatureSource(tname(PERSON)).getFeatures();
        assertEquals(3, fc.size());
    }
View Full Code Here

Examples of org.geotools.data.FeatureWriter

     * @return Iterator, should be closed closeIterator
     */
    protected Iterator<SimpleFeature> openIterator() throws IOException
    {     
      try {
          FeatureWriter writer = writer();
          if(writer != null) {
              return new FeatureWriterIterator( writer() );
          }
        } catch (IOException badWriter) {
            return new NoContentIterator( badWriter );
View Full Code Here

Examples of org.geotools.data.FeatureWriter

    public boolean addAll(Collection collection) {
        if( collection instanceof FeatureCollection ){
            return addAll( (FeatureCollection<?,?>) collection );
        }
        try {
            FeatureWriter writer = writer();
            if(writer == null) {
                return false;
            }
            try {
                // skip to end
                 while( writer.hasNext() ){
                    Feature feature = writer.next();
                }
                for( Object obj : collection ){
                    if( obj instanceof SimpleFeature){
                        SimpleFeature copy = (SimpleFeature) obj;
                        SimpleFeature feature = (SimpleFeature) writer.next();
                       
                        feature.setAttributes( copy.getAttributes() );
                        writer.write();
                    }
                }
            }
            finally {
                if( writer != null ) writer.close();
            }
            return true;
        }
        catch( IOException ignore ){
            return false;
View Full Code Here

Examples of org.geotools.data.FeatureWriter

        String typeName = sds.getTypeNames()[0];
        int idx = loadFeatures(sds, typeName).size();

        while (idx > 0) {
            FeatureWriter writer = null;

            try {
                writer = sds.getFeatureWriter(typeName, Filter.INCLUDE, Transaction.AUTO_COMMIT);
                writer.next();
                writer.remove();
            } finally {
                if (writer != null) {
                    writer.close();
                    writer = null;
                }
            }
            idx--;
            assertEquals(idx, countFeatures(loadFeatures(sds, typeName)));
View Full Code Here

Examples of org.geotools.data.FeatureWriter

        int idx = loadFeatures(sds, typeName).size();
        assertEquals(idx, countFeatures(loadFeatures(sds, typeName)));

        while (idx > 0) {
            FeatureWriter writer = null;
            try {
                writer = sds.getFeatureWriter(sds.getTypeNames()[0], Filter.INCLUDE,
                        Transaction.AUTO_COMMIT);
                while (writer.hasNext()) {
                    writer.next();
                }
                writer.remove();
            } finally {
                if (writer != null) {
                    writer.close();
                    writer = null;
                }
            }
            assertEquals(--idx, countFeatures(loadFeatures(sds, typeName)));
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.