I am not so seasoned at GeoTools libs, I am trying to transform a large (near 60K features) GML file. I want to change its CRS and features coordinates accordingly. The code I have is basically this:
public void parse(String crs, InputStream collection) throws Exception {
Configuration config = new GMLConfiguration();
StreamingParser parser = new StreamingParser(config, collection, SimpleFeature.class);
SimpleFeature feature = (SimpleFeature) parser.parse();
SimpleFeatureType featureType = feature.getFeatureType();
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(featureType.getName());
builder.setNamespaceURI(featureType.getName().getNamespaceURI());
builder.setCRS(CRS.getAuthorityFactory(true).
createCoordinateReferenceSystem("EPSG:4326"));
builder.setDefaultGeometry(feature.getDefaultGeometryProperty().
getDescriptor().getName().getLocalPart());
Collection<Property> props = feature.getProperties();
for (Property prop : props) {
builder.add(prop.getName().getLocalPart(), prop.getType().getBinding());
}
SimpleFeatureType buildedFeatureType = builder.buildFeatureType();
FeatureCollection<SimpleFeatureType, SimpleFeature> outCollection = FeatureCollections.newCollection();
do {
SimpleFeatureBuilder build = new SimpleFeatureBuilder(buildedFeatureType);
for (AttributeType attributeType : buildedFeatureType.getTypes()) {
Name attrName = attributeType.getName();
Object value = feature.getProperty(attrName).getValue();
build.add(value);
}
String id = feature.getIdentifier().getID();
SimpleFeature sf = build.buildFeature(id);
outCollection.add(sf);
} while ((feature = (SimpleFeature) parser.parse()) != null);
}
it takes a lot of time to complete, about a minute. Is there a better solution to deal with these big feature collections? Oh, I am bound to Java 8 SE and GeoTools version 2.7.0, migrate to newer GeoTools is not an option.
UPDATE I am dealing with a GML not shapefile. Shapefile was transformed to GML in a previous step.