public SimpleFeature next() throws IOException { try { current = delegate.next(); retyped = RetypingFeatureCollection.retype(current, builder); return retyped; } catch (IllegalAttributeException e) { throw (IOException) new IOException("Error occurred while retyping feature").initCause(e); } }
public SimpleFeature next() throws IOException { live = writer.next(); return live; }
@Override public SimpleFeature next() throws IOException { return (SimpleFeature) w.next(); }
public SimpleFeature next() throws IOException { return (SimpleFeature) writer.next(); }
/** * Next Feature from reader or new content. * * @see org.geotools.data.FeatureWriter#next() */ public SimpleFeature next() throws IOException { if (writer == null) { throw new IOException("FeatureWriter has been closed"); } feature = writer.next(); return feature; }
public SimpleFeature next() { if (writer == null) { throw new NoSuchElementException("Iterator has been closed"); } try { return writer.next(); } catch (IOException io) { NoSuchElementException problem = new NoSuchElementException("Could not obtain the next feature:" + io); problem.initCause(io); throw problem; } }
public SimpleFeature next() { if (writer == null) { throw new NoSuchElementException("Iterator has been closed"); } try { return writer.next(); } catch (IOException io) { NoSuchElementException problem = new NoSuchElementException("Could not obtain the next feature:" + io); problem.initCause(io); throw problem; } }
private void writeToShapefile( SimpleFeature f, FeatureWriter<SimpleFeatureType, SimpleFeature> writer) throws IOException { SimpleFeature fw = writer.next(); // we cannot trust attribute order, shapefile changes the location and name of the geometry for (AttributeDescriptor d : fw.getFeatureType().getAttributeDescriptors()) { fw.setAttribute(d.getLocalName(), f.getAttribute(d.getLocalName())); } fw.setDefaultGeometry(f.getDefaultGeometry()); writer.write(); }
public void testGetFeatureWriterRemove() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = writer.next(); if (feature.getID().equals("road.rd1")) { writer.remove(); } } assertEquals(roadFeatures.length - 1, data.entry("road").getMemory().size()); }
public void testGetFeaturesWriterModify() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = writer.next(); if (feature.getID().equals("road.rd1")) { feature.setAttribute("name", "changed"); writer.write(); } } feature = data.entry("road").getMemory().get("road.rd1"); assertEquals("changed", feature.getAttribute("name")); }
public void testGetFeaturesWriterAdd() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); } assertFalse(writer.hasNext()); feature = (SimpleFeature) writer.next(); feature.setAttributes(newRoad.getAttributes()); writer.write(); assertFalse(writer.hasNext()); assertEquals(roadFeatures.length + 1, data.entry("road").getMemory().size()); }
public void testGetFeatureWriter() throws NoSuchElementException, IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); assertEquals(roadFeatures.length, count(writer)); assertFalse(writer.hasNext()); try { writer.next(); fail("Should not be able to use a closed writer"); } catch (IOException expected) { } }
public void testGetFeatureWriterRemove() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = writer(tname("road"))) { SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); if (feature.getID().equals(td.roadFeatures[0].getID())) { writer.remove(); } } } assertEquals(td.roadFeatures.length - 1, count(tname("road"))); }
public void testGetFeatureWriterRemoveAll() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = writer(tname("road"))) { SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); writer.remove(); } } assertEquals(0, count(tname("road"))); }
public void testGetFeatureWriterAppend() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), Transaction.AUTO_COMMIT)) { for (int i = 3; i < 6; i++) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(i)); writer.write(); } } SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(6, features.size()); }
public void testNoCommit() throws IOException { try (Transaction tx = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx)) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(100)); writer.write(); tx.rollback(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(3, fc.size()); }
public void testModifyFeatures() throws Exception { try (FeatureWriter<SimpleFeatureType, SimpleFeature> w = dataStore.getFeatureWriter(tname("guid"), Transaction.AUTO_COMMIT)) { w.hasNext(); SimpleFeature f = w.next(); f.setAttribute(aname("uuidProperty"), uuid2); assertEquals(uuid2, f.getAttribute(aname("uuidProperty"))); w.write(); } }
public void testCommit() throws IOException { // JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); try (Transaction tx = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx)) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(100)); writer.write(); writer.close(); tx.commit(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(4, fc.size()); }
public void testGetFeaturesWriterModify() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = writer(tname("road"))) { while (writer.hasNext()) { SimpleFeature feature = (SimpleFeature) writer.next(); if (feature.getID().equals(td.roadFeatures[0].getID())) { feature.setAttribute(aname("name"), "changed"); writer.write(); } } } SimpleFeature feature = (SimpleFeature) feature(tname("road"), td.roadFeatures[0].getID()); assertNotNull(feature); assertEquals("changed", feature.getAttribute(aname("name"))); }
public void testWriteFeatures() throws Exception { try (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(); } FeatureCollection fc = dataStore.getFeatureSource(tname(PERSON)).getFeatures(); assertEquals(3, fc.size()); } }