List<AttributeDescriptor> attributes = prototype.getAttributeDescriptors();
GeometryDescriptor defaultGeometry = prototype.getGeometryDescriptor();
for (int i = 0; i < attributes.size(); i++) {
AttributeDescriptor att = attributes.get(i);
if (att == defaultGeometry) {
if (att.getType().getBinding() != MultiPolygon.class && att.getType().getBinding() != Polygon.class) {
Class<?> targetGeomType = Polygon.class;
final Class<?> sourceGeomClass = defaultGeometry.getType().getBinding();
if (GeometryCollection.class.isAssignableFrom(sourceGeomClass)) {
targetGeomType = MultiPolygon.class;
}
final String geomTypeName = att.getLocalName();
CoordinateReferenceSystem crs = defaultGeometry.getCoordinateReferenceSystem();
AttributeTypeBuilder build = new AttributeTypeBuilder();
build.setName(geomTypeName);
build.setBinding(targetGeomType);
build.setNillable(true);
build.setCRS(crs);
GeometryType type = build.buildGeometryType();
att = build.buildDescriptor(geomTypeName, type);
}
builder.add(att);
builder.setDefaultGeometry(att.getLocalName());
} else {
builder.add(att);
}
}
return builder;