SimpleFeatureType renamed = tb.buildFeatureType();
c = new RetypingFeatureCollection(c, renamed);
}
SimpleFeatureStore 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
SimpleFeatureCollection remapped = new RemappingFeatureCollection(c,attributeMappings);
SimpleFeatureType remappedSchema=(SimpleFeatureType)remapped.getSchema();
dstore = buildStore(tempDir, charset, remappedSchema);
fstore = (SimpleFeatureStore) dstore.getFeatureSource();
// we need retyping too, because the shapefile datastore
// could have sorted fields in a different order
SimpleFeatureCollection retyped = new RetypingFeatureCollection(remapped, fstore.getSchema());
fstore.addFeatures(retyped);
changeWKTFormatIfFileFormatIsESRI(tempDir, request, fileName,
remappedSchema);
} catch (FactoryException fe) {
LOGGER.log(Level.WARNING,
"Error while getting EPSG code from FeatureType", fe);
throw new ServiceException(fe);
} catch (IOException ioe) {
LOGGER.log(Level.WARNING,
"Error while writing featuretype '" + schema.getTypeName() + "' to shapefile.", ioe);
throw new ServiceException(ioe);
} finally {
if(dstore != null) {
dstore.dispose();
}
}
}