public void write() throws IOException { try { SimpleFeatureType target = getFeatureType(); for (int i = 0; i < target.getAttributeCount(); i++) { AttributeDescriptor at = target.getDescriptor(i); Object value = retyped.getAttribute(i); current.setAttribute(at.getLocalName(), value); } delegate.write(); } catch (IllegalAttributeException e) { throw (IOException) new IOException("Error occurred while retyping feature").initCause(e); } } }
List<String> props = new ArrayList(); for (int i = 0; i < schema.getAttributeCount(); i++) { AttributeDescriptor att = schema.getDescriptor(i);
/** * 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); }
SimpleFeature reproject(SimpleFeature feature) throws IOException { Object[] attributes = new Object[schema.getAttributeCount()];
/** * Get the number of columns in the table * * @return the number of columns */ public int getColumnCount() { if (exception != null) { return 1; } return schema.getAttributeCount() + 1; }
public void reset() { values = new Object[featureType.getAttributeCount()]; next = 0; userData = null; featureUserData = null; }
/** */ public int getAttributeCount() { return this.schema.getAttributeCount(); }
@Override public int getAttributeCount() { return featureType.getAttributeCount(); }
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; }
public Object[] readAll() throws ArrayIndexOutOfBoundsException, IOException { int size = schema.getAttributeCount(); Object[] all = new Object[size]; for (int i = 0; i < size; i++) { all[i] = read(i); } return all; }
/** * Retrieve the attributeNames defined by the featureType * * @param featureType * @return array of simple attribute names */ public static String[] attributeNames(SimpleFeatureType featureType) { String[] names = new String[featureType.getAttributeCount()]; final int count = featureType.getAttributeCount(); for (int i = 0; i < count; i++) { names[i] = featureType.getDescriptor(i).getLocalName(); } return names; }
@Test public void testQueryWithPropertyNames() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); Query q = new Query(RENAMED, Filter.INCLUDE, new String[] {"ADDRESS"}); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = fs.getFeatures(q); assertEquals(1, fc.getSchema().getAttributeCount()); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(1, sf.getAttributeCount()); assertNull(sf.getAttribute("FID")); assertNotNull(sf.getAttribute("ADDRESS")); } }
private int searchByName(ElementValue[] value, SimpleFeatureType ft, int i, int j) { for (int k = 0; k < ft.getAttributeCount() && j == -1; k++) { // TODO use equals if ((ft.getDescriptor(k).getLocalName() == null && value[i].getElement().getName() == null) || ft.getDescriptor(k) .getLocalName() .equals(value[i].getElement().getName())) j = k; } return j; }
public void testDefaultValues() throws IllegalAttributeException { Object[] values = DataUtilities.defaultValues(roadType); assertNotNull(values); assertEquals(values.length, roadType.getAttributeCount()); }
public void testTemplateFeatureType() throws IllegalAttributeException { SimpleFeature feature = DataUtilities.template(roadType); assertNotNull(feature); assertEquals(roadType.getAttributeCount(), feature.getAttributeCount()); }
public void testGetSchemaRiver() throws IOException { SimpleFeatureType expected = td.riverType; SimpleFeatureType actual = dataStore.getSchema(tname("river")); assertEquals("name", aname(expected.getName()), actual.getName()); // assertEquals( "compare", 0, DataUtilities.compare( expected, actual )); assertEquals("attributeCount", expected.getAttributeCount(), actual.getAttributeCount()); assertFeatureTypesEqual(expected, actual); // assertEquals(expected, actual); }
public void testExposePrimaryKeyColumns() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("noninc")); assertEquals(2, fs.getSchema().getAttributeCount()); fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("noninc")); fs.setExposePrimaryKeyColumns(true); assertEquals(3, fs.getSchema().getAttributeCount()); }
public void testCreateSubTypeWithPropertyNotMatchingAnAttributeDescriptor() throws Exception { // creating a sub type with a property that doesn't map to an attribute descriptor SimpleFeatureType before = DataUtilities.createType("cities", "the_geom:Point:srid=4326,name:String"); SimpleFeatureType after = DataUtilities.createSubType( before, new String[] {"the_geom", "name", "not_existing"}); // the not_existing property should have been ignored assertEquals(2, after.getAttributeCount()); assertNotNull(after.getDescriptor("the_geom")); assertNotNull(after.getDescriptor("name")); }
public void testTemplateFeatureTypeString() throws IllegalAttributeException { SimpleFeature feature = DataUtilities.template(roadType, "Foo"); assertNotNull(feature); assertEquals(roadType.getAttributeCount(), feature.getAttributeCount()); assertEquals("Foo", feature.getID()); assertNull(feature.getAttribute("name")); assertNull(feature.getAttribute("id")); assertNull(feature.getAttribute("geom")); }
public void testSchema() throws Exception { SimpleFeatureType schema = featureSource.getSchema(); assertEquals(tname("ft1"), schema.getTypeName()); assertEquals(dataStore.getNamespaceURI(), schema.getName().getNamespaceURI()); assertTrue(areCRSEqual(getWGS84(), schema.getCoordinateReferenceSystem())); assertEquals(4, schema.getAttributeCount()); assertNotNull(schema.getDescriptor(aname("geometry"))); assertNotNull(schema.getDescriptor(aname("intProperty"))); assertNotNull(schema.getDescriptor(aname("stringProperty"))); assertNotNull(schema.getDescriptor(aname("doubleProperty"))); }