Java Code Examples for org.geotools.data.FeatureWriter#close()
The following examples show how to use
org.geotools.data.FeatureWriter#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoWaveFeatureReaderTest.java From rya with Apache License 2.0 | 5 votes |
@Test public void testRemoveFeature() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException { final Query query = new Query( "GeoWaveFeatureReaderTest", ECQL.toFilter("pid like '" + pids.get( 0).substring( 0, 1) + "%'"), new String[] { "geometry", "pid" }); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT); int count = 0; while (reader.hasNext()) { final SimpleFeature feature = reader.next(); assertTrue(fids.contains(feature.getID())); count++; } assertEquals(1, count); // Remove final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), Transaction.AUTO_COMMIT); try { while (writer.hasNext()) { writer.next(); writer.remove(); } } finally { writer.close(); } // Re-query final FeatureReader<SimpleFeatureType, SimpleFeature> reader2 = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT); int recount = 0; while (reader2.hasNext()) { reader2.next(); recount++; } assertEquals(0, recount); }
Example 2
Source File: WFSBoundedSpatialQueryTest.java From geowave with Apache License 2.0 | 5 votes |
public void populate() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 3
Source File: WFSSpatialTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T18:33:55Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:33:55Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); writer.write(); writer.close(); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, transaction1); assertTrue(reader.hasNext()); final SimpleFeature priorFeature = reader.next(); assertEquals(newFeature.getAttribute("pid"), priorFeature.getAttribute("pid")); assertFalse(reader.hasNext()); reader.close(); transaction1.commit(); transaction1.close(); }
Example 4
Source File: GeoWaveFeatureSourceTest.java From geowave with Apache License 2.0 | 5 votes |
@Override public void populate(final SimpleFeatureType type, final DataStore dataStore) throws IOException, CQLException, ParseException { dataStore.createSchema(type); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(77)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(66)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.242))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 5
Source File: WFSBoundedQueryTest.java From geowave with Apache License 2.0 | 5 votes |
public void populate() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 6
Source File: GeoToolsAttributesSubsetTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException, GeoWavePluginException, SchemaException { geotoolsDataStore = createDataStore(); type = DataUtilities.createType(typeName, typeSpec); geotoolsDataStore.createSchema(type); final Transaction transaction = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = geotoolsDataStore.getFeatureWriter(type.getTypeName(), transaction); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.25, 41.25))); newFeature.setAttribute(long_attribute, 1l); newFeature.setAttribute(string_attribute, "string1"); writer.write(); newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.5, 41.5))); newFeature.setAttribute(long_attribute, 2l); newFeature.setAttribute(string_attribute, "string2"); writer.write(); newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.75, 41.75))); newFeature.setAttribute(long_attribute, 3l); newFeature.setAttribute(string_attribute, "string3"); writer.write(); writer.close(); transaction.commit(); transaction.close(); }
Example 7
Source File: WFSTemporalQueryTest.java From geowave with Apache License 2.0 | 5 votes |
public void populate() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("end", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("end", DateUtilities.parseISO("2005-05-20T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", DateUtilities.parseISO("2005-05-21T20:32:56Z")); newFeature.setAttribute("end", DateUtilities.parseISO("2005-05-22T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 8
Source File: GeoWaveFeatureReaderTest.java From rya with Apache License 2.0 | 4 votes |
@Before public void setup() throws SchemaException, CQLException, Exception { setupConf(); try (final GeoWaveGeoIndexer indexer = new GeoWaveGeoIndexer()) { indexer.setConf(conf); dataStore = indexer.getGeoToolsDataStore(); // Clear old data indexer.purge(conf); type = DataUtilities.createType( "GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String"); dataStore.createSchema(type); stime = DateUtilities.parseISO("2005-05-15T20:32:56Z"); etime = DateUtilities.parseISO("2005-05-20T20:32:56Z"); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter( type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute( "pop", Long.valueOf(100)); newFeature.setAttribute( "pid", "a" + UUID.randomUUID().toString()); newFeature.setAttribute( "start", stime); newFeature.setAttribute( "end", etime); newFeature.setAttribute( "geometry", factory.createPoint(new Coordinate(27.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); newFeature = writer.next(); newFeature.setAttribute( "pop", Long.valueOf(101)); newFeature.setAttribute( "pid", "b" + UUID.randomUUID().toString()); newFeature.setAttribute( "start", etime); newFeature.setAttribute( "geometry", factory.createPoint(new Coordinate(28.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); query = new Query( "GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] { "geometry", "pid" }); } }
Example 9
Source File: GeoWaveFeatureReaderTest.java From geowave with Apache License 2.0 | 4 votes |
@Before public void setup() throws SchemaException, CQLException, Exception { dataStore = createDataStore(); type = DataUtilities.createType( "GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String"); ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex( new SpatialIndexBuilder().createIndex()); ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex( new SpatialTemporalIndexBuilder().createIndex()); dataStore.createSchema(type); stime = DateUtilities.parseISO("2005-05-15T20:32:56Z"); mtime = DateUtilities.parseISO("2005-05-20T20:32:56Z"); etime = DateUtilities.parseISO("2005-05-25T20:32:56Z"); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", "a" + UUID.randomUUID().toString()); newFeature.setAttribute("start", stime); newFeature.setAttribute("end", mtime); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(101)); newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString()); newFeature.setAttribute("start", mtime); newFeature.setAttribute("end", etime); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); query = new Query( "GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] {"geometry", "pid"}); }
Example 10
Source File: WFSTransactionTest.java From geowave with Apache License 2.0 | 4 votes |
@Test public void testInsertIsolation() throws IOException, CQLException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); final SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); writer.write(); writer.close(); FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, transaction1); assertTrue(reader.hasNext()); final SimpleFeature priorFeature = reader.next(); assertEquals(newFeature.getAttribute("pid"), priorFeature.getAttribute("pid")); reader.close(); // uncommitted at this point, so this next transaction should not see // it. final Transaction transaction2 = new DefaultTransaction(); reader = dataStore.getFeatureReader(query, transaction2); assertFalse(reader.hasNext()); reader.close(); transaction1.commit(); reader = dataStore.getFeatureReader(query, transaction1); assertTrue(reader.hasNext()); reader.next(); assertFalse(reader.hasNext()); reader.close(); transaction1.close(); // since this implementation does not support serializable, transaction2 // can see the changes even though // it started after transaction1 and before the commit. reader = dataStore.getFeatureReader(query, transaction2); assertTrue(reader.hasNext()); reader.next(); assertFalse(reader.hasNext()); reader.close(); transaction2.commit(); transaction2.close(); // stats check final Transaction transaction3 = new DefaultTransaction(); reader = ((GeoWaveFeatureSource) ((GeoWaveGTDataStore) dataStore).getFeatureSource( "geostuff", transaction3)).getReaderInternal(query); final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> transStats = ((GeoWaveFeatureReader) reader).getTransaction().getDataStatistics(); assertNotNull( transStats.get( FeatureNumericRangeStatistics.STATS_TYPE.newBuilder().fieldName( "pop").build().getId())); transaction3.close(); }