/** * Recursively scans a SimpleFeature for SimpleFeature attributes in order to build a * "flattened" list of attributes * * @param attributeDescriptors A List of attribute descriptors, populated recursively * @param featuretype The feature type to scan * @param attrAlias An alias for adding as a prefix to the simple attribute names */ private static void scanAttributeDescriptors( List<AttributeDescriptor> attributeDescriptors, SimpleFeatureType featureType, String attrAlias) { List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors(); for (int i = 0; i < descriptors.size(); i++) { AttributeDescriptor ad = descriptors.get(i); SimpleFeatureType joinedSchema = (SimpleFeatureType) ad.getUserData().get(ContentDataStore.JOINED_FEATURE_TYPE); String name = (attrAlias != null ? attrAlias + "." : "") + ad.getLocalName(); if (joinedSchema != null) { // go forth and harvest feature attribute types scanAttributeDescriptors(attributeDescriptors, joinedSchema, name); } else { // this is a common (non-feature) attribute type AttributeTypeBuilder build = new AttributeTypeBuilder(); build.init(ad); AttributeDescriptor descriptor = build.buildDescriptor(name); attributeDescriptors.add(descriptor); } } }
AttributeTypeBuilder b = new AttributeTypeBuilder(); b.init(old); b.setCRS(getCRS(info.getSRS()));
/** * Constructs the builder specifying the factory for creating feature and feature collection * types. */ public SimpleFeatureTypeBuilder(FeatureTypeFactory factory) { this.factory = factory; attributeBuilder = new AttributeTypeBuilder(factory); setBindings(new SimpleSchema()); reset(); }
static AttributeDescriptor newAtt(String name, Class c) { AttributeTypeBuilder ab = new AttributeTypeBuilder(); ab.setBinding(c); return ab.buildDescriptor(name); }
/** * Create a fake property to store arbitrary text in a complex type. * * <p>Passed in value is converted to a string and then stored in the special <code> * simpleContent</code> attribute. * * @param type * @param value * @return */ Attribute buildTextContent(AttributeType type, Object value) { AttributeTypeBuilder atb = new AttributeTypeBuilder(); atb.setName(ComplexFeatureConstants.SIMPLE_CONTENT.getLocalPart()); atb.setBinding(String.class); AttributeType textContentType = atb.buildType(); return buildSimpleContentInternal(textContentType, value); }
static AttributeDescriptor newAtt(String name, Class c, boolean nillable) { AttributeTypeBuilder ab = new AttributeTypeBuilder(); ab.setNillable(nillable); ab.setBinding(c); return ab.buildDescriptor(name); }
AttributeTypeBuilder ab = new AttributeTypeBuilder(); Object result = expression.evaluate(originalFeature); Class computedBinding = null;
/** * 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 static AttributeDescriptor getChoiceAttrType2() { AttributeTypeBuilder ab = new AttributeTypeBuilder(); AttributeDescriptor[] choices = new AttributeDescriptor[2]; ab.setBinding(String.class); choices[0] = ab.buildDescriptor("testString"); ab.setBinding(Integer.class); choices[1] = ab.buildDescriptor("testInt"); return createChoiceAttrType("choiceTest2", choices); }
/** * Create a SimpleFeatureType with the same content; just updating the geometry attribute to * match the provided coordinate reference system. * * @param original SimpleFeatureType * @param crs CoordinateReferenceSystem of result * @return SimpleFeatureType updated with the provided CoordinateReferenceSystem */ public static SimpleFeatureType retype( SimpleFeatureType original, CoordinateReferenceSystem crs) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); // initialize the builder b.init(original); // clear the attributes b.attributes().clear(); // add attributes in order for (AttributeDescriptor descriptor : original.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) { GeometryDescriptor geometryDescriptor = (GeometryDescriptor) descriptor; AttributeTypeBuilder adjust = new AttributeTypeBuilder(b.factory); adjust.init(geometryDescriptor); adjust.setCRS(crs); b.add(adjust.buildDescriptor(geometryDescriptor.getLocalName())); continue; } b.add(descriptor); } return b.buildFeatureType(); }
builder.init(origType); AttributeTypeBuilder ab = new AttributeTypeBuilder(); if (query.getQueryJoins() != null) { for (int i = 0; i < query.getQueryJoins().size(); i++) {
public static AttributeDescriptor[] createType1Choices() { AttributeTypeBuilder ab = new AttributeTypeBuilder(); AttributeDescriptor[] choices = new AttributeDescriptor[3]; ab.setBinding(Byte.class); choices[0] = ab.buildDescriptor("testByte"); ab.setBinding(Double.class); choices[1] = ab.buildDescriptor("testDouble"); ab.setBinding(String.class); choices[2] = ab.buildDescriptor("testString"); return choices; }
AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.setName(schema.getName().getLocalPart() + "_" + descriptor.getName()); builder.setNillable(descriptor.isNillable());
@Override protected SimpleFeatureType buildTargetFeatureType() { // create schema SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor descriptor : delegate.getSchema().getAttributeDescriptors()) { if (!(descriptor.getType() instanceof GeometryTypeImpl) || (!delegate.getSchema().getGeometryDescriptor().equals(descriptor))) { tb.add(descriptor); } else { AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.setBinding(MultiPolygon.class); AttributeDescriptor attributeDescriptor = builder.buildDescriptor(descriptor.getLocalName(), builder.buildType()); tb.add(attributeDescriptor); if (tb.getDefaultGeometry() == null) { tb.setDefaultGeometry(descriptor.getLocalName()); } } } tb.setDescription(delegate.getSchema().getDescription()); tb.setCRS(delegate.getSchema().getCoordinateReferenceSystem()); tb.setName(delegate.getSchema().getName()); return tb.buildFeatureType(); }
static AttributeDescriptor getIntersectionType( SimpleFeatureCollection first, SimpleFeatureCollection second) { Class firstGeomType = first.getSchema().getGeometryDescriptor().getType().getBinding(); Class secondGeomType = second.getSchema().getGeometryDescriptor().getType().getBinding(); // figure out the output geometry type Class binding; if (isGeometryTypeIn(secondGeomType, Point.class)) { binding = Point.class; } else if (isGeometryTypeIn(secondGeomType, MultiPoint.class)) { binding = MultiPoint.class; } else if (isGeometryTypeIn(secondGeomType, LineString.class, MultiLineString.class)) { binding = MultiLineString.class; } else if (isGeometryTypeIn(secondGeomType, Polygon.class, MultiPolygon.class)) { if (isGeometryTypeIn(firstGeomType, Polygon.class, MultiPolygon.class)) { binding = MultiPolygon.class; } else { binding = MultiLineString.class; } } else { // we can't be more precise than this binding = Geometry.class; } AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.setName("the_geom"); builder.setBinding(binding); builder.setCRS(first.features().next().getFeatureType().getCoordinateReferenceSystem()); AttributeDescriptor descriptor = builder.buildDescriptor("the_geom"); return descriptor; }
@Test public void testCustomLengthExpressions() { AttributeTypeBuilder builder = new AttributeTypeBuilder(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Function length = ff.function("LengthFunction", new Expression[] {ff.property(".")}); // strict less builder.addRestriction(ff.less(length, ff.literal(20))); builder.setBinding(String.class); AttributeDescriptor attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); // flip expression builder.addRestriction(ff.greater(ff.literal(20), length)); builder.setBinding(String.class); attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); }
public void testModifyMadeUpGeometry() throws IOException { // GEOT-2371 SimpleFeatureType t = featureStore.getSchema(); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint(new Coordinate(-10, 0)); // make up a fake attribute with the same name, something that might happen // in chains of retyping where attributes are rebuilt AttributeTypeBuilder ab = new AttributeTypeBuilder(); ab.binding(Point.class); AttributeDescriptor madeUp = ab.buildDescriptor(aname("geometry")); featureStore.modifyFeatures( new AttributeDescriptor[] {madeUp}, new Object[] {point}, Filter.INCLUDE); SimpleFeatureCollection features = featureStore.getFeatures(); try (SimpleFeatureIterator i = features.features()) { assertTrue(i.hasNext()); while (i.hasNext()) { SimpleFeature feature = (SimpleFeature) i.next(); assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry")))); } } }
@Override protected void connect() throws Exception { super.connect(); // we need to use the type builder because the pk has min occurs = 1 on Oracle AttributeTypeBuilder atb = new AttributeTypeBuilder(); atb.setMinOccurs(isPkNillable() ? 0 : 1); atb.setMaxOccurs(1); atb.setNillable(isPkNillable()); atb.setName(FID); atb.setBinding(Integer.class); AttributeDescriptor fidDescriptor = atb.buildDescriptor(FID); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setNamespaceURI(dataStore.getNamespaceURI()); tb.setName(LAKESVIEW); tb.add(fidDescriptor); tb.add(ID, Integer.class); tb.add(GEOM, Polygon.class, (CoordinateReferenceSystem) null); tb.add(NAME, String.class); lakeViewSchema = tb.buildFeatureType(); lakeViewPkSchema = tb.retype(lakeViewSchema, new String[] {ID, GEOM, NAME}); }
if (sameNames(features.getSchema(), descriptor) && !sameTypes(features.getSchema(), descriptor)) { AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.setName(descriptor.getLocalName()); builder.setNillable(descriptor.isNillable());
public void testAttributeBuilder() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(); AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.binding(Integer.class); builder.minOccurs(1).maxOccurs(1); builder.defaultValue(0); builder.name("percent").description("Percent between 0 and 100"); builder.restriction(ff.greaterOrEqual(ff.property("."), ff.literal(0))) .restriction(ff.lessOrEqual(ff.property("."), ff.literal(100))); final AttributeType PERCENT = builder.buildType(); builder.minOccurs(1).maxOccurs(1); builder.defaultValue(0); builder.name("percent").description("Percent between 0 and 100"); AttributeDescriptor a = builder.buildDescriptor("a", PERCENT); assertSame(a.getType(), PERCENT); assertEquals(a.getDefaultValue(), 0); Filter restrictions = ff.and(PERCENT.getRestrictions()); assertTrue(restrictions.evaluate(50)); assertFalse(restrictions.evaluate(150)); }