private SimpleFeatureCollection makePointFeatures() throws Exception { Map<Vertex, Double> points = makePoints(); /* Stage the point features in memory */ DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, pointSchema); SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(pointSchema); GeometryFactory gf = new GeometryFactory(); for (Map.Entry<Vertex, Double> entry : points.entrySet()) { Vertex vertex = entry.getKey(); Double travelTime = entry.getValue(); fbuilder.add(gf.createPoint(vertex.getCoordinate())); fbuilder.add(travelTime); featureCollection.add(fbuilder.buildFeature(null)); } return featureCollection; }
private SimpleFeatureCollection makeContourFeatures() throws Exception { Map<Integer, Geometry> contours = makeContours(); /* Stage the features in memory, in order from bottom to top, biggest to smallest */ DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, contourSchema); SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema); List<Integer> thresholds = new ArrayList<Integer>(contours.keySet()); Collections.sort(thresholds); //Collections.reverse(thresholds); for (Integer threshold : thresholds) { Geometry contour = contours.get(threshold); fbuilder.add(contour); fbuilder.add(threshold); featureCollection.add(fbuilder.buildFeature(null)); } return featureCollection; }
/** * Create a geotools feature collection from a list of isochrones in the OTPA internal format. * Once in a FeatureCollection, they can for example be exported as GeoJSON. */ public static SimpleFeatureCollection makeContourFeatures(List<IsochroneData> isochrones) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, contourSchema); SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema); for (IsochroneData isochrone : isochrones) { fbuilder.add(isochrone.geometry); fbuilder.add(isochrone.cutoffSec); featureCollection.add(fbuilder.buildFeature(null)); } return featureCollection; }
/** * Receives an OGC feature and adds it into the collection * * @param feature the OGC feature */ public void feature(SimpleFeature feature) { featureCollection.add(feature); } }
/** * Ensures that this collection contains the specified element (optional operation). Returns * <tt>true</tt> if this collection changed as a result of the call. (Returns <tt>false</tt> if * this collection does not permit duplicates and already contains the specified element.) * * <p>Collections that support this operation may place limitations on what elements may be * added to this collection. In particular, some collections will refuse to add <tt>null</tt> * elements, and others will impose restrictions on the type of elements that may be added. * Collection classes should clearly specify in their documentation any restrictions on what * elements may be added. * * <p>If a collection refuses to add a particular element for any reason other than that it * already contains the element, it <i>must</i> throw an exception (rather than returning * <tt>false</tt>). This preserves the invariant that a collection always contains the specified * element after this call returns. * * @param o element whose presence in this collection is to be ensured. * @return <tt>true</tt> if this collection changed as a result of the call */ public boolean add(SimpleFeature o) { return add(o, true); }
/** * Copies the provided features into a FeatureCollection. * * <p>Often used when gathering a SimpleFeatureCollection into memory. * * @param list features to add to a new FeatureCollection * @return FeatureCollection */ public static SimpleFeatureCollection collection(List<SimpleFeature> list) { DefaultFeatureCollection collection = new DefaultFeatureCollection(null, null); for (SimpleFeature feature : list) { collection.add(feature); } return collection; }
/** @see org.geotools.data.FeatureResults#collection() */ public SimpleFeatureCollection collection() throws IOException { DefaultFeatureCollection fc = new DefaultFeatureCollection(); List<SimpleFeature> results = index.query(bounds); for (Iterator<SimpleFeature> it = results.iterator(); it.hasNext(); ) { fc.add(it.next()); } return fc; }
/** * Copies the provided features into a FeatureCollection. * * <p>Often used when gathering features for FeatureStore: * * <pre> * <code> * featureStore.addFeatures( DataUtilities.collection(feature)); * </code> * </pre> * * @param feature a feature to add to a new collection * @return FeatureCollection */ public static SimpleFeatureCollection collection(SimpleFeature feature) { DefaultFeatureCollection collection = new DefaultFeatureCollection(null, null); collection.add(feature); return collection; }
/** * Copies the provided features into a FeatureCollection. * * <p>Often used when gathering features for FeatureStore: * * <pre> * <code> * featureStore.addFeatures( DataUtilities.collection(array)); * </code> * </pre> * * @param features Array of features * @return FeatureCollection */ public static SimpleFeatureCollection collection(SimpleFeature[] features) { // JG: There may be some performance to be gained by using ListFeatureCollection here DefaultFeatureCollection collection = new DefaultFeatureCollection(null, null); final int length = features.length; for (int i = 0; i < length; i++) { collection.add(features[i]); } return collection; }
features.add(f);
/** * Go through collection contents and morph contents into SimpleFeatures as required. * * @param collection * @return SimpleFeatureCollection */ private SimpleFeatureCollection simpleFeatureCollection(Collection<?> collection) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); SimpleFeatureType schema = null; for (Object obj : collection) { if (schema == null) { schema = simpleType(obj); } SimpleFeature feature = simpleFeature(obj, schema); featureCollection.add(feature); } return featureCollection; }
public boolean addAll(FeatureCollection<?, ?> collection) { // TODO check inheritance with FeatureType here!!! boolean changed = false; FeatureIterator<?> iterator = collection.features(); try { while (iterator.hasNext()) { SimpleFeature f = (SimpleFeature) iterator.next(); boolean added = add(f, false); changed |= added; } return changed; } finally { iterator.close(); } }
public void addGranule( final String typeName, final SimpleFeature granule, final Transaction transaction) throws IOException { Utilities.ensureNonNull("typeName", typeName); Utilities.ensureNonNull("granule", granule); Utilities.ensureNonNull("transaction", transaction); final DefaultFeatureCollection collection = new DefaultFeatureCollection(); collection.add(granule); addGranules(typeName, collection, transaction); }
public SimpleFeatureCollection collection() throws IOException { try { DefaultFeatureCollection collection = new DefaultFeatureCollection(null, null); FeatureReader<SimpleFeatureType, SimpleFeature> reader = reader(); try { while (reader.hasNext()) { collection.add(reader.next()); } } finally { reader.close(); } return collection; } catch (org.opengis.feature.IllegalAttributeException e) { throw new DataSourceException("Could not read feature ", e); } } }
protected void setUp() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("Dummy"); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); for (int i = 0; i < 100; i++) { features.add(b.buildFeature(null)); } }
@Override protected void setUp() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("foo"); tb.add("geom", Point.class); tb.add("name", String.class); SimpleFeatureType featureType = tb.buildFeatureType(); delegate = new DefaultFeatureCollection(null, featureType); SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureType); for (int i = 0; i < 10; i++) { b.add(new GeometryFactory().createPoint(new Coordinate(i, i))); b.add(String.valueOf(i)); delegate.add(b.buildFeature("fid." + i)); } }
public void testSerialTransactions() throws IOException { SimpleFeatureStore st = (SimpleFeatureStore) dataStore.getFeatureSource(tname("ft1")); SimpleFeatureBuilder b = new SimpleFeatureBuilder(st.getSchema()); b.set(aname("intProperty"), Integer.valueOf(100)); SimpleFeature f1 = b.buildFeature(null); DefaultFeatureCollection features = new DefaultFeatureCollection(null, null); features.add(f1); try (Transaction tx1 = new DefaultTransaction()) { st.setTransaction(tx1); st.addFeatures(features); tx1.commit(); } assertEquals(4, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL)); try (Transaction tx2 = new DefaultTransaction()) { st.setTransaction(tx2); st.addFeatures(features); tx2.commit(); } assertEquals(5, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL)); } }