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(); }
/** * 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); } }
public void testMaintainDefaultGeometryOnRetype() { builder.setName("testGeometries"); builder.add("geo1", Point.class, DefaultGeographicCRS.WGS84); builder.add("geo2", Polygon.class, DefaultGeographicCRS.WGS84); builder.setDefaultGeometry("geo1"); SimpleFeatureType type = builder.buildFeatureType(); // performing an attribute selection, even changing order, should not change // the default geometry, that had a special meaning in the original source SimpleFeatureType retyped = SimpleFeatureTypeBuilder.retype(type, new String[] {"geo2", "geo1"}); assertEquals("geo1", retyped.getGeometryDescriptor().getLocalName()); }
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; }; }; }
public void testRetypeGeometryless() { builder.setName("testGeometryless"); builder.add("geo1", Point.class, DefaultGeographicCRS.WGS84); builder.add("integer", Integer.class); builder.setDefaultGeometry("geo1"); SimpleFeatureType type = builder.buildFeatureType(); // performing an attribute selection, even changing order, should not change // the default geometry, that had a special meaning in the original source SimpleFeatureType retyped = SimpleFeatureTypeBuilder.retype(type, new String[] {"integer"}); assertNotNull(retyped); assertNull(retyped.getGeometryDescriptor()); assertEquals(1, retyped.getAttributeCount()); assertEquals("integer", retyped.getAttributeDescriptors().get(0).getLocalName()); }
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(); }
result = new CompositeFeatureCollection(collections, schema); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(schema); tb.setName(coverageView.getName()); return new RetypingFeatureCollection(result, tb.buildFeatureType()) { @Override public SimpleFeatureIterator features() {
/** * 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); }
@Test public void testSimpleRename() throws IOException { SimpleFeatureSource fs = store.getFeatureSource(BUILDINGS.getLocalPart()); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(fs.getSchema()); tb.setName("houses"); SimpleFeatureType target = tb.buildFeatureType(); SimpleFeatureSource retyped = RetypingFeatureSource.getRetypingSource(fs, target); assertTrue(retyped instanceof SimpleFeatureLocking); assertEquals(target, retyped.getSchema()); assertEquals(target, ((DataStore) retyped.getDataStore()).getSchema("houses")); assertEquals(target, retyped.getFeatures().getSchema()); SimpleFeatureIterator it = retyped.getFeatures().features(); SimpleFeature f = it.next(); it.close(); assertEquals(target, f.getType()); }
SimpleFeatureType sft = (SimpleFeatureType) ft; SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(sft); tb.setName(info.getName()); tb.setNamespaceURI(info.getNamespace().getURI()); ad = handleDescriptor(ad, info); tb.add(ad); tb.add(ad); ft = tb.buildFeatureType();
assertNotNull(store.getSchema(BRIDGES.getLocalPart())); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(fs.getSchema()); tb.setName(BRIDGES.getLocalPart()); SimpleFeatureType target = tb.buildFeatureType();
SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.add("description", String.class); ftb.add("pointProperty", MultiPoint.class); // poly -> multi-poly ftb.add("intProperty", Long.class); // int -> long ftb.add("dateTimeProperty", Date.class); // timestamp -> date ftb.add("newProperty", String.class); // new property ftb.setName(RENAMED); // rename type primitive = ftb.buildFeatureType();
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.remove("curveProperty"); // the store cannot create multi-geom tables it seems tb.remove("uriProperty"); // this would render the store read only tb.setName("pgeo"); SimpleFeatureType schema = tb.buildFeatureType(); store.createSchema(schema); SimpleFeatureStore featureStore = (SimpleFeatureStore) store.getFeatureSource("pgeo");
@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);
/** * Builds a {@link RenamingGranuleSource} * * @param name The new type name * @param delegate The delegate to be wrapped */ public RenamingGranuleSource(String name, GranuleSource delegate) { this.name = name; this.delegate = delegate; SimpleFeatureType schema = null; try { schema = delegate.getSchema(); } catch (IOException e) { throw new RuntimeException(e); } this.delegateTypeName = schema.getTypeName(); SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.init(schema); builder.setName(name); this.schema = builder.buildFeatureType(); }
private static SimpleFeatureType createSchema( final String typeName, final String namespace, final List<AttributeDescriptor> properties) throws IOException { // TODO: use factory lookup mechanism once its in place SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(typeName); builder.setNamespaceURI(namespace); for (Iterator<AttributeDescriptor> it = properties.iterator(); it.hasNext(); ) { AttributeDescriptor attType = it.next(); builder.add(attType); } return builder.buildFeatureType(); }
public void nextWriter() throws IOException { // close the old shapefile this.writer.close(); this.dstore.dispose(); // prepare the new one currentFileId++; SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(schema); tb.setName(schema.getTypeName() + String.valueOf(currentFileId)); SimpleFeatureType ft = tb.buildFeatureType(); // set it up at the current store and writer createStoreAndWriter(ft); } }
private SimpleFeatureType createType(CoordinateReferenceSystem crs, boolean stretch) { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.add(ATTR_GEOM, Point.class, crs); tb.add(ATTR_COUNT, Integer.class); tb.add(ATTR_COUNT_UNIQUE, Integer.class); tb.add(ATTR_BOUNDING_BOX_GEOM, Polygon.class); tb.add(ATTR_BOUNDING_BOX, String.class); if (stretch) { tb.add(ATTR_NORM_COUNT, Double.class); tb.add(ATTR_NORM_COUNT_UNIQUE, Double.class); } tb.setName("stackedPoint"); SimpleFeatureType sfType = tb.buildFeatureType(); return sfType; }
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); }