public SimpleFeature next() throws NoSuchElementException { final SimpleFeature next = delegate.next(); // check all write protected attributes are null final SimpleFeatureType featureType = next.getFeatureType(); for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { String name = att.getLocalName(); if (!writableAttributes.contains(name)) { Object value = next.getAttribute(name); if (value != null) { String typeName = getSchema().getName().getLocalPart(); if (response == Response.CHALLENGE) { throw SecureCatalogImpl.unauthorizedAccess(typeName); } else { throw new UnsupportedOperationException( "Trying to write on the write protected attribute " + name); } } } } return next; } }
public SimpleFeatureCollection getFeatures(Filter filter) throws IOException { return getFeatures(new Query(schema.getTypeName(), filter)); }
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 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); } } }
public boolean hasNext() { while (next == null && delegate.hasNext()) { boolean clippedOut = false; SimpleFeature f = delegate.next(); for (AttributeDescriptor ad : f.getFeatureType().getAttributeDescriptors()) { Object attribute = f.getAttribute(ad.getName()); if (ad instanceof GeometryDescriptor) { Class target = ad.getType().getBinding(); attribute = clipGeometry( (Geometry) attribute, target, ((GeometryDescriptor) ad).getCoordinateReferenceSystem()); if (attribute == null && f.getFeatureType().getGeometryDescriptor() == ad) { fb.reset(); clippedOut = true; break; fb.add(attribute); next = fb.buildFeature(f.getID()); fb.reset();
public SimpleFeature next() throws NoSuchElementException { SimpleFeature zone = zones.next(); Geometry zoneGeom = (Geometry) zone.getDefaultGeometry(); CoordinateReferenceSystem dataCrs = data.getSchema().getCoordinateReferenceSystem(); CoordinateReferenceSystem zonesCrs = builder.getFeatureType() .getGeometryDescriptor() .getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(zonesCrs, dataCrs)) { zoneGeom = JTS.transform(zoneGeom, CRS.findMathTransform(zonesCrs, dataCrs, true)); SimpleFeatureCollection zoneCollection = data.subCollection(areaFilter); Results stats = new AggregateProcess() builder.addAll(zone.getAttributes()); if (stats != null) { builder.add(stats.getCount()); builder.add(stats.getMin()); builder.add(stats.getMax()); builder.add(stats.getStandardDeviation()); return builder.buildFeature(zone.getID()); } catch (Exception e) { throw new ProcessException("Failed to compute statistics on feature " + zone, e);
@Override protected SimpleFeatureType buildTargetFeatureType() { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor ad : delegate.getSchema().getAttributeDescriptors()) { if (ad instanceof GeometryDescriptor) { GeometryDescriptor gd = (GeometryDescriptor) ad; Class<?> binding = ad.getType().getBinding(); if (Point.class.isAssignableFrom(binding)) { tb.add(ad); } else { tb.minOccurs(ad.getMinOccurs()); tb.maxOccurs(ad.getMaxOccurs()); tb.nillable(ad.isNillable()); tb.add(ad.getLocalName(), Point.class, gd.getCoordinateReferenceSystem()); } } else { tb.add(ad); } } tb.setName(delegate.getSchema().getName()); return tb.buildFeatureType(); }
CoordinateReferenceSystem incomingCRS = incoming.getCoordinateReferenceSystem(); if (incomingCRS == null) { incoming.getGeometryDescriptor().getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(incomingCRS, DefaultGeographicCRS.WGS84)) { throw new IllegalArgumentException( "Unsupported coordinate reference system, only WGS84 supported"); builder.setName(name(incoming.getTypeName())); incoming = builder.buildFeatureType(); String gdName = incoming.getGeometryDescriptor().getLocalName(); for (AttributeDescriptor ad : incoming.getAttributeDescriptors()) { String adName = ad.getLocalName(); if (gdName.equals(adName)) { ad.getUserData().put(KEY_mapping, geometryMapping); ad.getUserData().put(KEY_encoding, "GeoJSON"); } else { ad.getUserData().put(KEY_mapping, "properties." + adName); incoming.getUserData().put(KEY_collection, incoming.getTypeName()); .createCollection(incoming.getTypeName(), new BasicDBObject()) .createIndex(new BasicDBObject(geometryMapping, "2dsphere")); ContentEntry entry = entry(incoming.getName()); ContentState state = entry.getState(null); state.setFeatureType(incoming);
public void testGetFeatureStoreModifyFeatures1() throws IOException { SimpleFeatureStore road = (SimpleFeatureStore) dataStore.getFeatureSource(tname("road")); // FilterFactory factory = FilterFactoryFinder.createFilterFactory(); // rd1Filter = factory.createFidFilter( roadFeatures[0].getID() ); Object changed = Integer.valueOf(5); AttributeDescriptor name = td.roadType.getDescriptor(aname("id")); road.modifyFeatures(name, changed, td.rd1Filter); SimpleFeatureCollection results = road.getFeatures(td.rd1Filter); try (SimpleFeatureIterator features = results.features()) { assertTrue(features.hasNext()); assertEquals(5, ((Number) features.next().getAttribute(aname("id"))).intValue()); } }
@Override public SimpleFeature next() throws IOException { SimpleFeature f = wrapped.next(); for (AttributeDescriptor ad : target.getAttributeDescriptors()) { Expression ex = transformer.getExpression(ad.getLocalName()); if (ex != null) { Object value = ex.evaluate(f, ad.getType().getBinding()); fb.add(value); } else { fb.add(null); } } return fb.buildFeature(transformer.transformFid(f)); }
@Test public void testModify() throws Exception { final Query queryAll = new Query(RENAMED); SimpleFeatureStore store; store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED); SimpleFeature original = store.getFeatures(fidFilter).features().next(); String newAddress = ((String) original.getAttribute("ADDRESS")) + " xxx"; store.modifyFeatures( original.getFeatureType().getDescriptor("ADDRESS"), newAddress, fidFilter); SimpleFeature modified = store.getFeatures(fidFilter).features().next(); assertEquals(newAddress, modified.getAttribute("ADDRESS")); }
public static SimpleFeature feature(SimpleFeatureType fType, String fid, Node node) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(fType); int attributeCount = fType.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { AttributeDescriptor att = fType.getDescriptor(i); AttributeType attType = att.getType(); Object attValue = node.getChildValue(att.getLocalName()); if ((attValue != null) && !attType.getBinding().isAssignableFrom(attValue.getClass())) { // type mismatch, to try convert Object converted = Converters.convert(attValue, attType.getBinding()); if (converted != null) { attValue = converted; } } b.add(attValue); } // create the feature return b.buildFeature(fid); }
@Test public void testFeautureSourceFidFilter() throws Exception { // grab the last feature in the collection (there are more than one) SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); // build a filter that will retrieve that feature only FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); final String fid = RENAMED + ".1107531701011"; Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter)); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertEquals(1, fc.size()); FeatureIterator<SimpleFeature> it = fc.features(); assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertFalse(it.hasNext()); it.close(); assertEquals(fid, sf.getID()); }
public void testFixture() throws Exception { SimpleFeatureType type = DataUtilities.createType( "namespace.typename", "name:String,id:0,geom:MultiLineString"); assertEquals("namespace", "namespace", type.getName().getNamespaceURI()); assertEquals("typename", "typename", type.getTypeName()); assertEquals("attributes", 3, type.getAttributeCount()); assertEquals("a1", "name", type.getDescriptor(0).getLocalName()); assertEquals("a1", String.class, type.getDescriptor(0).getType().getBinding()); assertEquals("a2", "id", type.getDescriptor(1).getLocalName()); assertEquals("a2", Integer.class, type.getDescriptor(1).getType().getBinding()); assertEquals("a3", "geom", type.getDescriptor(2).getLocalName()); assertEquals("a3", MultiLineString.class, type.getDescriptor(2).getType().getBinding()); }
/** * 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 testNaturalSortingAsc() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); try (SimpleFeatureIterator features = featureSource.getFeatures(q).features()) { String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) <= 0); prevId = currId; } } }
public void testGetFeatureStoreModifyFeatures1() throws IOException { SimpleFeatureStore road = (SimpleFeatureStore) data.getFeatureSource("road"); AttributeDescriptor descriptor = roadType.getDescriptor("name"); road.modifyFeatures(descriptor.getName(), "changed", rd1Filter); SimpleFeatureCollection results = road.getFeatures(rd1Filter); assertEquals("changed", results.features().next().getAttribute("name")); }
String[] propNames = null; if (query.retrieveAllProperties()) { List<String> props = new ArrayList(); for (int i = 0; i < schema.getAttributeCount(); i++) { AttributeDescriptor att = schema.getDescriptor(i); if (Feature.class.isAssignableFrom(att.getType().getBinding()) && !query.getJoins().isEmpty()) { continue; props.add(att.getLocalName()); String[] queriedAtts = query.getPropertyNames(); int queriedAttCount = queriedAtts.length; List allowedAtts = new LinkedList(); if (schema.getDescriptor(queriedAtts[i]) != null) { allowedAtts.add(queriedAtts[i]); } else {
@Test public void testGetFeaturesReader() throws Exception { FeatureReader<SimpleFeatureType, SimpleFeature> fr; fr = rts.getFeatureReader(new Query(RENAMED), Transaction.AUTO_COMMIT); SimpleFeature sf = fr.next(); fr.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
SimpleFeature reproject(SimpleFeature feature) throws IOException { Object[] attributes = new Object[schema.getAttributeCount()]; AttributeDescriptor type = schema.getDescriptor(i); Object object = feature.getAttribute(type.getName()); SimpleFeature f = SimpleFeatureBuilder.build(schema, attributes, feature.getID()); f.getUserData().putAll(feature.getUserData()); return f; } catch (IllegalAttributeException e) {