// having dots in the name prevents various programs to recognize the file as a shapefile
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.init(c.getSchema());
tb.setName(c.getSchema().getTypeName().replace('.', '_'));
SimpleFeatureType renamed = tb.buildFeatureType();
c = new RetypingFeatureCollection(c, renamed);
}
FeatureStore<SimpleFeatureType, SimpleFeature> fstore = null;
ShapefileDataStore dstore = null;
try {
// create attribute name mappings, to be compatible
// with shapefile constraints:
// - geometry field is always named the_geom
// - field names have a max length of 10
Map<String,String> attributeMappings=createAttributeMappings(c.getSchema());
// wraps the original collection in a remapping wrapper
FeatureCollection remapped=new RemappingFeatureCollection(c,attributeMappings);
SimpleFeatureType remappedSchema=(SimpleFeatureType)remapped.getSchema();
dstore = buildStore(tempDir, charset, remappedSchema);
fstore = (FeatureStore<SimpleFeatureType, SimpleFeature>) dstore.getFeatureSource();
// we need retyping too, because the shapefile datastore
// could have sorted fields in a different order
FeatureCollection<SimpleFeatureType, SimpleFeature> retyped = new RetypingFeatureCollection(remapped, fstore.getSchema());
fstore.addFeatures(retyped);
} catch (IOException ioe) {
LOGGER.log(Level.WARNING,
"Error while writing featuretype '" + schema.getTypeName() + "' to shapefile.", ioe);