use of net.geoprism.data.importer.SimpleFeatureRow in project geoprism-registry by terraframe.
the class ShapefileImporter method process.
/**
* Imports the entities from the shapefile
*
* @param writer
* Log file writer
* @throws InvocationTargetException
* @throws IOException
* @throws InterruptedException
*/
@Request
private void process(ImportStage stage, File shp) throws InvocationTargetException, IOException, InterruptedException {
/*
* Check permissions
*/
ImportConfiguration config = this.getObjectImporter().getConfiguration();
config.enforceCreatePermissions();
FileDataStore myData = FileDataStoreFinder.getDataStore(shp);
SimpleFeatureSource source = myData.getFeatureSource();
SimpleFeatureCollection featCol = source.getFeatures();
this.progressListener.setWorkTotal((long) featCol.size());
if (this.getStartIndex() > 0) {
Query query = new Query();
query.setStartIndex(Math.toIntExact(this.getStartIndex()));
featCol = source.getFeatures(query);
}
SimpleFeatureIterator featIt = featCol.features();
SimpleFeatureReader fr = new DelegateSimpleFeatureReader(source.getSchema(), featIt);
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
// We want to sort the features by the parentId column for better lookup
// performance (more cache hits) and
// also so that we have predictable ordering if we want to resume the import
// later.
List<SortBy> sortBy = new ArrayList<SortBy>();
// We also sort by featureId because it's
sortBy.add(SortBy.NATURAL_ORDER);
// guaranteed to be unique.
if (this.config.getLocations().size() > 0) {
ShapefileFunction loc = this.config.getLocations().get(0).getFunction();
if (loc instanceof BasicColumnFunction) {
// TODO
sortBy.add(ff.sort(loc.toJson().toString(), SortOrder.ASCENDING));
// :
// This
// assumes
// loc.tojson()
// returns
// only
// the
// attribute
// name.
}
}
try (SimpleFeatureReader sr = new SortedFeatureReader(fr, sortBy.toArray(new SortBy[sortBy.size()]), 5000)) {
while (sr.hasNext()) {
SimpleFeature feature = sr.next();
if (stage.equals(ImportStage.VALIDATE)) {
this.objectImporter.validateRow(new SimpleFeatureRow(feature));
} else {
this.objectImporter.importRow(new SimpleFeatureRow(feature));
}
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
myData.dispose();
}
}
Aggregations