/** * Adds an attribute. * * <p>This method should be called repeatedly for the number of attributes as specified by the * type of the feature. */ public void add(Object value) { set(next, value); next++; }
/** * Adds an attribute value by name. * * <p>This method can be used to add attribute values out of order. * * @param name The name of the attribute. * @param value The value of the attribute. * @throws IllegalArgumentException If no such attribute with teh specified name exists. */ public void set(Name name, Object value) { set(name.getLocalPart(), value); }
/** * Adds an attribute value by name. * * <p>This method can be used to add attribute values out of order. * * @param name The name of the attribute. * @param value The value of the attribute. * @throws IllegalArgumentException If no such attribute with teh specified name exists. */ public void set(String name, Object value) { int index = featureType.indexOf(name); if (index == -1) { throw new IllegalArgumentException("No such attribute:" + name); } set(index, value); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(FeatureType); SimpleFeature feature = (SimpleFeature) value; b.init(feature); b.set("name", node.getChildValue("name")); b.set("description", node.getChildValue("description")); // <element maxOccurs="unbounded" minOccurs="0" ref="kml:Feature"/> b.set("Feature", node.getChildValues(SimpleFeature.class)); return b.buildFeature(feature.getID()); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(FeatureType); SimpleFeature feature = (SimpleFeature) value; b.init(feature); b.set("name", node.getChildValue("name")); b.set("description", node.getChildValue("description")); // <element maxOccurs="unbounded" minOccurs="0" ref="kml:Feature"/> b.set("Feature", node.getChildValues(SimpleFeature.class)); return b.buildFeature(feature.getID()); } }
@Override public SimpleFeature next() throws NoSuchElementException { final SimpleFeature f = delegate.next(); fb.init(f); fb.set("location", location); return fb.buildFeature(f.getID()); } }
@Override protected SimpleFeature readFeature(final AttributeReader atts) throws IllegalAttributeException, IOException { final ArcSDEAttributeReader sdeAttReader = (ArcSDEAttributeReader) atts; final int attCount = sdeAttReader.getAttributeCount(); Object value; for (int index = 0; index < attCount; index++) { value = sdeAttReader.read(index); featureBuilder.set(index, value); } String fid = sdeAttReader.readFID(); SimpleFeature feature = featureBuilder.buildFeature(fid); return feature; } }
public void testSetNonSequential() throws Exception { GeometryFactory gf = new GeometryFactory(); builder.set("float", new Float(2.0)); builder.set("point", gf.createPoint(new Coordinate(0, 0))); builder.set("integer", Integer.valueOf(1)); SimpleFeature feature = builder.buildFeature("fid"); assertNotNull(feature); assertEquals(3, feature.getAttributeCount()); assertTrue(gf.createPoint(new Coordinate(0, 0)).equals(feature.getAttribute(0))); assertEquals(Integer.valueOf(1), feature.getAttribute(1)); assertEquals(new Float(2.0), feature.getAttribute(2)); }
public void testSetSequential() throws Exception { GeometryFactory gf = new GeometryFactory(); builder.set("point", gf.createPoint(new Coordinate(0, 0))); builder.set("integer", Integer.valueOf(1)); builder.set("float", new Float(2.0)); SimpleFeature feature = builder.buildFeature("fid"); assertNotNull(feature); assertEquals(3, feature.getAttributeCount()); assertTrue(gf.createPoint(new Coordinate(0, 0)).equals(feature.getAttribute(0))); assertEquals(Integer.valueOf(1), feature.getAttribute(1)); assertEquals(new Float(2.0), feature.getAttribute(2)); }
public boolean hasNext() { while (next == null && firstDelegate.hasNext()) { SimpleFeature f = firstDelegate.next(); for (PropertyDescriptor property : fb.getFeatureType().getDescriptors()) { fb.set(property.getName(), f.getAttribute(property.getName())); } next = fb.buildFeature(Integer.toString(iterationIndex)); fb.reset(); iterationIndex++; } while (next == null && secondDelegate.hasNext() && !firstDelegate.hasNext()) { SimpleFeature f = secondDelegate.next(); for (PropertyDescriptor property : fb.getFeatureType().getDescriptors()) { fb.set(property.getName(), f.getAttribute(property.getName())); } next = fb.buildFeature(Integer.toString(iterationIndex)); fb.reset(); iterationIndex++; } return next != null; }
@Override protected void setUp() throws Exception { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("test"); ftb.add("geom", Point.class); ftb.add("symb", String.class); ftb.add("icon", String.class); featureType = ftb.buildFeatureType(); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(featureType); fb.set("geom", new GeometryFactory().createPoint(new Coordinate(0, 0))); fb.set("symb", "0xF054"); fb.set("icon", "draw.png"); feature = fb.buildFeature(null); }
/** * Copies an existing feature, retyping it in the process. * * <p>If the feature type contains attributes in which the original feature does not have a * value for, the value in the resulting feature is set to <code>null</code>. * * @param feature The original feature. * @param SimpleFeatureBuilder A builder for the target feature type * @return The copied feature, with a new type. * @since 2.5.3 */ public static SimpleFeature retype(SimpleFeature feature, SimpleFeatureBuilder builder) { builder.reset(); for (AttributeDescriptor att : builder.getFeatureType().getAttributeDescriptors()) { Object value = feature.getAttribute(att.getName()); builder.set(att.getName(), value); } return builder.buildFeature(feature.getID()); }
public void testSetTooFew() throws Exception { builder.set("integer", Integer.valueOf(1)); SimpleFeature feature = builder.buildFeature("fid"); assertNotNull(feature); assertEquals(3, feature.getAttributeCount()); assertNull(feature.getAttribute(0)); assertEquals(Integer.valueOf(1), feature.getAttribute(1)); assertNull(feature.getAttribute(2)); }
SimpleFeature createFeatureSized(int sizeNum) { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("geotools"); ftb.add("size", Integer.class); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(ftb.buildFeatureType()); fb.set("size", sizeNum); SimpleFeature feature = fb.buildFeature(null); return feature; } }
public void testGetBoundsSupportsFeaturesWithoutGeometry() throws Exception { SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(data.getSchema("road")); featureBuilder.init(roadFeatures[0]); featureBuilder.set("geom", null); SimpleFeature feature = featureBuilder.buildFeature("road.rd0"); data.addFeature(feature); SimpleFeatureSource road = data.getFeatureSource("road"); assertEquals(roadBounds, road.getBounds(Query.ALL)); }
public void testGetAnyGeometry() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("test"); tb.setCRS(null); tb.add("g1", Point.class); tb.add("g2", Point.class); tb.setDefaultGeometry("g1"); SimpleFeatureType type = tb.buildFeatureType(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(type); b.set("g1", null); Point p = new GeometryFactory().createPoint(new Coordinate(0, 0)); b.set("g2", p); SimpleFeature feature = b.buildFeature(null); assertNull(feature.getDefaultGeometry()); assertEquals( p, SimpleFeaturePropertyAccessorFactory.DEFAULT_GEOMETRY_ACCESS.get( feature, "", Geometry.class)); } }
public void testSerialTransactions() throws IOException { SimpleFeatureStore st = (SimpleFeatureStore) dataStore.getFeatureSource(tname("ft1")); SimpleFeatureBuilder b = new SimpleFeatureBuilder(st.getSchema()); b.set(aname("intProperty"), Integer.valueOf(100)); SimpleFeature f1 = b.buildFeature(null); DefaultFeatureCollection features = new DefaultFeatureCollection(null, null); features.add(f1); try (Transaction tx1 = new DefaultTransaction()) { st.setTransaction(tx1); st.addFeatures(features); tx1.commit(); } assertEquals(4, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL)); try (Transaction tx2 = new DefaultTransaction()) { st.setTransaction(tx2); st.addFeatures(features); tx2.commit(); } assertEquals(5, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL)); } }