/** * Recursively breaks down SimpleFeatures that may contain other features as attributes to * accumulate simple attribute values to a List * * @param attributeValues The List of attribute values * @param feature A SimpleFeature to harvest attributes */ private void accumulateAttributes(SimpleFeature feature) { for (int i = 0; i < feature.getAttributes().size(); i++) { Object attr = feature.getAttribute(i); if (attr instanceof SimpleFeature) { // go forth and harvest attrubutes accumulateAttributes((SimpleFeature) attr); } else { builder.add(attr); } } } }
public List<Object> getAttributes() { return feature.getAttributes(); }
public List<Object> getAttributes() { return delegate.getAttributes(); }
public List<Object> getAttributes() { return delegate.getAttributes(); }
/** * Checks if a feature is a joined one * * @param obj * @return */ public static boolean isJoinedFeature(Object obj) { if (!(obj instanceof SimpleFeature)) { return false; } SimpleFeature feature = (SimpleFeature) obj; for (Object att : feature.getAttributes()) { if (att != null && att instanceof SimpleFeature) { return true; } } return false; }
public void visit(Feature feature) { SimpleFeature simple = (SimpleFeature) feature; Object[] values = simple.getAttributes().toArray(); ArrayList<Object> row = new ArrayList<Object>(Arrays.asList(values)); row.add(0, simple.getID()); publish(row.toArray()); if (isCancelled()) listener.setCanceled(true); } },
SimpleFeature reproject(SimpleFeature feature) throws IOException { List<Object> attributes = feature.getAttributes(); for (int i = 0; i < attributes.size(); i++) { Object object = attributes.get(i); if (object instanceof Geometry) { // do the transformation Geometry geometry = (Geometry) object; try { attributes.set(i, tx.transform(geometry)); } catch (TransformException e) { String msg = "Error occured transforming " + geometry.toString(); throw (IOException) new IOException(msg).initCause(e); } } } try { return SimpleFeatureBuilder.build(schema, attributes, feature.getID()); } catch (IllegalAttributeException e) { String msg = "Error creating reprojeced feature"; throw (IOException) new IOException(msg).initCause(e); } } }
SimpleFeature reproject(SimpleFeature feature) throws IOException { List<Object> attributes = feature.getAttributes(); for (int i = 0; i < attributes.size(); i++) { Object object = attributes.get(i); if (object instanceof Geometry) { // do the transformation Geometry geometry = (Geometry) object; try { attributes.set(i, tx.transform(geometry)); } catch (TransformException e) { String msg = "Error occured transforming " + geometry.toString(); throw (IOException) new IOException(msg).initCause(e); } } } try { return SimpleFeatureBuilder.build(schema, attributes, feature.getID()); } catch (IllegalAttributeException e) { String msg = "Error creating reprojeced feature"; throw (IOException) new IOException(msg).initCause(e); } }
/** * Initialize the builder with the provided feature. * * <p>This method adds all the attributes from the provided feature. It is useful when copying a * feature. */ public void init(SimpleFeature feature) { reset(); // optimize the case in which we just build if (feature instanceof SimpleFeatureImpl) { SimpleFeatureImpl impl = (SimpleFeatureImpl) feature; System.arraycopy(impl.values, 0, values, 0, impl.values.length); if (impl.userData != null) { featureUserData = new HashMap(impl.userData); } } else { for (Object value : feature.getAttributes()) { add(value); } if (!feature.getUserData().isEmpty()) { featureUserData = new HashMap(feature.getUserData()); } } }
/** @see FeatureWriter#next() */ public final SimpleFeature next() throws IOException { if (hasNext()) { feature = filteredContent.next(); } else { final String newFid = newFid(); final SimpleFeature newFeature = featureBuilder.buildFeature(newFid); final List<Object> properties = newFeature.getAttributes(); feature = new MutableFIDFeature(properties, featureType, newFid); } return feature; }
public SimpleFeature next() throws NoSuchElementException { SimpleFeature f = delegate.next(); for (Object attribute : f.getAttributes()) { if ((attribute instanceof Geometry) && !(attribute instanceof Point)) { attribute = ((Geometry) attribute).getCentroid(); } fb.add(attribute); } return fb.buildFeature(f.getID()); } }
protected void assertDuplicate(String message, Object expected, Object value) { // Ensure value is equal to expected if (expected.getClass().isArray()) { int length1 = Array.getLength(expected); int length2 = Array.getLength(value); assertEquals(message, length1, length2); for (int i = 0; i < length1; i++) { assertDuplicate( message + "[" + i + "]", Array.get(expected, i), Array.get(value, i)); } // assertNotSame( message, expected, value ); } else if (expected instanceof SimpleFeature) { assertDuplicate( message, ((SimpleFeature) expected).getAttributes(), ((SimpleFeature) value).getAttributes()); } else { assertEquals(message, expected, value); } // Ensure Non Immutables are actually copied if (!immutable.contains(expected.getClass())) { // assertNotSame( message, expected, value ); } } }
public Object get(Object object, String xpath, Class target) { if (object instanceof SimpleFeature) { SimpleFeature f = (SimpleFeature) object; Object defaultGeometry = f.getDefaultGeometry(); // not found? Ok, let's do a lookup then... if (defaultGeometry == null) { for (Object o : f.getAttributes()) { if (o instanceof Geometry) { defaultGeometry = o; break; } } } return defaultGeometry; } if (object instanceof SimpleFeatureType) { SimpleFeatureType ft = (SimpleFeatureType) object; GeometryDescriptor gd = ft.getGeometryDescriptor(); if (gd == null) { // look for any geometry descriptor for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { if (Geometry.class.isAssignableFrom(ad.getType().getBinding())) { return ad; } } } return gd; } return null; }
public SimpleFeature next() throws NoSuchElementException { SimpleFeature f = delegate.next(); for (Object attribute : f.getAttributes()) { if (attribute instanceof Geometry) { if (preserveTopology) { attribute = TopologyPreservingSimplifier.simplify( (Geometry) attribute, distance); } else { attribute = DouglasPeuckerSimplifier.simplify((Geometry) attribute, distance); } } fb.add(attribute); } return fb.buildFeature(f.getID()); } }
public boolean hasNext() { while (next == null && delegate.hasNext()) { SimpleFeature f = delegate.next(); for (Object attribute : f.getAttributes()) { if (attribute instanceof Geometry) { Geometry geom = (Geometry) attribute; Filter overFilter = ff.contains(ff.property(dataGeomName), ff.literal(geom)); SimpleFeatureCollection subFeatureCollectionInclusion = this.secondFeatures.subCollection(overFilter); if (subFeatureCollectionInclusion.size() > 0) { next = f; } } } } return next != null; }
/** @see FeatureStore#addFeatures(SimpleFeatureCollection) */ public List<FeatureId> addFeatures( final FeatureCollection<SimpleFeatureType, SimpleFeature> collection) throws IOException { // System.err.println(">>addFeatures called at " + // Thread.currentThread().getName()); final String typeName = typeInfo.getFeatureTypeName(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = dataStore.getFeatureWriterAppend(typeName, transaction); final FeatureIterator<SimpleFeature> iterator = collection.features(); List<FeatureId> featureIds = new LinkedList<FeatureId>(); try { SimpleFeature toAdd; SimpleFeature newFeature; while (iterator.hasNext()) { toAdd = iterator.next(); newFeature = writer.next(); newFeature.setAttributes(toAdd.getAttributes()); writer.write(); featureIds.add(newFeature.getIdentifier()); } } finally { iterator.close(); writer.close(); } return featureIds; }
/** @see FeatureStore#setFeatures(FeatureReader) */ public void setFeatures(final FeatureReader<SimpleFeatureType, SimpleFeature> reader) throws IOException { final SimpleFeatureType readerType = reader.getFeatureType(); if (!getSchema().equals(readerType)) { throw new IllegalArgumentException("Type mismatch: " + readerType); } final String typeName = typeInfo.getFeatureTypeName(); final ISession session = getSession(); try { // truncate using this connection to apply or not depending on // whether a transaction is in progress truncate(typeName, session); } finally { session.dispose(); } final FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = dataStore.getFeatureWriterAppend(typeName, transaction); try { while (reader.hasNext()) { SimpleFeature feature = reader.next(); SimpleFeature newFeature = writer.next(); newFeature.setAttributes(feature.getAttributes()); writer.write(); } } finally { writer.close(); } }
public boolean hasNext() { while (next == null && delegate.hasNext()) { SimpleFeature f = delegate.next(); for (Object value : f.getAttributes()) { if (value instanceof Geometry) { Double fDistance = distance; if (this.attribute != null) { fDistance = Converters.convert( f.getAttribute(this.attribute), Double.class); } if (fDistance != null && fDistance != 0.0) { value = ((Geometry) value).buffer(fDistance); } } fb.add(value); } next = fb.buildFeature("" + count); count++; fb.reset(); } return next != null; }
public void testGetFeaturesWriterAdd() throws IOException { FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriter("road", Transaction.AUTO_COMMIT); SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); } assertFalse(writer.hasNext()); feature = (SimpleFeature) writer.next(); feature.setAttributes(newRoad.getAttributes()); writer.write(); assertFalse(writer.hasNext()); assertEquals(roadFeatures.length + 1, data.entry("road").getMemory().size()); }
public void testGetFeaturesWriterAdd() throws IOException { try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(tname("road"), Transaction.AUTO_COMMIT)) { SimpleFeature feature; while (writer.hasNext()) { feature = (SimpleFeature) writer.next(); } assertFalse(writer.hasNext()); feature = (SimpleFeature) writer.next(); feature.setAttributes(td.newRoad.getAttributes()); writer.write(); assertFalse(writer.hasNext()); assertEquals(td.roadFeatures.length + 1, count(tname("road"))); } }