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); } } }
/** * 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); } } }
private SimpleFeatureType appendAttributes( SimpleFeatureType acc, SimpleFeatureType typeToAppend) { if (typeToAppend == null) { return acc; } SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(acc); for (AttributeDescriptor ad : typeToAppend.getAttributeDescriptors()) { // only add attributes that we don't already have if (acc.getDescriptor(ad.getLocalName()) == null) { tb.add(ad); } } return tb.buildFeatureType(); }
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; } }
AttributeDescriptor att = schema.getDescriptor(i); props.add(att.getLocalName()); if (schema.getDescriptor(queriedAtts[i]) != null) { allowedAtts.add(queriedAtts[i]); } else {
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(sft); for (AttributeDescriptor at : sft.getAttributeDescriptors()) { String attName = at.getLocalName(); if (!properties.contains(attName)) { tb.remove(attName);
/** * Retrieve the specified column name * * @param column column index * @return the column name */ @Override public String getColumnName(int column) { if (column == 0) { return "FeatureIdentifer"; } return schema.getDescriptor(column - 1).getLocalName(); }
/** * Locates all geometry properties in the transformed type * * @return */ List<String> getGeometryPropertyNames() { List<String> result = new ArrayList<String>(); for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { if (ad instanceof GeometryDescriptor) { result.add(ad.getLocalName()); } } return result; }
public SumAreaVisitor(int attributeTypeIndex, SimpleFeatureType type) throws IllegalFilterException { this(factory.property(type.getDescriptor(attributeTypeIndex).getLocalName())); }
protected String findPrimaryKeyColumnName(SimpleFeatureType featureType) { String[] suffix = new String[] {"", "_1", "_2"}; String[] base = new String[] {"fid", "id", "gt_id", "ogc_fid"}; for (String b : base) { O: for (String s : suffix) { String name = b + s; for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { if (ad.getLocalName().equalsIgnoreCase(name)) { continue O; } } return name; } } // practically should never get here, but just fall back and fail later return "fid"; }
public SumAreaVisitor(String attrName, SimpleFeatureType type) throws IllegalFilterException { this(factory.property(type.getDescriptor(attrName).getLocalName())); }
private List<String> getRequiredAttributes(SimpleFeatureType schema) { List<String> result = new ArrayList<String>(); for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { if (ad.getMinOccurs() > 0) { result.add(ad.getLocalName()); } } return result; }
private Expression toExpression(int attributeTypeIndex, SimpleFeatureType type) { FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null); AttributeDescriptor attribute = type.getDescriptor(attributeTypeIndex); if (attribute == null) { throw new IllegalArgumentException( "Attribute index '" + attributeTypeIndex + "' is not valid."); } return filterFactory.property(attribute.getLocalName()); }
/** * Maps schema attributes to shapefile-compatible attributes. * * @param schema * @return */ private static Map<String, String> createAttributeMappings(SimpleFeatureType schema) { Map<String, String> result = new HashMap<String, String>(); // track the field names used and reserve "the_geom" for the geometry Set<String> usedFieldNames = new HashSet<String>(); usedFieldNames.add("the_geom"); // scan and remap for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) { if (attDesc instanceof GeometryDescriptor) { result.put(attDesc.getLocalName(), "the_geom"); } else { String name = attDesc.getLocalName(); result.put(attDesc.getLocalName(), getShapeCompatibleName(usedFieldNames, name)); } } return result; }
private Expression toExpression(String attributeName, SimpleFeatureType type) { FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null); AttributeDescriptor attribute = type.getDescriptor(attributeName); if (attribute == null) { throw new IllegalArgumentException("Attribute '" + attributeName + "' is not valid."); } return filterFactory.property(attribute.getLocalName()); }
private void addAttributeValues( SimpleFeature feature, List<String> retained, SimpleFeatureBuilder fb) { Iterator<AttributeDescriptor> firstIterator = feature.getType().getAttributeDescriptors().iterator(); while (firstIterator.hasNext()) { AttributeDescriptor ad = firstIterator.next(); Object firstAttribute = feature.getAttribute(ad.getLocalName()); if ((retained == null || retained.contains(ad.getLocalName())) && !(firstAttribute instanceof Geometry)) { fb.add(feature.getAttribute(ad.getLocalName())); } } }
public MedianVisitor(int attributeTypeIndex, SimpleFeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); expr = factory.property(type.getDescriptor(attributeTypeIndex).getLocalName()); }
private InsertionClassifier(SimpleFeatureType featureType, SimpleFeature feature) { useExisting = useExisting(feature); geometryTypes = new TreeMap<>(); for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { if (att instanceof GeometryDescriptor) { Geometry geometry = (Geometry) feature.getAttribute(att.getName()); if (geometry == null) { geometryTypes.put(att.getLocalName(), null); } else { geometryTypes.put(att.getLocalName(), geometry.getClass()); } } } }
public MaxVisitor(int attributeTypeIndex, SimpleFeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); expr = factory.property(type.getDescriptor(attributeTypeIndex).getLocalName()); }
/** * Builds a list of the aggregate function calls necesary to compute each geometry column bounds * * @param featureType * @param sql */ void buildEnvelopeAggregates(SimpleFeatureType featureType, StringBuffer sql) { // walk through all geometry attributes and build the query for (Iterator a = featureType.getAttributeDescriptors().iterator(); a.hasNext(); ) { AttributeDescriptor attribute = (AttributeDescriptor) a.next(); if (attribute instanceof GeometryDescriptor) { String geometryColumn = attribute.getLocalName(); dialect.encodeGeometryEnvelope(featureType.getTypeName(), geometryColumn, sql); sql.append(","); } } sql.setLength(sql.length() - 1); }