Search in sources :

Example 16 with AttributeDescriptor

use of org.opengis.feature.type.AttributeDescriptor in project coastal-hazards by USGS-CIDA.

the class FeatureCollectionExport method getDescriptorFromPrototype.

private AttributeDescriptor getDescriptorFromPrototype(String name) {
    SimpleFeatureType schema = simpleFeatureCollection.getSchema();
    AttributeDescriptor descriptor = schema.getDescriptor(name);
    return descriptor;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 17 with AttributeDescriptor

use of org.opengis.feature.type.AttributeDescriptor in project coastal-hazards by USGS-CIDA.

the class RibboningProcess method sortFeatures.

// if there's an attribute to sort by, sort by it
public SimpleFeatureCollection sortFeatures(String sortAttribute, SimpleFeatureCollection features) {
    SimpleFeatureCollection result = features;
    AttributeDescriptor sortAttr = features.getSchema().getDescriptor(sortAttribute);
    if (null != sortAttr) {
        SortBy sort = new SortByImpl(new AttributeExpressionImpl(sortAttr.getName()), SortOrder.ASCENDING);
        result = new SortedSimpleFeatureCollection(features, new SortBy[] { sort });
    } else {
        LOGGER.log(Level.WARNING, "Could not find sort attribute {0}", sortAttribute);
    }
    return result;
}
Also used : SortedSimpleFeatureCollection(org.geotools.feature.collection.SortedSimpleFeatureCollection) SortByImpl(org.geotools.filter.SortByImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) SortBy(org.opengis.filter.sort.SortBy) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) SortedSimpleFeatureCollection(org.geotools.feature.collection.SortedSimpleFeatureCollection) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection)

Example 18 with AttributeDescriptor

use of org.opengis.feature.type.AttributeDescriptor in project eol-globi-data by jhpoelen.

the class EcoregionFinderImpl method getFeatureProperties.

public static Map<String, Object> getFeatureProperties(Point point, SimpleFeatureCollection featureCollection) {
    Map<String, Object> map = null;
    SimpleFeatureIterator features = featureCollection.features();
    try {
        while (features.hasNext()) {
            SimpleFeature feature = features.next();
            Object defaultGeometry = feature.getDefaultGeometry();
            if (defaultGeometry instanceof MultiPolygon) {
                MultiPolygon polygon = (MultiPolygon) defaultGeometry;
                if (polygon.contains(point)) {
                    map = new TreeMap<String, Object>();
                    SimpleFeatureType featureType = feature.getFeatureType();
                    List<AttributeDescriptor> attributeDescriptors = featureType.getAttributeDescriptors();
                    for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
                        String localName = attributeDescriptor.getLocalName();
                        Object value = feature.getAttribute(localName);
                        if (value != null) {
                            map.put(attributeDescriptor.getLocalName(), value);
                        }
                    }
                    break;
                }
            }
        }
    } finally {
        features.close();
    }
    return map;
}
Also used : SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 19 with AttributeDescriptor

use of org.opengis.feature.type.AttributeDescriptor in project hale by halestudio.

the class ShapeSchemaReader method loadFromSource.

@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    // $NON-NLS-1$
    progress.begin(Messages.getString("ShapeSchemaProvider.1"), ProgressIndicator.UNKNOWN);
    // DataStore store = new ShapefileDataStoreFactory().createDataStore(location.toURL());
    // DataStore store = FileDataStoreFinder.getDataStore(getSource().getLocation().toURL());
    ShapefileDataStore store = new ShapefileDataStore(getSource().getLocation().toURL());
    store.setCharset(getCharset());
    // TODO namespace from configuration parameter?!
    String namespace = ShapefileConstants.SHAPEFILE_NS;
    DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
    // $NON-NLS-1$
    progress.setCurrentTask(Messages.getString("ShapeSchemaProvider.2"));
    // create type for augmented filename property
    TypeDefinition filenameType = null;
    if (isAddFilenameAttribute()) {
        QName filenameTypeName = new QName(SHAPEFILE_AUGMENT_NS, "filenameType");
        if (getSharedTypes() != null) {
            filenameType = getSharedTypes().getType(filenameTypeName);
        }
        if (filenameType == null) {
            DefaultTypeDefinition fnt = new DefaultTypeDefinition(filenameTypeName);
            fnt.setConstraint(MappableFlag.DISABLED);
            fnt.setConstraint(MappingRelevantFlag.DISABLED);
            fnt.setConstraint(Binding.get(String.class));
            fnt.setConstraint(HasValueFlag.ENABLED);
            filenameType = fnt;
        }
    }
    // build type definitions based on Schema extracted by geotools
    for (Name name : store.getNames()) {
        SimpleFeatureType sft = store.getSchema(name);
        try {
            // create type definition
            DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(namespace, sft.getName().getLocalPart()));
            // constraints on main type
            type.setConstraint(MappingRelevantFlag.ENABLED);
            type.setConstraint(MappableFlag.ENABLED);
            type.setConstraint(HasValueFlag.DISABLED);
            type.setConstraint(AbstractFlag.DISABLED);
            type.setConstraint(Binding.get(Instance.class));
            for (AttributeDescriptor ad : sft.getAttributeDescriptors()) {
                DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(ad.getLocalName()), type, getTypeFromAttributeType(ad.getType(), schema, namespace));
                // set constraints on property
                // nillable
                property.setConstraint(NillableFlag.get(ad.isNillable()));
                // cardinality
                property.setConstraint(Cardinality.get(ad.getMinOccurs(), ad.getMaxOccurs()));
                // set metadata
                property.setLocation(getSource().getLocation());
            }
            // add additional filename property
            if (filenameType != null) {
                // String filename = sft.getName().getLocalPart();
                DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(SHAPEFILE_AUGMENT_NS, AUGMENTED_PROPERTY_FILENAME), type, filenameType);
                property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
                property.setConstraint(NillableFlag.ENABLED);
            }
            schema.addType(type);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        progress.setCurrentTask(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        Messages.getString("ShapeSchemaProvider.7"), sft.getTypeName()));
    }
    reporter.setSuccess(true);
    return schema;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Name(org.opengis.feature.type.Name) QName(javax.xml.namespace.QName) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)

Example 20 with AttributeDescriptor

use of org.opengis.feature.type.AttributeDescriptor in project GeoGig by boundlessgeo.

the class ExportDiffOp method addFidAttribute.

private static SimpleFeatureType addFidAttribute(RevFeatureType revFType) {
    SimpleFeatureType featureType = (SimpleFeatureType) revFType.type();
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.add("geogig_fid", String.class);
    for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
        builder.add(descriptor);
    }
    builder.setName(featureType.getName());
    builder.setCRS(featureType.getCoordinateReferenceSystem());
    featureType = builder.buildFeatureType();
    return featureType;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Aggregations

AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)40 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)22 SimpleFeature (org.opengis.feature.simple.SimpleFeature)10 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)9 ArrayList (java.util.ArrayList)8 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)8 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)7 HashMap (java.util.HashMap)6 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)6 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)6 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)6 IOException (java.io.IOException)5 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5 Test (org.junit.Test)5 File (java.io.File)4 Map (java.util.Map)4 DefaultTransaction (org.geotools.data.DefaultTransaction)4 FileDataStoreFactorySpi (org.geotools.data.FileDataStoreFactorySpi)4 Transaction (org.geotools.data.Transaction)4 GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)4