Search in sources :

Example 1 with AttributeDescriptorImpl

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;
}
Also used : NameImpl(org.geotools.feature.NameImpl) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) AttributeDescriptorImpl(org.geotools.feature.type.AttributeDescriptorImpl)

Aggregations

NameImpl (org.geotools.feature.NameImpl)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 AttributeDescriptorImpl (org.geotools.feature.type.AttributeDescriptorImpl)1 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)1