use of eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser in project hale by halestudio.
the class SpatialIndexInstanceProcessor method process.
/**
* @see eu.esdihumboldt.hale.common.instance.processing.InstanceProcessor#process(eu.esdihumboldt.hale.common.instance.model.Instance,
* eu.esdihumboldt.hale.common.instance.model.InstanceReference)
*/
@Override
public void process(Instance instance, InstanceReference reference) {
SpatialIndexService<Localizable, Localizable> index = getSpatialIndexService();
final GeometryFinder finder = new GeometryFinder(null);
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
traverser.traverse(instance, finder);
final List<Geometry> geometries = new ArrayList<>();
for (GeometryProperty<?> property : finder.getGeometries()) {
Geometry g = property.getGeometry();
for (int i = 0; i < g.getNumGeometries(); i++) {
geometries.add(g.getGeometryN(i));
}
}
final BoundingBox boundingBox = new BoundingBox();
for (Geometry geometry : geometries) {
boundingBox.add(BoundingBox.compute(geometry));
}
if (boundingBox.checkIntegrity()) {
TypedInstanceReference typedRef = new TypedInstanceReference(reference, instance.getDefinition());
index.insert(new LocalizableInstanceReference(typedRef, boundingBox));
}
}
Aggregations