@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 String toString() { StringBuffer sb = new StringBuffer(getClass().getSimpleName()).append(":"); sb.append(getDescriptor().getName().getLocalPart()); if (!getDescriptor() .getName() .getLocalPart() .equals(getDescriptor().getType().getName().getLocalPart()) || id != null) { sb.append("<"); sb.append(getDescriptor().getType().getName().getLocalPart()); if (id != null) { sb.append(" id="); sb.append(id); } sb.append(">"); } sb.append("="); sb.append(value); return sb.toString(); }
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(); }
/** Initializes builder state from another attribute type. */ public AttributeTypeBuilder init(AttributeType type) { name = type.getName().getLocalPart(); separator = type.getName().getSeparator(); namespaceURI = type.getName().getNamespaceURI(); isAbstract = type.isAbstract(); if (type.getRestrictions() != null) { restrictions().addAll(type.getRestrictions()); } description = type.getDescription() != null ? type.getDescription().toString() : null; isIdentifiable = type.isIdentified(); binding = type.getBinding(); superType = type.getSuper(); if (type instanceof GeometryType) { crs = ((GeometryType) type).getCoordinateReferenceSystem(); } return this; }
/** * Get base (non-collection) type of simple content. * * @param type * @return */ static AttributeType getSimpleContentType(AttributeType type) { Class<?> binding = type.getBinding(); if (binding == Collection.class) { return getSimpleContentType(type.getSuper()); } else { return type; } }
/** * Complete the definition of a type and store it in the schema. * * <p>This method calls {@link AttributeType#getSuper()} (and {@link * ComplexType#getDescriptors()} where applicable) to ensure the construction of the type (a * concrete {@link AbstractLazyAttributeTypeImpl} or {@link AbstractLazyComplexTypeImpl} * sublass) is complete. This should be sufficient to avoid any nasty thread-safety surprises in * code using this schema. * * @param type the type to complete and store */ private void put(AttributeType type) { type.getSuper(); if (type instanceof ComplexType) { ((ComplexType) type).getDescriptors(); } put(type.getName(), type); } }
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();
List<AttributeDescriptor> atts = features.getSchema().getAttributeDescriptors(); for (int i = 0; i < atts.size(); i++) { if (atts.get(i).getLocalName().equals(attribute)) { attIndex = i; break; List uniqueValues = visitor.getResult().toList(); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.add("value", features.getSchema().getDescriptor(attIndex).getType().getBinding()); tb.setName("UniqueValue"); SimpleFeatureType ft = tb.buildFeatureType(); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(ft);
/** * 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; }
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()); AttributeDescriptor intersectionDescriptor = builder.buildDescriptor( schema.getName().getLocalPart() + "_" + descriptor.getName(), descriptor.getType()); tb.add(intersectionDescriptor); tb.addBinding(descriptor.getType());
SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder(); SimpleFeatureType origional = delegate.getSchema(); AttributeDescriptor descriptor = origional.getDescriptor(name); AttributeType attributeType = descriptor.getType(); binding = attributeType.getBinding(); AttributeType originalAttributeType = origional.getType(name); if (originalAttributeType != null && originalAttributeType instanceof GeometryType) { crs = geometryType.getCoordinateReferenceSystem(); } else { crs = origional.getCoordinateReferenceSystem(); build.crs(crs); build.add(name, binding); } else { build.add(name, binding);
/** * 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(); }
StringBuffer sql = new StringBuffer(); sql.append("INSERT INTO "); encodeTableName(featureType.getTypeName(), sql, null); for (int i = 0; i < featureType.getAttributeCount(); i++) { String colName = featureType.getDescriptor(i).getLocalName(); for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { String colName = att.getLocalName(); kind.geometryTypes.get(att.getName().getLocalPart()); dialect.prepareGeometryValue( geometryClass, getDescriptorDimension(att), getDescriptorSRID(att), att.getType().getBinding(), sql); } else {
public static DBObject convert(SimpleFeatureType ft) { DBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName()); Map<String, String> ftUserData = typeCheck(ft.getUserData()); if (!ftUserData.isEmpty()) { ftDBO.put(KEY_userData, new BasicDBObject(ftUserData)); GeometryDescriptor gd = ft.getGeometryDescriptor(); String gdLocalName = gd.getLocalName(); DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs == null) { crs = DefaultGeographicCRS.WGS84; for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { String adLocalName = ad.getLocalName(); DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName); if (!adLocalName.equals(gdLocalName)) { Object dv = ad.getDefaultValue(); if (dv != null) { adDBO.put(KEY_defaultValue, dv); adDBO.put(KEY_minOccurs, ad.getMinOccurs()); adDBO.put(KEY_maxOccurs, ad.getMaxOccurs()); ad instanceof GeometryDescriptor ? Geometry.class : ad.getType().getBinding(); adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName())); Map<String, String> adUserData = typeCheck(ad.getUserData());
Name name = type.getName(); String uri = name.getNamespaceURI(); String local = name.getLocalPart(); String binding; if (typeBindings.containsKey(name)) { binding = typeBindings.get(name) + ".class"; } else { binding = type.getBinding().getName() + ".class"; String isIdentified = type.isIdentified() ? "true" : "false"; String isAbstract = type.isAbstract() ? "true" : "false"; String restrictions = "null"; String superType = "null"; if (type.getSuper() != null) { superType = type.getSuper().getName() .getLocalPart().toUpperCase() + "_TYPE"; String superURI = type.getSuper().getName().getNamespaceURI(); if (!uri.equals(superURI)) { superType = ns2import.get(superURI) + "." + superType; AttributeType adType = ad.getType(); String adTypeName = adType.getName().getLocalPart().toUpperCase() + "_TYPE"; String adTypeURI = adType.getName().getNamespaceURI(); if (!uri.equals(adTypeURI)) { adTypeName = ns2import.get(adTypeURI) + "." + adTypeName; if (!type.getUserData().isEmpty()) {
type.setTargetNamespace(featureType.getName().getNamespaceURI()); type.setName(featureType.getTypeName() + "Type"); type.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); type.setBaseTypeDefinition(schemaIndex.getTypeDefinition(gml.qName("AbstractFeatureType"))); group.setCompositor(XSDCompositor.SEQUENCE_LITERAL); List attributes = featureType.getAttributeDescriptors(); for (int i = 0; i < attributes.size(); i++) { AttributeDescriptor attribute = (AttributeDescriptor) attributes.get(i); if (toFilter.contains(attribute.getLocalName())) { continue; element.setName(attribute.getLocalName()); element.setNillable(attribute.isNillable()); Class binding = attribute.getType().getBinding(); if (Point.class.isAssignableFrom(binding)) { element.setTypeDefinition( String attributeNs = attribute.getName().getNamespaceURI(); if (attributeNs != null && !attributeNs.trim().isEmpty()) { element.setTargetNamespace(attributeNs); } else { element.setTargetNamespace(featureType.getName().getNamespaceURI());
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 {
public void testSanity() { builder.setName("testName"); builder.setNamespaceURI("testNamespaceURI"); builder.add("point", Point.class, (CoordinateReferenceSystem) null); builder.add("integer", Integer.class); SimpleFeatureType type = builder.buildFeatureType(); assertNotNull(type); assertEquals(2, type.getAttributeCount()); AttributeType t = type.getType("point"); assertNotNull(t); assertEquals(Point.class, t.getBinding()); t = type.getType("integer"); assertNotNull(t); assertEquals(Integer.class, t.getBinding()); t = type.getGeometryDescriptor().getType(); assertNotNull(t); assertEquals(Point.class, t.getBinding()); }