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; } }
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()); if (schema.getDescriptor(queriedAtts[i]) != null) { allowedAtts.add(queriedAtts[i]); } else {
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 modifyFeatures(AttributeDescriptor[] type, Object[] values, Filter filter) throws IOException { SimpleFeatureType original = typeMap.getOriginalFeatureType(); // map back attribute types and values to the original values AttributeDescriptor[] originalTypes = new AttributeDescriptor[type.length]; Object[] originalValues = new Object[values.length]; for (int i = 0; i < values.length; i++) { originalTypes[i] = original.getDescriptor(type[i].getName()); if (values[i] != null) { Class<?> target = originalTypes[i].getType().getBinding(); originalValues[i] = Converters.convert(values[i], target); if (originalValues[i] == null) throw new IOException("Could not map back " + values[i] + " to type " + target); } } featureStore() .modifyFeatures(originalTypes, originalValues, store.retypeFilter(filter, typeMap)); }
/** * 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); } } }
@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(); }
public ZonalStatisticsCollection( SimpleFeatureCollection data, String dataAttribute, SimpleFeatureCollection zones) { super(zones); this.dataAttribute = dataAttribute; this.data = data; SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor att : zones.getSchema().getAttributeDescriptors()) { tb.minOccurs(att.getMinOccurs()); tb.maxOccurs(att.getMaxOccurs()); tb.restrictions(att.getType().getRestrictions()); if (att instanceof GeometryDescriptor) { GeometryDescriptor gatt = (GeometryDescriptor) att; tb.crs(gatt.getCoordinateReferenceSystem()); } tb.add("z_" + att.getLocalName(), att.getType().getBinding()); } tb.add("count", Long.class); tb.add("min", Double.class); tb.add("max", Double.class); tb.add("sum", Double.class); tb.add("avg", Double.class); tb.add("stddev", Double.class); tb.setName(zones.getSchema().getName()); targetSchema = tb.buildFeatureType(); }
/** * Create the modified feature type. * * @param sourceFeatureType the source feature type * @return the modified feature type * @throws ProcessException errror */ private SimpleFeatureType createTargetFeatureType(FeatureType sourceFeatureType) throws ProcessException { try { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(sourceFeatureType.getName().getLocalPart()); typeBuilder.setNamespaceURI(sourceFeatureType.getName().getNamespaceURI()); AttributeDescriptor geomAttbType = sourceFeatureType.getGeometryDescriptor(); for (PropertyDescriptor attbType : sourceFeatureType.getDescriptors()) { if (attbType.equals(geomAttbType)) { typeBuilder.add(geomAttbType.getLocalName(), Point.class); } else { typeBuilder.add((AttributeDescriptor) attbType); } } typeBuilder.setDefaultGeometry( sourceFeatureType.getGeometryDescriptor().getLocalName()); return typeBuilder.buildFeatureType(); } catch (Exception e) { LOGGER.warning("Error creating type: " + e); throw new ProcessException("Error creating type: " + e, e); } }
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor descriptor : delegate.getSchema().getAttributeDescriptors()) { if (sameNames(features.getSchema(), descriptor) && !sameTypes(features.getSchema(), descriptor)) { AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.setName(descriptor.getLocalName()); builder.setNillable(descriptor.isNillable()); builder.setBinding(String.class); builder.setMinOccurs(descriptor.getMinOccurs()); builder.setMaxOccurs(descriptor.getMaxOccurs()); builder.setDefaultValue(descriptor.getDefaultValue()); builder.setCRS( this.delegate .features() .next() .getFeatureType() .getCoordinateReferenceSystem()); AttributeDescriptor attributeDescriptor = builder.buildDescriptor(descriptor.getName(), builder.buildType()); tb.add(attributeDescriptor); } else { tb.add(descriptor); for (AttributeDescriptor descriptor : features.getSchema().getAttributeDescriptors()) { if (!sameNames(delegate.getSchema(), descriptor) && !sameTypes(delegate.getSchema(), descriptor)) {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(featureType.getName()); builder.setAbstract(featureType.isAbstract()); builder.setDescription(featureType.getDescription()); if (featureType.getSuper() instanceof SimpleFeatureType) { builder.setSuperType((SimpleFeatureType) featureType.getSuper()); for (AttributeDescriptor descriptor : attributes) { if (descriptor instanceof GeometryDescriptor) { String name = descriptor.getLocalName(); Class<?> binding = descriptor.getType().getBinding(); builder.add(name, binding, crs); } else { builder.setDefaultGeometry(defaultGeometry.getLocalName()); featureType = builder.buildFeatureType();
CoordinateReferenceSystem incomingCRS = incoming.getCoordinateReferenceSystem(); if (incomingCRS == null) { incoming.getGeometryDescriptor().getCoordinateReferenceSystem(); SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.init(incoming); 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);
if (storeWriter == null) { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor d : original.getAttributeDescriptors()) { if (Geometry.class.isAssignableFrom(d.getType().getBinding()) && multiWriter) { GeometryDescriptor gd = (GeometryDescriptor) d; builder.add(gd.getLocalName(), target, gd.getCoordinateReferenceSystem()); builder.setDefaultGeometry(gd.getLocalName()); } else { builder.add(d); builder.setNamespaceURI(original.getName().getURI());
/** * Gets a new schema, built remapping attribute names via the attributeMappings map. * * @param schema * @return */ private SimpleFeatureType remapSchema(SimpleFeatureType schema) { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(schema.getName()); for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) { if (attDesc instanceof GeometryDescriptor) { GeometryDescriptor geoDesc = (GeometryDescriptor) attDesc; builder.add( attributesMapping.get(attDesc.getLocalName()), attDesc.getType().getBinding(), geoDesc.getCoordinateReferenceSystem()); } else { List<Filter> filters = attDesc.getType().getRestrictions(); if (filters != null && !filters.isEmpty()) { builder.restrictions(filters); } builder.add( attributesMapping.get(attDesc.getLocalName()), attDesc.getType().getBinding()); } } return builder.buildFeatureType(); }
List<String> retainedAttributes, SimpleFeatureTypeBuilder tb) { for (AttributeDescriptor descriptor : schema.getAttributeDescriptors()) { isInRetainList = retainedAttributes.contains(descriptor.getLocalName()); logger.fine("Checking " + descriptor.getLocalName() + " --> " + isInRetainList); if (!isInRetainList || schema.getGeometryDescriptor() == descriptor) { continue; builder.setName(schema.getName().getLocalPart() + "_" + descriptor.getName()); builder.setNillable(descriptor.isNillable()); builder.setBinding(descriptor.getType().getBinding()); builder.setMinOccurs(descriptor.getMinOccurs()); builder.setMaxOccurs(descriptor.getMaxOccurs()); builder.setDefaultValue(descriptor.getDefaultValue()); builder.setCRS(schema.getCoordinateReferenceSystem()); AttributeDescriptor intersectionDescriptor = builder.buildDescriptor( schema.getName().getLocalPart() + "_" + descriptor.getName(), descriptor.getType()); tb.add(intersectionDescriptor); tb.addBinding(descriptor.getType());
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();
throws ProcessException { try { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(sourceFeatureType.getName().getLocalPart()); typeBuilder.setNamespaceURI(sourceFeatureType.getName().getNamespaceURI()); AttributeDescriptor geomAttbType = sourceFeatureType.getGeometryDescriptor(); for (PropertyDescriptor attbType : sourceFeatureType.getDescriptors()) { if (attbType.equals(geomAttbType)) { typeBuilder.add(geomAttbType.getLocalName(), Point.class); } else { typeBuilder.add((AttributeDescriptor) attbType); .add("nearest_bearing", Double.class); typeBuilder.setDefaultGeometry( sourceFeatureType.getGeometryDescriptor().getLocalName()); return typeBuilder.buildFeatureType(); } catch (Exception e) {
/** * Create a new {@link OracleFeatureTypeMapper} on top of the original featureType provided * * @param featureType * @throws CQLException */ public OracleFeatureTypeMapper(SimpleFeatureType featureType) throws CQLException { wrappedFeatureType = featureType; originalName = featureType.getName(); mappedName = originalName.getLocalPart(); mappedName = remap(mappedName); List<AttributeDescriptor> attributes = featureType.getAttributeDescriptors(); definitions = new LinkedList<Definition>(); definitionsMapping = new HashMap<Name, Definition>(); // Loop over attributes and prepare the definitions for (AttributeDescriptor attribute : attributes) { final String originalAttribute = attribute.getLocalName(); final AttributeType type = attribute.getType(); final Class<?> binding = type.getBinding(); String attributeName = remap(originalAttribute); // Create the definition to map the original attribute to the Oracle specific one final Definition definition = new Definition(originalAttribute, ECQL.toExpression(attributeName), binding); definitions.add(definition); definitionsMapping.put(attribute.getName(), definition); } remapFeatureType(); }
@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)); }
/** * Checks if the feature type specified is a GridCoverage wrapper * * @param featureType * @return */ public static boolean isWrappedCoverage(SimpleFeatureType featureType) { if (!"GridCoverage".equals(featureType.getName().getLocalPart())) return false; if (featureType.getAttributeCount() != 2) return false; AttributeDescriptor polyDescriptor = featureType.getDescriptor("geom"); if (polyDescriptor == null || !Polygon.class.equals(polyDescriptor.getType().getBinding())) return false; AttributeDescriptor gridDescriptor = featureType.getDescriptor("grid"); if (gridDescriptor == null || !GridCoverage.class.equals(gridDescriptor.getType().getBinding())) return false; return true; }
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); }