Search in sources :

Example 61 with AttributeType

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

the class JAXBFeatureTypeReader method addProperty.

/**
 * Add property to feature type builder.
 * This methods skips standard object properties, reset identifier parameters
 * and unroll propertytypes.
 *
 * @param ftb
 * @param property
 */
private void addProperty(FeatureTypeBuilder ftb, PropertyType property) {
    if (skipStandardObjectProperties && (Utils.GML_ABSTRACT_FEATURE_PROPERTIES.contains(property.getName()) || Utils.GML_STANDARD_OBJECT_PROPERTIES.contains(property.getName()))) {
        return;
    }
    if (property instanceof AttributeType) {
        final AttributeType att = (AttributeType) property;
        // //            final boolean decorated = GMLConvention.isDecoratedProperty(att.getName().tip().toString());
        final AttributeTypeBuilder atb = ftb.addAttribute(att);
        if (FeatureExt.getCharacteristicValue(property, FLAG_ID, false)) {
            // special case, consider it as a property
            atb.addRole(AttributeRole.IDENTIFIER_COMPONENT);
            atb.characteristics().clear();
        }
    // //            if (decorated) {
    // //                atb.setDescription(GMLConvention.DECORATED_DESCRIPTION);
    // //            }
    } else if (property instanceof FeatureAssociationRole) {
        final FeatureAssociationRole far = (FeatureAssociationRole) property;
        // PropertyType field are only decorations used to rename elements
        // this would cause a double association hard to manipulate
        // so we unroll them
        final GenericName valueTypeName = Features.getValueTypeName(far);
        final String tip = valueTypeName.tip().toString();
        // //            final boolean isEncapsulated = GMLConvention.isDecoratedProperty(tip);
        // //            if (isEncapsulated) {
        // //                //this is an encapsulated property, we unroll it
        // //                final FeatureType valueType = far.getValueType();
        // //                final Collection<? extends PropertyType> subProps = valueType.getProperties(true);
        // //                boolean found = false;
        // //                //we peek the first association, there should be only one
        // //                //but attributes are possible
        // //                for (PropertyType pt : subProps) {
        // //                    if (pt instanceof FeatureAssociationRole) {
        // //                        /* HACK : GML 3.1.1 : Only way I've found to manage
        // //                         * geometries as attributes. If we've found an association,
        // //                         * and if it's feature type is a geometric property
        // //                         * (derived from abstract geometric type), well, we
        // //                         * return a geometric property.
        // //                         */
        // //                        final FeatureAssociationRole subFar = (FeatureAssociationRole) pt;
        // //                        final PropertyTypeBuilder propBuilder;
        // ////                        if (isGeometric(subFar)) {
        // ////                            propBuilder = ftb.addAttribute(Geometry.class);
        // ////                        } else {
        // //                            propBuilder = ftb.addAssociation(subFar);
        // ////                        }
        // //
        // //                        propBuilder
        // //                                .setDescription(GMLConvention.DECORATED_DESCRIPTION)
        // //                                .setMinimumOccurs(far.getMinimumOccurs())
        // //                                .setMaximumOccurs(far.getMaximumOccurs())
        // //                                .setName(far.getName());
        // //                        found = true;
        // //                        break;
        // //                    }
        // //                }
        // //
        // //                if (!found) {
        // //                    //add property normally
        // //                    ftb.addProperty(property);
        // //                }
        // //
        // //            } else {
        ftb.addProperty(property);
    // //            }
    } else {
        ftb.addProperty(property);
    }
}
Also used : SingleAttributeTypeBuilder(org.geotoolkit.feature.SingleAttributeTypeBuilder) AttributeTypeBuilder(org.apache.sis.feature.builder.AttributeTypeBuilder) GenericName(org.opengis.util.GenericName) AttributeType(org.opengis.feature.AttributeType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 62 with AttributeType

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

the class JAXBFeatureTypeWriter method writeProperty.

private void writeProperty(final PropertyType pType, final ExplicitGroup sequence, final Schema schema, final List<Attribute> attributes, final Set<String> alreadyWritten) {
    if (pType instanceof Operation) {
        // operation types are not written in the xsd.
        return;
    }
    final boolean decorated = GMLConvention.isDecoratedProperty(pType);
    if (pType instanceof AttributeType) {
        final AttributeType attType = (AttributeType) pType;
        final String name = attType.getName().tip().toString();
        final QName type = Utils.getQNameFromType(attType, gmlVersion);
        final int minOccurs = attType.getMinimumOccurs();
        final int maxOccurs = attType.getMaximumOccurs();
        final boolean nillable = FeatureExt.getCharacteristicValue(attType, GMLConvention.NILLABLE_PROPERTY.toString(), minOccurs == 0);
        final String maxOcc;
        if (maxOccurs == Integer.MAX_VALUE) {
            maxOcc = "unbounded";
        } else {
            maxOcc = Integer.toString(maxOccurs);
        }
        if (AttributeConvention.contains(attType.getName())) {
            Attribute att = new Attribute();
            att.setName(name);
            att.setType(type);
            if (minOccurs == 0) {
                att.setUse("optional");
            } else {
                att.setUse("required");
            }
            attributes.add(att);
        } else {
            if (decorated) {
                final QName decorationTypeName = GMLConvention.getDecorationTypeName(gmlVersion, pType);
                final String namespace = decorationTypeName.getNamespaceURI();
                if (!GMLConvention.isGmlNamespace(namespace)) {
                    // create a new separate type, how ?
                    throw new UnsupportedOperationException("Not supported yet.");
                }
                sequence.addElement(new LocalElement(name, decorationTypeName, minOccurs, maxOcc, nillable));
            } else {
                sequence.addElement(new LocalElement(name, type, minOccurs, maxOcc, nillable));
            }
        }
    } else if (pType instanceof FeatureAssociationRole) {
        final FeatureAssociationRole role = (FeatureAssociationRole) pType;
        final FeatureType valueType = role.getValueType();
        final String name = role.getName().tip().toString();
        final int minOccurs = role.getMinimumOccurs();
        final int maxOccurs = role.getMaximumOccurs();
        final String maxOcc;
        if (maxOccurs == Integer.MAX_VALUE) {
            maxOcc = "unbounded";
        } else {
            maxOcc = Integer.toString(maxOccurs);
        }
        if (decorated) {
            // for a complexType we have to add 2 complexType (PropertyType and type)
            final String typeName = Utils.getNameWithoutTypeSuffix(valueType.getName().tip().toString());
            final String propertyName = Utils.getNameWithPropertyTypeSuffix(typeName);
            final QName proptype = new QName(schema.getTargetNamespace(), propertyName);
            final String nameWithSuffix = propertyName;
            // search if this type has already been written
            if (!alreadyWritten.contains(nameWithSuffix)) {
                alreadyWritten.add(nameWithSuffix);
                final QName type = Utils.getQNameFromType(role, gmlVersion);
                // property type
                // <xsd:element name="Address" type="gml:AddressType" xmlns:gml="http://www.opengis.net/gml" nillable="false" minOccurs="1" maxOccurs="1" />
                final ExplicitGroup exp = new ExplicitGroup();
                final TopLevelComplexType tlcType = new TopLevelComplexType(propertyName, exp);
                final LocalElement le = new LocalElement(typeName, type, 1, "1", Boolean.FALSE);
                le.setType(Utils.getQNameFromType(valueType, gmlVersion));
                exp.addElement(le);
                schema.addComplexType(tlcType);
            }
            // attribute type
            final boolean nillable = FeatureExt.getCharacteristicValue(role, GMLConvention.NILLABLE_PROPERTY.toString(), minOccurs == 0);
            sequence.addElement(new LocalElement(name, proptype, minOccurs, maxOcc, nillable));
        } else {
            final QName type = Utils.getQNameFromType(valueType, gmlVersion);
            final boolean nillable = FeatureExt.getCharacteristicValue(role, GMLConvention.NILLABLE_PROPERTY.toString(), false);
            sequence.addElement(new LocalElement(name, type, minOccurs, maxOcc, nillable));
        }
        // real type
        writeComplexType(role.getValueType(), schema, alreadyWritten);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) Attribute(org.geotoolkit.xsd.xml.v2001.Attribute) QName(javax.xml.namespace.QName) LocalElement(org.geotoolkit.xsd.xml.v2001.LocalElement) Operation(org.opengis.feature.Operation) ExplicitGroup(org.geotoolkit.xsd.xml.v2001.ExplicitGroup) TopLevelComplexType(org.geotoolkit.xsd.xml.v2001.TopLevelComplexType) AttributeType(org.opengis.feature.AttributeType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 63 with AttributeType

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

the class XSDFeatureType method isSimple.

@Override
public boolean isSimple() {
    boolean isSimple = true;
    for (final PropertyTypeBuilder property : builder.properties()) {
        final int minimumOccurs, maximumOccurs;
        if (property instanceof AttributeType<?>) {
            minimumOccurs = ((AttributeType<?>) property).getMinimumOccurs();
            maximumOccurs = ((AttributeType<?>) property).getMaximumOccurs();
            isSimple &= (minimumOccurs == maximumOccurs);
        } else if (property instanceof FeatureAssociationRole) {
            minimumOccurs = ((FeatureAssociationRole) property).getMinimumOccurs();
            maximumOccurs = ((FeatureAssociationRole) property).getMaximumOccurs();
            isSimple = false;
        } else {
            // For feature operations, maximumOccurs is implicitly 0.
            continue;
        }
        if (maximumOccurs != 0) {
            isSimple &= (maximumOccurs == 1);
        }
        if (!isSimple)
            break;
    }
    return isSimple;
}
Also used : PropertyTypeBuilder(org.apache.sis.feature.builder.PropertyTypeBuilder) AttributeType(org.opengis.feature.AttributeType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 64 with AttributeType

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

the class Utils method getQNameFromType.

/**
 * Return a QName intended to be used in a xsd XML file from the specified class.
 *
 * @param type a primitive type Class.
 * @param gmlVersion GML version (default to 3.1.1) if not specified.
 * @return A QName describing the class.
 */
public static QName getQNameFromType(final PropertyType type, final String gmlVersion) {
    if (type instanceof AttributeType) {
        final Class binding = ((AttributeType) type).getValueClass();
        final QName result;
        if (Geometry.class.isAssignableFrom(binding)) {
            if ("3.2.1".equals(gmlVersion)) {
                result = GEOMETRY_NAME_BINDING_321.get(binding);
            } else {
                result = GEOMETRY_NAME_BINDING_311.get(binding);
            }
            if (result == null) {
                if ("3.2.1".equals(gmlVersion)) {
                    return new QName(GML_321_NAMESPACE, "GeometryPropertyType", "gml");
                } else {
                    return new QName(GML_311_NAMESPACE, "GeometryPropertyType", "gml");
                }
            }
        // maybe we can find a better way to handle Enum. for now we set a String value
        } else if (binding.isEnum()) {
            result = new QName("http://www.w3.org/2001/XMLSchema", "string");
        } else if (binding.equals(Object.class)) {
            if ("3.2.1".equals(gmlVersion)) {
                result = new QName(GML_321_NAMESPACE, "AbstractObject", "gml");
            } else {
                result = new QName(GML_311_NAMESPACE, "_Object", "gml");
            }
        } else {
            result = NAME_BINDING.get(binding);
        }
        if (result == null) {
            throw new IllegalArgumentException("unexpected type:" + binding);
        }
        return result;
    }
    return null;
}
Also used : AttributeType(org.opengis.feature.AttributeType) QName(javax.xml.namespace.QName)

Example 65 with AttributeType

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

the class ClipGeometryProcess method clipFeature.

/**
 * Clip the feature with the Geometry Clipping
 *
 * @param newType the new FeatureType for the Feature
 */
public static Feature clipFeature(final Feature oldFeature, final FeatureType newType, final Geometry clipGeometry) {
    final Feature resultFeature = newType.newInstance();
    FeatureExt.setId(resultFeature, FeatureExt.getId(oldFeature));
    for (PropertyType property : oldFeature.getType().getProperties(true)) {
        final String name = property.getName().toString();
        final Object value = oldFeature.getPropertyValue(name);
        if (AttributeConvention.isGeometryAttribute(property)) {
            final Geometry interGeometry = VectorProcessUtils.geometryIntersection((Geometry) value, clipGeometry);
            // test clipping
            if (interGeometry != null) {
                resultFeature.setPropertyValue(name, interGeometry);
            } else {
                return null;
            }
        } else if (property instanceof AttributeType && !(AttributeConvention.contains(property.getName()))) {
            resultFeature.setPropertyValue(name, value);
        }
    }
    return resultFeature;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) 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