Search in sources :

Example 11 with InstanceTraverser

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));
    }
}
Also used : LocalizableInstanceReference(eu.esdihumboldt.hale.common.instance.index.LocalizableInstanceReference) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) ArrayList(java.util.ArrayList) Localizable(de.fhg.igd.geom.Localizable) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Geometry(com.vividsolutions.jts.geom.Geometry) BoundingBox(de.fhg.igd.geom.BoundingBox) TypedInstanceReference(eu.esdihumboldt.hale.common.instance.index.TypedInstanceReference)

Aggregations

GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)11 DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)11 InstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)7 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)7 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)6 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)6 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)3 NoResultException (eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 Point (com.vividsolutions.jts.geom.Point)2 ArrayList (java.util.ArrayList)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)1 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 TopologyException (com.vividsolutions.jts.geom.TopologyException)1 BufferBuilder (com.vividsolutions.jts.operation.buffer.BufferBuilder)1 BufferParameters (com.vividsolutions.jts.operation.buffer.BufferParameters)1 BoundingBox (de.fhg.igd.geom.BoundingBox)1 Localizable (de.fhg.igd.geom.Localizable)1