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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations