Refine search
/** * 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; }
static SimpleFeature retype(SimpleFeature source, SimpleFeatureBuilder builder) throws IllegalAttributeException { SimpleFeatureType target = builder.getFeatureType(); for (int i = 0; i < target.getAttributeCount(); i++) { AttributeDescriptor attributeType = target.getDescriptor(i); Object value = null; if (source.getFeatureType().getDescriptor(attributeType.getName()) != null) { value = source.getAttribute(attributeType.getName()); } builder.add(value); } FeatureId id = reTypeId(source.getIdentifier(), source.getFeatureType(), target); SimpleFeature retyped = builder.buildFeature(id.getID()); retyped.getUserData().putAll(source.getUserData()); return retyped; }
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(type); WKTReader reader = new WKTReader(); sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023"); sfb.set("NAME", "Old oak"); SimpleFeature feature = sfb.buildFeature(null); SimpleFeatureCollection fc = DataUtilities.collection(feature);
/** * Static method to build a new feature. * * <p>If multiple features need to be created, this method should not be used and instead an * instance should be instantiated directly. * * <p>This method is a short-hand convenience which creates a builder instance internally and * adds all the specified attributes. * * @param type SimpleFeatureType defining the structure for the created feature * @param values Attribute values, must be in the order defined by SimpleFeatureType * @param id FeatureID for the generated feature, use null to allow one to be supplied for you */ public static SimpleFeature build(SimpleFeatureType type, Object[] values, String id) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); builder.addAll(values); return builder.buildFeature(id); }
builder.add(stats.getCount()); builder.add(stats.getMin()); builder.add(stats.getMax()); builder.add(stats.getSum()); builder.add(stats.getAverage()); builder.add(stats.getStandardDeviation()); return builder.buildFeature(zone.getID()); } catch (Exception e) { throw new ProcessException("Failed to compute statistics on feature " + zone, e);
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; }
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(type); WKTReader reader = new WKTReader(); sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023"); sfb.set("NAME", "Old oak"); SimpleFeature feature = sfb.buildFeature(null); SimpleFeatureCollection fc = DataUtilities.collection(feature);
public SimpleFeature next() { SimpleFeature next = (SimpleFeature) delegate.next(); String id = next.getID(); try { for (int i = 0; i < types.length; i++) { final String xpath = types[i].getLocalName(); builder.add(next.getAttribute(xpath)); } return builder.buildFeature(id); } catch (IllegalAttributeException e) { throw new RuntimeException(e); } }
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; }
/** * Copy an existing feature (the values are reused so be careful with mutable values). * * <p>If multiple features need to be copied, this method should not be used and instead an * instance should be instantiated directly. * * <p>This method is a short-hand convenience which creates a builder instance and initializes * it with the attributes from the specified feature. */ public static SimpleFeature copy(SimpleFeature original) { if (original == null) return null; SimpleFeatureBuilder builder = new SimpleFeatureBuilder(original.getFeatureType()); builder.init(original); // this is a shallow copy return builder.buildFeature(original.getID()); }
private SimpleFeature createFeature(String label, Geometry geom) { fb.add(label); fb.add(geom); return fb.buildFeature(null); }
tb.add("geom", Point.class); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); b.add(new WKTReader().read("POINT(1 1)")); SimpleFeature f = b.buildFeature(null); f.getUserData().put("foo", "bar");
/** * Check null encoding is working properly * * @throws IOException */ public void testAddNullAttributes() throws IOException { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema()); SimpleFeature nullFeature = b.buildFeature("testId"); featureStore.addFeatures(Arrays.asList(nullFeature)); }
protected SimpleFeature readFeature(AttributeReader atts) throws IllegalAttributeException, IOException { // Seems like doing it here could be a bit expensive. // The other option from this is to have this constructed with two // attributeReaders, the FID one and real attributes one. Could then // have default FIDAttributeReader. String fid = fidReader.next(); for (int i = 0, ii = atts.getAttributeCount(); i < ii; i++) { builder.add(atts.read(i)); } return builder.buildFeature(fid); }
/** * Builds a new feature whose attribute values are the default ones * * @param featureType * @param featureId * @return */ public static SimpleFeature template(SimpleFeatureType featureType, String featureId) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { builder.add(ad.getDefaultValue()); } return builder.buildFeature(featureId); }
protected void setUp() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("Dummy"); SimpleFeatureType schema = tb.buildFeatureType(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(schema); List<SimpleFeature> list = new ArrayList<SimpleFeature>(); for (int i = 0; i < 100; i++) { list.add(b.buildFeature(null)); } features = newCollection(schema, list); }
public SimpleFeature next() throws NoSuchElementException { SimpleFeature feature = delegate.next(); for (Definition def : definition) { Object value = def.expression.evaluate(feature); fb.add(value); } SimpleFeature created = fb.buildFeature(feature.getID()); return created; } }
private SimpleFeature createFeature( SimpleFeatureType featureType, String name, LineString geom1, Geometry geom2) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); builder.add(name); builder.add(geom1); builder.add(geom2); return builder.buildFeature(name); }
/** * Copies an existing feature, retyping it in the process. * * <p>Be warned, this method will create its own SimpleFeatureBuilder, which will trigger a scan * of the SPI looking for the current default feature factory, which is expensive and has * scalability issues. * * <p>If you need good performance consider using {@link * SimpleFeatureBuilder#retype(SimpleFeature, SimpleFeatureBuilder)} instead. * * <p>If the feature type contains attributes in which the original feature does not have a * value for, the value in the resulting feature is set to <code>null</code>. * * @param feature The original feature. * @param featureType The target feature type. * @return The copied feature, with a new type. */ public static SimpleFeature retype(SimpleFeature feature, SimpleFeatureType featureType) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { Object value = feature.getAttribute(att.getName()); builder.set(att.getName(), value); } return builder.buildFeature(feature.getID()); }
public SimpleFeature next() { SimpleFeature next = delegate.next(); String id = next.getID(); try { for (int i = 0; i < types.length; i++) { final String xpath = types[i].getLocalName(); builder.add(next.getAttribute(xpath)); } return builder.buildFeature(id); } catch (IllegalAttributeException e) { throw new RuntimeException(e); } }