use of org.opengis.feature.type.PropertyDescriptor 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);
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class ImportOp method alter.
/**
* Translates a feature pointed by a node from its original feature type to a given one, using
* values from those attributes that exist in both original and destination feature type. New
* attributes are populated with null values
*
* @param node The node that points to the feature. No checking is performed to ensure the node
* points to a feature instead of other type
* @param featureType the destination feature type
* @return a feature with the passed feature type and data taken from the input feature
*/
private Feature alter(NodeRef node, RevFeatureType featureType) {
RevFeature oldFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class).get();
RevFeatureType oldFeatureType;
oldFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class).get();
ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors();
ImmutableList<PropertyDescriptor> newAttributes = featureType.sortedDescriptors();
ImmutableList<Optional<Object>> oldValues = oldFeature.getValues();
List<Optional<Object>> newValues = Lists.newArrayList();
for (int i = 0; i < newAttributes.size(); i++) {
int idx = oldAttributes.indexOf(newAttributes.get(i));
if (idx != -1) {
Optional<Object> oldValue = oldValues.get(idx);
newValues.add(oldValue);
} else {
newValues.add(Optional.absent());
}
}
RevFeature newFeature = RevFeatureImpl.build(ImmutableList.copyOf(newValues));
FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
Feature feature = featureBuilder.build(node.name(), newFeature);
return feature;
}
Aggregations