Refine search
/** * 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); } } }
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; } }
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(sft); for (AttributeDescriptor at : sft.getAttributeDescriptors()) { String attName = at.getLocalName(); if (!properties.contains(attName)) { tb.remove(attName);
/** * 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; }
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"; }
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 int[] calculateIndexMapping( SimpleFeatureType backendType, String geomProperyName, String backendGeomPropertyName) throws IOException { int[] mapping = new int[getSchema().getAttributeCount()]; outer: for (int i = 0; i < mapping.length; i++) { String attrName = getSchema().getAttributeDescriptors().get(i).getLocalName(); if (attrName.equals(geomProperyName)) attrName = backendGeomPropertyName; for (int j = 0; j < backendType.getAttributeDescriptors().size(); j++) { if (backendType.getAttributeDescriptors().get(j).getLocalName().equals(attrName)) { mapping[i] = j; continue outer; } } throw new IOException( "No attribute " + attrName + " found in " + backendType.getTypeName()); } return mapping; }
/** * 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 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()); } } } }
/** * 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); }
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())); } } }
/** * Builds the name -> descriptor index used by simple features for fast attribute lookup * * @param featureType * @return */ static Map<String, AttributeDescriptor> buildDescriptorIndex(SimpleFeatureType featureType) { // build an index of attribute name to index Map<String, AttributeDescriptor> index = new HashMap<>(); for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { index.put(ad.getLocalName(), ad); } if (featureType.getGeometryDescriptor() != null) { index.put(null, featureType.getGeometryDescriptor()); } return index; } }
/** * Builds the name -> position index used by simple features for fast attribute lookup * * @param featureType * @return */ static Map<String, Integer> buildIndex(SimpleFeatureType featureType) { // build an index of attribute name to index Map<String, Integer> index = new HashMap<String, Integer>(); int i = 0; for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { index.put(ad.getLocalName(), i++); } if (featureType.getGeometryDescriptor() != null) { index.put(null, index.get(featureType.getGeometryDescriptor().getLocalName())); } return index; }
public FeatureTypeAttributeIO(SimpleFeatureType featureType) { for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { AttributeIO io = null; if (Date.class.isAssignableFrom(ad.getType().getBinding())) { io = new DateAttributeIO(); } else { io = new DefaultAttributeIO(); } ios.put(ad.getLocalName(), io); } }
/** * Overrides to include the geometry column whether it is required by the {@code schema} or * not, since we need to get the fid from the geometry id. */ @Override public String[] getPropertiesToFetch(SimpleFeatureType schema) throws IOException { List<String> attNames = new ArrayList<String>(schema.getAttributeCount() + 1); // /List attDescriptors = Descriptors.nodes(schema.getDescriptor()); List<AttributeDescriptor> attDescriptors = schema.getAttributeDescriptors(); for (AttributeDescriptor property : attDescriptors) { attNames.add(property.getLocalName()); } shapeIndex = attNames.indexOf(shapeColName); if (shapeIndex == -1) { String fidColumn = getFidColumn(); int fidIndex = attNames.indexOf(shapeColName); if (fidIndex == -1) { attNames.add(fidColumn); fidIndex = attNames.size() - 1; } setColumnIndex(fidIndex); } return attNames.toArray(new String[attNames.size()]); } }
private List restriction(SimpleFeatureType featureType, String name, List filters) { List ancestors = FeatureTypes.getAncestors(featureType); if (ancestors != null && !ancestors.isEmpty()) { for (int i = 0, length = ancestors.size(); i < length; i++) { SimpleFeatureType superType = (SimpleFeatureType) ancestors.get(i); filters = restriction(superType, name, filters); } } List attributes = featureType.getAttributeDescriptors(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0, length = attributes.size(); i < length; i++) { AttributeDescriptor type = (AttributeDescriptor) attributes.get(i); if (name.equals(type.getLocalName())) { filters = override(filters, type.getType().getRestrictions()); } } } return filters; }
@Override public void encodePostSelect(SimpleFeatureType featureType, StringBuffer sql) { // Since geometries are stored as LOB's in teradata reading a geometry value in TD requires // as second trip to the database. Since this is expensive we attempt to cast the geometry // into a 64K byte string which is the limit of what TD will include inline. For large // geometries we will have to check and fall back onto readin the Blob, but for smaller // geometries this will save us the second trip // see decodeGeometryValue() // CASE WHEN CHARACTERS("the_geom") > 16000 THEN NULL ELSE CAST("the_geom" AS // VARCHAR(16000)) END as "the_geom_inline // Note: this only applies to TD 13 and up if (tdVersion > 12 && lobWorkaroundEnabled) { for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { if (att instanceof GeometryDescriptor) { sql.append(", CASE WHEN CHARACTERS(cast("); encodeColumnName(att.getLocalName(), sql); sql.append(" as clob)) > 30000 THEN NULL ELSE CAST ("); encodeColumnName(att.getLocalName(), sql); // works but not ideal, assumes rest of attributes consume < 2000 characters in // result set sql.append(" as VARCHAR(30000)) END"); encodeColumnAlias(att.getLocalName() + "_inline", sql); } } } }
/** * Writes the feature to the file * * @param sf * @throws IOException */ public void write(SimpleFeature sf) throws IOException { // write each attribute in the random access file List<AttributeDescriptor> attributes = schema.getAttributeDescriptors(); // write feature id raf.writeUTF(sf.getID()); // write the attributes for (AttributeDescriptor ad : attributes) { Object value = sf.getAttribute(ad.getLocalName()); writeAttribute(ad, value); } }
private void writeToShapefile( SimpleFeature f, FeatureWriter<SimpleFeatureType, SimpleFeature> writer) throws IOException { SimpleFeature fw = writer.next(); // we cannot trust attribute order, shapefile changes the location and name of the geometry for (AttributeDescriptor d : fw.getFeatureType().getAttributeDescriptors()) { fw.setAttribute(d.getLocalName(), f.getAttribute(d.getLocalName())); } fw.setDefaultGeometry(f.getDefaultGeometry()); writer.write(); }
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(); }