ImportTask task(ImportData data, Catalog catalog) throws IOException {
File file = maybeFile(data).get();
// get the composite feature type
SimpleFeatureType featureType = new FeatureJSON().readFeatureCollectionSchema(file, false);
System.out.println(featureType);
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.init(featureType);
tb.setName(FilenameUtils.getBaseName(file.getName()));
featureType = tb.buildFeatureType();
// create the feature type
FeatureTypeInfo ft = catalog.getFactory().createFeatureType();
ft.setName(FilenameUtils.getBaseName(file.getName()));
ft.setNativeName(ft.getName());
// crs
CoordinateReferenceSystem crs = null;
if (featureType != null && featureType.getCoordinateReferenceSystem() != null) {
crs = featureType.getCoordinateReferenceSystem();
}
try {
crs = crs != null ? crs : CRS.decode("EPSG:4326");
}
catch (Exception e) {
throw new IOException(e);
}
ft.setNativeCRS(crs);
String srs = srs(crs);
if (srs != null) {
ft.setSRS(srs);
}
// bounds
ReferencedEnvelope bounds = new ReferencedEnvelope(crs);
FeatureJSON reader = new FeatureJSON();
reader.setFeatureType(featureType);
FeatureIterator<SimpleFeature> it = reader.streamFeatureCollection(file);
while(it.hasNext()) {
SimpleFeature f = it.next();
bounds.include(f.getBounds());
}
ft.setNativeBoundingBox(bounds);