public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (iterator == null) { throw new IOException("Feature Reader has been closed"); } try { return SimpleFeatureBuilder.copy((SimpleFeature) iterator.next()); } catch (NoSuchElementException end) { throw new DataSourceException("There are no more Features", end); } }
public void testCopyFeature() throws Exception { SimpleFeature feature = lakeFeatures[0]; assertDuplicate("feature", feature, SimpleFeatureBuilder.copy(feature)); }
current = SimpleFeatureBuilder.copy(live);
return SimpleFeatureBuilder.copy(feature);
/** * Next Feature from reader or new content. * * @see org.geotools.data.FeatureWriter#next() */ public SimpleFeature next() throws IOException { SimpleFeatureType type = getFeatureType(); if (hasNext()) { // hasNext() will take care recording // any modifications to current live = next; // update live value next = null; // hasNext will need to search again current = SimpleFeatureBuilder.copy(live); return current; } else { if (diff == null) { throw new IOException("FeatureWriter has been closed"); } // Create new content // created with an empty ID // (The real writer will supply a FID later) live = null; next = null; current = builder.buildFeature( "new" + diff.nextFID, new Object[type.getAttributeCount()]); diff.nextFID++; return current; } }
public SimpleFeature next() throws IOException, NoSuchElementException { if (hasNext()) { // existing content live = iterator.next(); try { current = SimpleFeatureBuilder.copy(live); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to edit " + live.getID() + " of " + typeName); } } else { // new content live = null; try { current = SimpleFeatureBuilder.template(featureType, null); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to add additional Features of " + typeName); } } return current; }
public SimpleFeatureCollection collection() throws IOException { DefaultFeatureCollection copy = new DefaultFeatureCollection(null, getSchema()); List<SimpleFeature> list = new ArrayList<SimpleFeature>(contents.size()); SimpleFeatureIterator iterator = features(); try { while (iterator.hasNext()) { SimpleFeature feature = iterator.next(); SimpleFeature duplicate; try { duplicate = SimpleFeatureBuilder.copy(feature); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to copy " + feature.getID(), e); } list.add(duplicate); } } finally { iterator.close(); } copy.addAll(list); return copy; }
public SimpleFeatureCollection collection() throws IOException { TreeSetFeatureCollection copy = new TreeSetFeatureCollection(null, getSchema()); List<SimpleFeature> list = new ArrayList<SimpleFeature>(contents.size()); SimpleFeatureIterator iterator = features(); try { while (iterator.hasNext()) { SimpleFeature feature = iterator.next(); SimpleFeature duplicate; try { duplicate = SimpleFeatureBuilder.copy(feature); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to copy " + feature.getID(), e); } list.add(duplicate); } } finally { iterator.close(); } copy.addAll(list); return copy; }
/** * Same as DataUtilities.reType, but without the cloning that uselessly wastes CPU cycles... * * @param featureType * @param feature * @return * @throws IllegalAttributeException */ public static SimpleFeature reType(SimpleFeatureType featureType, SimpleFeature feature) throws IllegalAttributeException { FeatureType origional = feature.getFeatureType(); if (featureType.equals(origional)) { return SimpleFeatureBuilder.copy(feature); } String id = feature.getID(); int numAtts = featureType.getAttributeCount(); Object[] attributes = new Object[numAtts]; for (int i = 0; i < numAtts; i++) { AttributeDescriptor curAttType = featureType.getDescriptor(i); attributes[i] = feature.getAttribute(curAttType.getLocalName()); } return SimpleFeatureBuilder.build(featureType, attributes, id); }
/** * Applies transform to all geometry attribute. * * @param feature Feature to be transformed * @param schema Schema for target transformation - transform( schema, crs ) * @param transform MathTransform used to transform coordinates - reproject( crs, crs ) * @return transformed Feature of type schema * @throws TransformException * @throws MismatchedDimensionException * @throws IllegalAttributeException */ public static SimpleFeature transform( SimpleFeature feature, SimpleFeatureType schema, MathTransform transform) throws MismatchedDimensionException, TransformException, IllegalAttributeException { feature = SimpleFeatureBuilder.copy(feature); GeometryDescriptor geomType = schema.getGeometryDescriptor(); Geometry geom = (Geometry) feature.getAttribute(geomType.getLocalName()); geom = JTS.transform(geom, transform); feature.setAttribute(geomType.getLocalName(), geom); return feature; }
public SimpleFeature next() throws IOException { if (writer == null) { throw new IOException("Writer has been closed"); } String fid = null; try { if (hasNext()) { delegate.next(); // grab next line fid = delegate.fid; Object values[] = new Object[type.getAttributeCount()]; for (int i = 0; i < type.getAttributeCount(); i++) { values[i] = delegate.read(i); } origional = SimpleFeatureBuilder.build(type, values, fid); live = SimpleFeatureBuilder.copy(origional); return live; } else { fid = type.getTypeName() + "." + System.currentTimeMillis(); Object values[] = DataUtilities.defaultValues(type); origional = null; live = SimpleFeatureBuilder.build(type, values, fid); return live; } } catch (IllegalAttributeException e) { String message = "Problem creating feature " + (fid != null ? fid : ""); throw new DataSourceException(message, e); } } // next end
/** * Creates duplicate of feature adjusted to the provided featureType. * * <p>Please note this implementation provides "deep copy" using {@link #duplicate(Object)} to * copy each attribute. * * @param featureType FeatureType requested * @param feature Origional Feature from DataStore * @return An instance of featureType based on feature * @throws IllegalAttributeException If opperation could not be performed */ public static SimpleFeature reType(SimpleFeatureType featureType, SimpleFeature feature) throws IllegalAttributeException { SimpleFeatureType origional = feature.getFeatureType(); if (featureType.equals(origional)) { return SimpleFeatureBuilder.copy(feature); } String id = feature.getID(); int numAtts = featureType.getAttributeCount(); Object[] attributes = new Object[numAtts]; String xpath; for (int i = 0; i < numAtts; i++) { AttributeDescriptor curAttType = featureType.getDescriptor(i); xpath = curAttType.getLocalName(); attributes[i] = duplicate(feature.getAttribute(xpath)); } return SimpleFeatureBuilder.build(featureType, attributes, id); }
public void testClone() { SimpleFeature f = SampleFeatureFixtures.createFeature(); SimpleFeature c = SimpleFeatureBuilder.copy(f); for (int i = 0, ii = c.getAttributeCount(); i < ii; i++) { assertEquals(c.getAttribute(i), f.getAttribute(i)); } }
public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (iterator == null) { throw new IOException("Feature Reader has been closed"); } try { return SimpleFeatureBuilder.copy((SimpleFeature) iterator.next()); } catch (NoSuchElementException end) { throw new DataSourceException("There are no more Features", end); } }
public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (iterator == null) { throw new IOException("Feature Reader has been closed"); } try { return SimpleFeatureBuilder.copy((SimpleFeature) iterator.next()); } catch (NoSuchElementException end) { throw new DataSourceException("There are no more Features", end); } }
public SimpleFeature next() throws IOException { try { if (originalFeature != null) { writeFeature(originalFeature); // keep the original } if (innerReader.hasNext()) { originalFeature = innerReader.next(); // ; editFeature = SimpleFeatureBuilder.copy(originalFeature); } else { originalFeature = null; editFeature = SimpleFeatureBuilder.build(featureType, featureDefaults, null); } return editFeature; } catch (Exception e) { throw new IOException(e.toString()); } }
public SimpleFeature next() throws IOException { if (live != null) { write(); } if (reader.hasNext()) { original = reader.next(); live = SimpleFeatureBuilder.copy(original); } else { original = null; live = SimpleFeatureBuilder.template(featureType, null); } return live; }
public SimpleFeature next() throws IOException, NoSuchElementException { if (hasNext()) { // existing content live = (SimpleFeature) iterator.next(); try { current = SimpleFeatureBuilder.copy(live); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to edit " + live.getID() + " of " + typeName); } } else { // new content live = null; try { current = SimpleFeatureBuilder.template(featureType, null); } catch (IllegalAttributeException e) { throw new DataSourceException("Unable to add additional Features of " + typeName); } } return current; }
/** * Applies transform to all geometry attribute. * * @param feature Feature to be transformed * @param schema Schema for target transformation - transform( schema, crs ) * @param transform MathTransform used to transform coordinates - reproject( crs, crs ) * @return transformed Feature of type schema * @throws TransformException * @throws MismatchedDimensionException * @throws IllegalAttributeException */ public static SimpleFeature transform( SimpleFeature feature, SimpleFeatureType schema, MathTransform transform ) throws MismatchedDimensionException, TransformException, IllegalAttributeException { feature = SimpleFeatureBuilder.copy(feature); GeometryDescriptor geomType = schema.getGeometryDescriptor(); Geometry geom = (Geometry) feature.getAttribute(geomType.getLocalName()); geom = JTS.transform(geom, transform); feature.setAttribute(geomType.getLocalName(), geom); return feature; }