Search in sources :

Example 91 with AttributeType

use of org.opengis.feature.AttributeType in project geotoolkit by Geomatys.

the class SpatialJoinProcess method copyAttributes.

/**
 * This function copy attributes from source to target Feature except geometry descriptor.
 * The copied attributes name will be "attributeName_sourceFeatureTypeName".
 * @param target targetFeature
 * @param source source Feature
 * @param concatType concatenated FeatureType
 * @return the resulting Feature
 */
static Feature copyAttributes(final Feature target, final Feature source, final FeatureType concatType) {
    final Feature resultFeature = concatType.newInstance();
    resultFeature.setPropertyValue(AttributeConvention.IDENTIFIER, FeatureExt.getId(target).getIdentifier() + "_" + FeatureExt.getId(source).getIdentifier());
    // copy target Feature
    for (final PropertyType targetProperty : target.getType().getProperties(true)) {
        if (targetProperty instanceof AttributeType && !AttributeConvention.contains(targetProperty.getName())) {
            final String name = targetProperty.getName().toString();
            resultFeature.setPropertyValue(name, target.getPropertyValue(name));
        }
    }
    // copy source Feature except geometry descriptor
    for (final PropertyType sourceProperty : source.getType().getProperties(true)) {
        if (sourceProperty instanceof AttributeType && !AttributeConvention.contains(sourceProperty.getName())) {
            if (!AttributeConvention.isGeometryAttribute(sourceProperty)) {
                final String name = sourceProperty.getName().tip().toString();
                final String rename = name + "_" + source.getType().getName().tip().toString();
                try {
                    resultFeature.setPropertyValue(rename, source.getPropertyValue(name));
                } catch (IllegalArgumentException ex) {
                    resultFeature.setPropertyValue(name, source.getPropertyValue(name));
                }
            }
        }
    }
    return resultFeature;
}
Also used : AttributeType(org.opengis.feature.AttributeType) PropertyType(org.opengis.feature.PropertyType) Feature(org.opengis.feature.Feature)

Aggregations

AttributeType (org.opengis.feature.AttributeType)91 PropertyType (org.opengis.feature.PropertyType)55 FeatureType (org.opengis.feature.FeatureType)33 Feature (org.opengis.feature.Feature)29 Geometry (org.locationtech.jts.geom.Geometry)28 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)23 ArrayList (java.util.ArrayList)22 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)22 PropertyNotFoundException (org.opengis.feature.PropertyNotFoundException)19 GenericName (org.opengis.util.GenericName)19 Operation (org.opengis.feature.Operation)16 DataStoreException (org.apache.sis.storage.DataStoreException)14 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)9 Attribute (org.opengis.feature.Attribute)9 Map (java.util.Map)8 DefaultAttributeType (org.apache.sis.feature.DefaultAttributeType)8 FeatureSet (org.apache.sis.storage.FeatureSet)8 Collection (java.util.Collection)7