Search in sources :

Example 26 with FeatureAssociationRole

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

the class DefaultJDBCFeatureStore method decompose.

/**
 * Decompose given type in flat types for table creation.
 */
private void decompose(FeatureType type, List<FeatureType> types, List<TypeRelation> relations) throws DataStoreException {
    final GenericName dbName = NamesExt.create(type.getName().tip().toString());
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName(dbName);
    for (PropertyType pt : type.getProperties(true)) {
        if (pt instanceof FeatureAssociationRole) {
            final FeatureAssociationRole asso = (FeatureAssociationRole) pt;
            final FeatureType attType = asso.getValueType();
            final TypeRelation relation = new TypeRelation();
            relation.property = asso;
            relation.parent = type;
            relation.child = attType;
            relations.add(relation);
            decompose(attType, types, relations);
        } else {
            ftb.addProperty(pt);
        }
    }
    final FeatureType flatType = ftb.build();
    if (!types.contains(flatType)) {
        types.add(flatType);
    }
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) GenericName(org.opengis.util.GenericName) PropertyType(org.opengis.feature.PropertyType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 27 with FeatureAssociationRole

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

the class SQLQueryBuilder method encodeSelectColumnNames.

protected void encodeSelectColumnNames(StringBuilder sql, FeatureType featureType, Hints hints) {
    for (PropertyType att : featureType.getProperties(true)) {
        if (att instanceof DBRelationOperation) {
            final RelationMetaModel relation = ((DBRelationOperation) att).getRelation();
            final String str = att.getName().tip().toString();
            if (relation.isImported()) {
                dialect.encodeColumnName(sql, str);
            } else {
                // key is exported, it means the database field is in the other table.
                continue;
            }
        } else if (att instanceof Operation || att instanceof FeatureAssociationRole || AttributeConvention.contains(att.getName())) {
            continue;
        } else if (AttributeConvention.isGeometryAttribute(att)) {
            // encode as geometry
            encodeGeometryColumn((AttributeType) att, sql, hints);
            // alias it to be the name of the original geometry
            dialect.encodeColumnAlias(sql, att.getName().tip().toString());
        } else {
            dialect.encodeColumnName(sql, att.getName().tip().toString());
        }
        sql.append(',');
    }
    sql.setLength(sql.length() - 1);
}
Also used : RelationMetaModel(org.geotoolkit.db.reverse.RelationMetaModel) DBRelationOperation(org.geotoolkit.db.DBRelationOperation) PropertyType(org.opengis.feature.PropertyType) Operation(org.opengis.feature.Operation) DBRelationOperation(org.geotoolkit.db.DBRelationOperation) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 28 with FeatureAssociationRole

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

the class FeatureExt method fill.

private static void fill(final ParameterValueGroup source, final Feature target) {
    final ParameterDescriptorGroup paramdesc = source.getDescriptor();
    for (final PropertyType desc : target.getType().getProperties(true)) {
        if (desc instanceof FeatureAssociationRole) {
            final FeatureAssociationRole assRole = (FeatureAssociationRole) desc;
            try {
                final List<ParameterValueGroup> groups = source.groups(desc.getName().tip().toString());
                if (groups != null) {
                    for (ParameterValueGroup gr : groups) {
                        final FeatureAssociation att = assRole.newInstance();
                        final Feature val = assRole.getValueType().newInstance();
                        att.setValue(val);
                        fill(gr, val);
                        target.setProperty(att);
                    }
                }
            } catch (Exception ex) {
            // parameter might not exist of might be a group
            }
        } else if (desc instanceof AttributeType) {
            final AttributeType at = (AttributeType) desc;
            final String code = desc.getName().tip().toString();
            final GeneralParameterValue gpv = searchParameter(source, code);
            if (gpv instanceof ParameterValue) {
                target.setPropertyValue(code, ((ParameterValue) gpv).getValue());
            }
        }
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) FeatureAssociation(org.opengis.feature.FeatureAssociation) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) AttributeType(org.opengis.feature.AttributeType) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) PropertyType(org.opengis.feature.PropertyType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole) Feature(org.opengis.feature.Feature) ArrayFeature(org.geotoolkit.internal.feature.ArrayFeature) FactoryException(org.opengis.util.FactoryException) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) PropertyNotFoundException(org.opengis.feature.PropertyNotFoundException)

Example 29 with FeatureAssociationRole

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

the class FeatureExt method copy.

/**
 * @param deep true for a deep copy
 */
private static Feature copy(Feature feature, boolean deep) {
    final FeatureType type = feature.getType();
    final Feature cp = type.newInstance();
    final Collection<? extends PropertyType> props = type.getProperties(true);
    for (PropertyType pt : props) {
        if (pt instanceof AttributeType) {
            final String name = pt.getName().toString();
            final Object val = feature.getPropertyValue(name);
            if (val != null) {
                cp.setPropertyValue(name, deep ? deepCopy(val) : val);
            }
        } else if (pt instanceof FeatureAssociationRole) {
            final String name = pt.getName().toString();
            final Object val = feature.getPropertyValue(name);
            if (deep) {
                if (val != null) {
                    cp.setPropertyValue(name, deepCopy(val));
                }
            } else {
                if (val instanceof Collection) {
                    final Collection col = (Collection) val;
                    final Collection cpCol = new ArrayList(col.size());
                    for (Iterator ite = col.iterator(); ite.hasNext(); ) {
                        cpCol.add(copy((Feature) ite.next()));
                    }
                    cp.setPropertyValue(name, cpCol);
                } else if (val != null) {
                    cp.setPropertyValue(name, copy((Feature) val));
                }
            }
        }
    }
    return cp;
}
Also used : FeatureType(org.opengis.feature.FeatureType) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) AttributeType(org.opengis.feature.AttributeType) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) PropertyType(org.opengis.feature.PropertyType) Feature(org.opengis.feature.Feature) ArrayFeature(org.geotoolkit.internal.feature.ArrayFeature) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 30 with FeatureAssociationRole

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

the class FeatureTypeExt method equalsIgnoreConvention.

private static boolean equalsIgnoreConvention(PropertyType pt1, PropertyType pt2) {
    if (pt1 instanceof FeatureAssociationRole) {
        if (pt2 instanceof FeatureAssociationRole) {
            final FeatureAssociationRole far1 = (FeatureAssociationRole) pt1;
            final FeatureAssociationRole far2 = (FeatureAssociationRole) pt2;
            // check base properties
            if (!Objects.equals(far1.getName(), far2.getName()) || !Objects.equals(far1.getDefinition(), far2.getDefinition()) || !Objects.equals(far1.getDesignation(), far2.getDesignation()) || !Objects.equals(far1.getDesignation(), far2.getDesignation())) {
                return false;
            }
            if (far1.getMinimumOccurs() != far2.getMinimumOccurs() || far1.getMaximumOccurs() != far2.getMaximumOccurs()) {
                return false;
            }
            if (!equalsIgnoreConvention(far1.getValueType(), far2.getValueType())) {
                return false;
            }
        } else {
            return false;
        }
    } else if (!pt1.equals(pt2)) {
        return false;
    }
    return true;
}
Also used : FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Aggregations

FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)48 FeatureType (org.opengis.feature.FeatureType)31 PropertyType (org.opengis.feature.PropertyType)25 AttributeType (org.opengis.feature.AttributeType)21 Feature (org.opengis.feature.Feature)18 GenericName (org.opengis.util.GenericName)12 Collection (java.util.Collection)9 Test (org.junit.Test)9 Operation (org.opengis.feature.Operation)9 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 Statement (java.sql.Statement)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)6 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)6 SimpleInternationalString (org.apache.sis.util.SimpleInternationalString)5 Attribute (org.opengis.feature.Attribute)5 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)4 AttributeTypeBuilder (org.apache.sis.feature.builder.AttributeTypeBuilder)4 Timestamp (java.sql.Timestamp)3