/** * 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); } }
tb.init(schema); tb.setName(coverageView.getName()); return new RetypingFeatureCollection(result, tb.buildFeatureType()) {
new HashSet<String>(Arrays.asList(query.getPropertyNames())); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(sft); for (AttributeDescriptor at : sft.getAttributeDescriptors()) { String attName = at.getLocalName();
/** * * 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; }
@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; }; }; }
tb.init(sft);
List<Join> joins = (List<Join>) hints.get(JOINS); SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.init(schema);
tb.init(fs.getSchema()); tb.setName(BRIDGES.getLocalPart()); SimpleFeatureType target = tb.buildFeatureType();
@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()); }
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(fsp.getSchema()); tb.remove("surfaceProperty"); // the store cannot create multi-geom tables it seems tb.remove("curveProperty"); // the store cannot create multi-geom tables it seems
private SimpleFeatureType buildTargetSchema(SimpleFeatureType sourceSchema) { if (sourceSchema.getDescriptor("location") != null) { return sourceSchema; } SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(sourceSchema); tb.add("location", String.class); return tb.buildFeatureType(); } }
static SimpleFeatureType retype(SimpleFeatureType featureType, JoinInfo join) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.init(featureType); for (JoinPart part : join.getParts()) { b.add(part.getAttributeName(), SimpleFeature.class); } return b.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 appendAttributes( SimpleFeatureType acc, SimpleFeatureType typeToAppend) { if (typeToAppend == null) { return acc; } SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(acc); for (AttributeDescriptor ad : typeToAppend.getAttributeDescriptors()) { // only add attributes that we don't already have if (acc.getDescriptor(ad.getLocalName()) == null) { tb.add(ad); } } return tb.buildFeatureType(); }
/** * Copys a feature type. * * <p>This method does a deep copy in that all individual attributes are copied as well. */ public static SimpleFeatureType copy(SimpleFeatureType original) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); // initialize the builder b.init(original); // clear attributes b.attributes().clear(); // add attributes in order for (AttributeDescriptor descriptor : original.getAttributeDescriptors()) { AttributeTypeBuilder ab = new AttributeTypeBuilder(b.factory); ab.init(descriptor); b.add(ab.buildDescriptor(descriptor.getLocalName())); } return b.buildFeatureType(); } }
public void testCreateSchema() throws IOException { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(lobSchema); tb.setName(tname("testLobCreate")); SimpleFeatureType ft = tb.buildFeatureType(); if (Arrays.asList(dataStore.getTypeNames()).contains(ft.getTypeName())) { dataStore.removeSchema(ft.getTypeName()); } dataStore.createSchema(ft); SimpleFeatureType ft2 = dataStore.getSchema(ft.getTypeName()); assertFeatureTypesEqual(ft, ft2); } }
public void testInitGeometryless() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("testGeometryless"); builder.add("integer", Integer.class); SimpleFeatureType type1 = builder.buildFeatureType(); builder = new SimpleFeatureTypeBuilder(); builder.init(type1); SimpleFeatureType type2 = builder.buildFeatureType(); assertEquals(type1, type2); }
public void testSchema() throws Exception { // see http://jira.codehaus.org/browse/GEOT-1616 SimpleFeatureType original = delegate.getSchema(); String newName = original.getTypeName() + "xxx"; SimpleFeatureTypeBuilder stb = new SimpleFeatureTypeBuilder(); stb.init(original); stb.setName(newName); SimpleFeatureType renamed = stb.buildFeatureType(); ReTypingFeatureCollection rtc = new ReTypingFeatureCollection(delegate, renamed); assertEquals(renamed, rtc.getSchema()); }
public void testMaintainDefaultGeometryOnInit() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("testGeometries"); builder.add("geo1", Point.class, DefaultGeographicCRS.WGS84); builder.add("geo2", Polygon.class, DefaultGeographicCRS.WGS84); builder.setDefaultGeometry("geo2"); SimpleFeatureType type1 = builder.buildFeatureType(); builder = new SimpleFeatureTypeBuilder(); builder.init(type1); SimpleFeatureType type2 = builder.buildFeatureType(); assertEquals("geo2", type1.getGeometryDescriptor().getLocalName()); assertEquals("geo2", type2.getGeometryDescriptor().getLocalName()); }
public void testRemoveDefaultGeometryAfterInit() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("testGeometries"); builder.add("geo1", Point.class, DefaultGeographicCRS.WGS84); builder.add("geo2", Polygon.class, DefaultGeographicCRS.WGS84); builder.setDefaultGeometry("geo2"); SimpleFeatureType type1 = builder.buildFeatureType(); builder = new SimpleFeatureTypeBuilder(); builder.init(type1); builder.remove("geo2"); SimpleFeatureType type2 = builder.buildFeatureType(); assertEquals("geo2", type1.getGeometryDescriptor().getLocalName()); assertEquals("geo1", type2.getGeometryDescriptor().getLocalName()); } }