Codota Logo
FeatureWriter
Code IndexAdd Codota to your IDE (free)

How to use
FeatureWriter
in
org.geotools.data

Best Java code snippets using org.geotools.data.FeatureWriter (Showing top 20 results out of 315)

Refine searchRefine arrow

  • SimpleFeature
  • JDBCDataStore
  • Common ways to obtain FeatureWriter
private void myMethod () {
FeatureWriter f =
  • Codota IconDataStore dataStore;String typeName;Transaction transaction;dataStore.getFeatureWriterAppend(typeName, transaction)
  • Codota IconDataStore dataStore;String str;Transaction transaction;dataStore.getFeatureWriter(str, transaction)
  • Codota IconPropertyDataStore propertyDataStore;String typeName;new PropertyFeatureWriter(propertyDataStore, typeName)
  • Smart code suggestions by Codota
}
origin: geotools/geotools

  /** Counts the number of Features in the specified writer. This method will close the writer. */
  protected int count(FeatureWriter<SimpleFeatureType, SimpleFeature> writer)
      throws NoSuchElementException, IOException {
    int count = 0;

    try {
      while (writer.hasNext()) {
        writer.next();
        count++;
      }
    } finally {
      writer.close();
    }

    return count;
  }
}
origin: geoserver/geoserver

  public void write() throws IOException {
    try {
      SimpleFeatureType target = getFeatureType();
      for (int i = 0; i < target.getAttributeCount(); i++) {
        AttributeDescriptor at = target.getDescriptor(i);
        Object value = retyped.getAttribute(i);
        current.setAttribute(at.getLocalName(), value);
      }
      delegate.write();
    } catch (IllegalAttributeException e) {
      throw (IOException)
          new IOException("Error occurred while retyping feature").initCause(e);
    }
  }
}
origin: geotools/geotools

public void remove() throws IOException {
  writer.remove();
}
origin: geotools/geotools

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();
  }
}
origin: geotools/geotools

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());
}
origin: geotools/geotools

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"));
}
origin: geotools/geotools

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();
}
origin: geotools/geotools

  while (writer.hasNext()) {
    feature = (SimpleFeature) writer.next();
    String fid = feature.getID();
        writer.remove();
          feature.setAttributes(update.getAttributes());
          writer.write();
      addedFeature = diff.getAdded().get(fid);
      nextFeature = (SimpleFeature) writer.next();
          writer.write();
} finally {
  try {
    writer.close();
    state.fireBatchFeatureEvent(true);
    diff.clear();
origin: geotools/geotools

    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();
DWithin filter = ff.dwithin(ff.property(aname("geo")), ff.literal(line), 130000d, "metre");
FeatureCollection features =
    dataStore.getFeatureSource(tname("geopoint")).getFeatures(filter);
assertEquals(1, features.size());
try (FeatureIterator fi = features.features()) {
  assertTrue(fi.hasNext());
  SimpleFeature feature = (SimpleFeature) fi.next();
  assertEquals("Reykjavik", feature.getAttribute("name"));
origin: geotools/geotools

      dataStore.getFeatureWriter(tname("road"), td.rd1Filter, t1);
  FeatureWriter<SimpleFeatureType, SimpleFeature> writer2 =
      dataStore.getFeatureWriterAppend(tname("road"), t2)) {
int i;
int index;
  feature = ORIGINAL[i];
  if (!feature.getID().equals(td.roadFeatures[0].getID())) {
    REMOVE[index++] = feature;
    dataStore.getFeatureReader(
        new Query(tname("road"), Filter.INCLUDE),
        Transaction.AUTO_COMMIT)) {
while (writer1.hasNext()) {
  feature = (SimpleFeature) writer1.next();
  assertEquals(td.roadFeatures[0].getID(), feature.getID());
  writer1.remove();
writer1.close();
feature = (SimpleFeature) writer2.next();
feature.setAttributes(td.newRoad.getAttributes());
writer2.write();
origin: geotools/geotools

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());
}
origin: geotools/geotools

public void testAppend() throws Exception {
  if (!isGeographySupportAvailable()) {
    return;
  }
  Point point = gf.createPoint(new Coordinate(10, 10));
  try (FeatureWriter fw =
      dataStore.getFeatureWriterAppend(tname("geopoint"), Transaction.AUTO_COMMIT)) {
    assertFalse(fw.hasNext());
    SimpleFeature f = (SimpleFeature) fw.next();
    f.setAttribute("name", "append");
    f.setDefaultGeometry(point);
    fw.write();
  }
  Filter filter = ff.equals(ff.property("name"), ff.literal("append"));
  Query q = new Query(tname("geopoint"), filter);
  try (FeatureReader fr = dataStore.getFeatureReader(q, Transaction.AUTO_COMMIT)) {
    assertTrue(fr.hasNext());
    SimpleFeature f = (SimpleFeature) fr.next();
    assertEquals(point, f.getDefaultGeometry());
  }
}
origin: geotools/geotools

dataStore.createSchema(poly3DType);
SimpleFeatureType actualSchema = dataStore.getSchema(tname(getPoly3d()));
assertFeatureTypesEqual(poly3DType, actualSchema);
assertEquals(
    dataStore.getFeatureWriterAppend(tname(getPoly3d()), Transaction.AUTO_COMMIT)) {
  SimpleFeature f = fw.next();
  f.setAttribute(aname(ID), 0);
  f.setAttribute(aname(GEOM), poly);
  f.setAttribute(aname(NAME), "3dpolygon!");
  fw.write();
origin: geotools/geotools

public void testUpdate() throws Exception {
  if (!isGeographySupportAvailable()) {
    return;
  }
  Point p = gf.createPoint(new Coordinate(1, 1));
  try (FeatureWriter fw =
      dataStore.getFeatureWriter(tname("geopoint"), Transaction.AUTO_COMMIT)) {
    assertTrue(fw.hasNext());
    while (fw.hasNext()) {
      SimpleFeature f = (SimpleFeature) fw.next();
      f.setDefaultGeometry(p);
      fw.write();
    }
  }
  try (FeatureReader fr =
      dataStore.getFeatureReader(new Query(tname("geopoint")), Transaction.AUTO_COMMIT)) {
    while (fr.hasNext()) {
      SimpleFeature f = (SimpleFeature) fr.next();
      assertEquals(p, f.getDefaultGeometry());
    }
  }
}
origin: geotools/geotools

dataStore.createSchema(featureType);
SimpleFeatureType ft2 = dataStore.getSchema(tname("ft2"));
    dataStore.getFeatureWriter(tname("ft2"), Transaction.AUTO_COMMIT)) {
  w.hasNext();
  SimpleFeature f = w.next();
  f.setAttribute(1, Integer.valueOf(0));
  f.setAttribute(2, "hello");
  w.write();
  w.hasNext();
  f = w.next();
  f.setAttribute(1, null);
  try {
    w.write();
    fail("null value for intProperty should have failed");
  } catch (Exception e) {
  f.setAttribute(2, "hello!");
  try {
    w.write();
    fail("string greather than 5 chars should have failed");
  } catch (Exception e) {
origin: geotools/geotools

public void testGetFeaturesWriterAdd() throws IOException {
  try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
      dataStore.getFeatureWriter(tname("road"), Transaction.AUTO_COMMIT)) {
    SimpleFeature feature;
    while (writer.hasNext()) {
      feature = (SimpleFeature) writer.next();
    }
    assertFalse(writer.hasNext());
    feature = (SimpleFeature) writer.next();
    feature.setAttributes(td.newRoad.getAttributes());
    writer.write();
    assertFalse(writer.hasNext());
    assertEquals(td.roadFeatures.length + 1, count(tname("road")));
  }
}
origin: geotools/geotools

/** @see FeatureStore#addFeatures(SimpleFeatureCollection) */
public List<FeatureId> addFeatures(
    final FeatureCollection<SimpleFeatureType, SimpleFeature> collection)
    throws IOException {
  // System.err.println(">>addFeatures called at " +
  // Thread.currentThread().getName());
  final String typeName = typeInfo.getFeatureTypeName();
  final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
  writer = dataStore.getFeatureWriterAppend(typeName, transaction);
  final FeatureIterator<SimpleFeature> iterator = collection.features();
  List<FeatureId> featureIds = new LinkedList<FeatureId>();
  try {
    SimpleFeature toAdd;
    SimpleFeature newFeature;
    while (iterator.hasNext()) {
      toAdd = iterator.next();
      newFeature = writer.next();
      newFeature.setAttributes(toAdd.getAttributes());
      writer.write();
      featureIds.add(newFeature.getIdentifier());
    }
  } finally {
    iterator.close();
    writer.close();
  }
  return featureIds;
}
origin: geotools/geotools

public void testGetFeatureReaderFilterTransaction()
    throws NoSuchElementException, IOException, IllegalAttributeException {
  SimpleFeatureType type = dataStore.getSchema(tname("road"));
        dataStore.getFeatureReader(new Query(tname("road"), Filter.EXCLUDE), t)) {
      assertFalse(reader.hasNext());
      assertEquals(type, reader.getFeatureType());
        dataStore.getFeatureReader(new Query(tname("road"), Filter.INCLUDE), t)) {
      assertEquals(type, reader.getFeatureType());
      assertEquals(td.roadFeatures.length, count(reader));
      SimpleFeature feature;
      while (writer.hasNext()) {
        feature = (SimpleFeature) writer.next();
        if (feature.getID().equals(td.roadFeatures[0].getID())) {
          writer.remove();
origin: geotools/geotools

public void modifyFeatures(final Name[] attributes, final Object[] values, final Filter filter)
    throws IOException {
  final ISession session = getSession();
  try {
    final String typeName = typeInfo.getFeatureTypeName();
    final Transaction currTransaction = getTransaction();
    final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
    writer = dataStore.getFeatureWriter(typeName, filter, currTransaction);
    try {
      SimpleFeature feature;
      while (writer.hasNext()) {
        feature = writer.next();
        for (int i = 0; i < values.length; i++) {
          feature.setAttribute(attributes[i].getLocalPart(), values[i]);
        }
        writer.write();
      }
    } finally {
      writer.close();
    }
  } finally {
    session.dispose();
  }
}
origin: geotools/geotools

public void remove() throws IOException {
  if (live != null) {
    assertAccess(typeName, live.getID(), transaction);
  }
  writer.remove();
  live = null;
}
org.geotools.dataFeatureWriter

Javadoc

Provides the ability to write Features information.

Capabilities:

  • Similar API to FeatureReader
  • After aquiring a feature using next() you may call remove() or after modification write(). If you do not call one of these two methods before calling hasNext(), or next() for that matter, the feature will be left unmodified.
  • This API allows modification, and Filter based modification to be written. Please see ContentDataStore for examples of implementing common opperations using this API.
  • In order to add new Features, FeatureWriters capable of accepting new content allow next() to be called when hasNext() is false to allow new feature creation. These changes

One thing that is really nice about the approach to adding content is that the generation of FID is not left in the users control.

Most used methods

  • next
  • write
    Wrties the current Feature, must be called before hasNext. FeautreWriters will need to allow Feature
  • close
    Release the underlying resources.
  • hasNext
    Query whether this FeatureWriter has another Feature. Please note: it is more efficient to construct
  • remove
    Removes current Feature, must be called before hasNext. FeatureWriters will need to allow all Featur
  • getFeatureType

Popular in Java

  • Updating database using SQL prepared statement
  • setContentView (Activity)
  • runOnUiThread (Activity)
  • orElseThrow (Optional)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • ResourceBundle (java.util)
    Resource bundles contain locale-specific objects. When your program needs a locale-specific resource
  • JFileChooser (javax.swing)
  • JPanel (javax.swing)
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now