Search in sources :

Example 26 with Name

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

the class DescribeOp method _call.

/**
     * Describes a table from the data store that has been assigned.
     * 
     * @return a map that contains all properties and their types from the provided table
     */
@Override
protected Optional<Map<String, String>> _call() {
    if (dataStore == null) {
        throw new GeoToolsOpException(StatusCode.DATASTORE_NOT_DEFINED);
    }
    if (table == null || table.isEmpty()) {
        throw new GeoToolsOpException(StatusCode.TABLE_NOT_DEFINED);
    }
    Map<String, String> propertyMap = new HashMap<String, String>();
    boolean foundTable = false;
    List<Name> typeNames;
    try {
        typeNames = dataStore.getNames();
    } catch (Exception e) {
        throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_NAMES);
    }
    for (Name typeName : typeNames) {
        if (!table.equals(typeName.toString()))
            continue;
        foundTable = true;
        SimpleFeatureSource featureSource;
        try {
            featureSource = dataStore.getFeatureSource(typeName);
        } catch (Exception e) {
            throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_FEATURES);
        }
        SimpleFeatureType featureType = featureSource.getSchema();
        Collection<PropertyDescriptor> descriptors = featureType.getDescriptors();
        for (PropertyDescriptor descriptor : descriptors) {
            propertyMap.put(descriptor.getName().toString(), descriptor.getType().getBinding().getSimpleName());
        }
    }
    if (!foundTable) {
        return Optional.absent();
    }
    return Optional.of(propertyMap);
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) Name(org.opengis.feature.type.Name)

Aggregations

Name (org.opengis.feature.type.Name)26 WorkingTree (org.locationtech.geogig.repository.WorkingTree)9 Test (org.junit.Test)6 Node (org.locationtech.geogig.api.Node)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 ObjectId (org.locationtech.geogig.api.ObjectId)4 Feature (org.opengis.feature.Feature)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 ArrayList (java.util.ArrayList)3 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)3 Optional (com.google.common.base.Optional)2 LinkedList (java.util.LinkedList)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 RevFeatureTypeImpl (org.locationtech.geogig.api.RevFeatureTypeImpl)2 FieldType (org.locationtech.geogig.storage.FieldType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 AttributeType (org.opengis.feature.type.AttributeType)2 GeometryType (org.opengis.feature.type.GeometryType)2 FactoryException (org.opengis.referencing.FactoryException)2