static SimpleFeatureType makeContourSchema() { /* Create the output feature schema. */ SimpleFeatureTypeBuilder tbuilder = new SimpleFeatureTypeBuilder(); tbuilder.setName("contours"); tbuilder.setCRS(DefaultGeographicCRS.WGS84); // Do not use "geom" or "geometry" below, it seems to broke shapefile generation tbuilder.add("the_geom", MultiPolygon.class); tbuilder.add("time", Integer.class); // TODO change to something more descriptive and lowercase return tbuilder.buildFeatureType(); }
public RetypingFeatureReader( FeatureReader<SimpleFeatureType, SimpleFeature> delegate, SimpleFeatureType target) { this.delegate = delegate; this.builder = new SimpleFeatureBuilder(target); }
public SimpleFeatureType getFeatureType() { return builder.getFeatureType(); }
@Test public void testPerserveUserData() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("foo"); tb.setSRS("epsg:4326"); 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"); DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType()); features.add(f);
/** * * Takes into account eventual joins * * @param query * @return */ public SimpleFeatureType getFeatureType(Query query) { SimpleFeatureType result; if (query.getPropertyNames() != Query.ALL_NAMES) { result = SimpleFeatureTypeBuilder.retype(featureType, query.getPropertyNames()); } else { result = featureType; } // add back the joined features in case of join if (!query.getJoins().isEmpty()) { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(result); for (Join join : query.getJoins()) { String joinedFeatureAttribute = join.getAlias(); if (joinedFeatureAttribute == null) { joinedFeatureAttribute = join.getTypeName(); } tb.add(joinedFeatureAttribute, SimpleFeature.class); } result = tb.buildFeatureType(); } return result; }
/** * Transforms the original feature type into a destination one according to the renaming rules. * For the moment, it's just a feature type name replacement * * @param original * @throws IOException */ protected SimpleFeatureType transformFeatureType(SimpleFeatureType original) throws IOException { String transfomedName = transformFeatureTypeName(original.getTypeName()); if (transfomedName.equals(original.getTypeName())) return original; try { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.init(original); b.setName(transfomedName); return b.buildFeatureType(); } catch (Exception e) { throw new DataSourceException("Could not build the renamed feature type.", e); } }
/** * 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; }
@Override public SimpleFeature next() throws NoSuchElementException { SimpleFeature next = delegate.next(); accumulateAttributes(next); return builder.buildFeature(next.getID()); }
/** * Recursively breaks down SimpleFeatures that may contain other features as attributes to * accumulate simple attribute values to a List * * @param attributeValues The List of attribute values * @param feature A SimpleFeature to harvest attributes */ private void accumulateAttributes(SimpleFeature feature) { for (int i = 0; i < feature.getAttributes().size(); i++) { Object attr = feature.getAttribute(i); if (attr instanceof SimpleFeature) { // go forth and harvest attrubutes accumulateAttributes((SimpleFeature) attr); } else { builder.add(attr); } } } }
static SimpleFeatureType makePointSchema() { SimpleFeatureTypeBuilder tbuilder = new SimpleFeatureTypeBuilder(); tbuilder.setName("points"); tbuilder.setCRS(DefaultGeographicCRS.WGS84); tbuilder.add("Geometry", Point.class); tbuilder.add("Time", Integer.class); return tbuilder.buildFeatureType(); }
@Before public void setup() throws SchemaException { SimpleFeatureType originalSchema = DataUtilities.createType( "BasicPolygons", "the_geom:MultiPolygon:srid=4326,ID:String,value:int"); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(originalSchema); tb.setName("BasicPolygons2"); renamedSchema = tb.buildFeatureType(); collection = new ListFeatureCollection(originalSchema) { public void accepts(FeatureVisitor visitor, ProgressListener progress) throws java.io.IOException { lastVisitor = visitor; }; }; }
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; }
public RetypingFeatureWriter( FeatureWriter<SimpleFeatureType, SimpleFeature> delegate, SimpleFeatureType target) { this.delegate = delegate; this.builder = new SimpleFeatureBuilder(target); }
public SimpleFeatureType getFeatureType() { return builder.getFeatureType(); }
static SimpleFeatureType makeContourSchema() { /* Create the output feature schema. */ SimpleFeatureTypeBuilder tbuilder = new SimpleFeatureTypeBuilder(); tbuilder.setName("contours"); tbuilder.setCRS(DefaultGeographicCRS.WGS84); tbuilder.add("Geometry", MultiPolygon.class); tbuilder.add("Time", Integer.class); return tbuilder.buildFeatureType(); }
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; }
public FlatteningFeatureIterator( SimpleFeatureIterator delegate, SimpleFeatureType flattenedType) { this.delegate = delegate; this.builder = new SimpleFeatureBuilder(flattenedType); }
/** * Flattens a SimpleFeatureCollection that may contain SimpleFeatures as attributes of other * features. * * @param collection The input SimpleFeatureCollection * @return A SimpleFeatureCollection whose features have no SimpleFeature attributes, or the * original one, if no SimpleFeature attributes were found */ public static SimpleFeatureCollection flatten(SimpleFeatureCollection collection) { SimpleFeatureType schema = collection.getSchema(); // collect the attributes List<AttributeDescriptor> attributeDescriptors = new ArrayList<AttributeDescriptor>(); scanAttributeDescriptors(attributeDescriptors, schema, null); // build the flattened feature type SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(schema.getName()); for (AttributeDescriptor desc : attributeDescriptors) builder.add(desc); SimpleFeatureType flattenedType = builder.buildFeatureType(); // if the number of attributes is the same, we did not encounter a new attribute if (collection.getSchema().getAttributeCount() == flattenedType.getAttributeCount()) { return collection; } return new FlatteningFeatureCollection(collection, flattenedType); }
public RetypingIterator(SimpleFeatureIterator delegate, SimpleFeatureType target) { this.delegate = delegate; this.builder = new SimpleFeatureBuilder(target); }