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; }
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; }
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; }
b.add(new WKTReader().read("POINT(1 1)")); SimpleFeature f = b.buildFeature(null); f.getUserData().put("foo", "bar");
private SimpleFeature createFeature(String label, Geometry geom) { fb.add(label); fb.add(geom); return fb.buildFeature(null); }
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); }
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); } }
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; } }
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); }
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); } }
/** @see org.geotools.data.FeatureReader#next() */ public SimpleFeature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IOException("FeatureReader has been closed"); } SimpleFeature next = reader.next(); String id = next.getID(); String xpath; for (int i = 0; i < types.length; i++) { xpath = types[i].getLocalName(); if (clone) builder.add(DataUtilities.duplicate(next.getAttribute(xpath))); else builder.add(next.getAttribute(xpath)); } return builder.buildFeature(id); }
/** * Reads the next feature form the file * * @return * @throws IOException */ public SimpleFeature read() throws IOException { // read the fid, check for file end String fid = raf.readUTF(); // read the other attributes, build the feature for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { Object att = readAttribute(ad); builder.add(att); } // return the feature return builder.buildFeature(fid); }
public SimpleFeature next() throws NoSuchElementException { SimpleFeature f = delegate.next(); for (Object attribute : f.getAttributes()) { if ((attribute instanceof Geometry) && !(attribute instanceof Point)) { attribute = ((Geometry) attribute).getCentroid(); } fb.add(attribute); } return fb.buildFeature(f.getID()); } }
/** Creates a point feature at position x,y. */ private SimpleFeature createPointFeature(double x, double y) { fb.add(geomFactory.createPoint(new Coordinate(x, y))); fb.add(Integer.valueOf(featureList.size() + 1)); return fb.buildFeature(null); }
@Override public SimpleFeature next() throws IOException { SimpleFeature f = wrapped.next(); for (AttributeDescriptor ad : target.getAttributeDescriptors()) { Expression ex = transformer.getExpression(ad.getLocalName()); if (ex != null) { Object value = ex.evaluate(f, ad.getType().getBinding()); fb.add(value); } else { fb.add(null); } } return fb.buildFeature(transformer.transformFid(f)); }
@Override public SimpleFeature next() { SimpleFeature f = wrapped.next(); for (AttributeDescriptor ad : target.getAttributeDescriptors()) { Expression ex = transformer.getExpression(ad.getLocalName()); if (ex != null) { Object value = ex.evaluate(f, ad.getType().getBinding()); fb.add(value); } else { fb.add(null); } } return fb.buildFeature(transformer.transformFid(f)); }
protected SimpleFeature feature(Object value) throws Exception { String typeSpec = "geom:Point,value:" + value.getClass().getSimpleName(); SimpleFeatureType type = DataUtilities.createType("Feature", typeSpec); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Coordinate coord = new Coordinate(0, 0); builder.add(gf.createPoint(coord)); builder.add(value); return builder.buildFeature(null); } }
/** Build a test feature with the specified id. */ protected static SimpleFeature buildFeature(String id) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(TYPE); builder.add(new Envelope(0, 1, 0, 1)); return builder.buildFeature(id); }