use of org.geotools.feature.type.AttributeDescriptorImpl in project GeoGig by boundlessgeo.
the class ImportOp method overrideGeometryName.
private SimpleFeatureType overrideGeometryName(SimpleFeatureType featureType) {
if (geomName == null) {
return featureType;
}
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
List<AttributeDescriptor> newAttributes = Lists.newArrayList();
String oldGeomName = featureType.getGeometryDescriptor().getName().getLocalPart();
Collection<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
for (AttributeDescriptor descriptor : descriptors) {
String name = descriptor.getName().getLocalPart();
Preconditions.checkArgument(!name.equals(geomName), "The provided geom name is already in use by another attribute");
if (name.equals(oldGeomName)) {
AttributeDescriptorImpl newDescriptor = new AttributeDescriptorImpl(descriptor.getType(), new NameImpl(geomName), descriptor.getMinOccurs(), descriptor.getMaxOccurs(), descriptor.isNillable(), descriptor.getDefaultValue());
newAttributes.add(newDescriptor);
} else {
newAttributes.add(descriptor);
}
}
builder.setAttributes(newAttributes);
builder.setName(featureType.getName());
builder.setCRS(featureType.getCoordinateReferenceSystem());
featureType = builder.buildFeatureType();
return featureType;
}
Aggregations