Search in sources :

Example 6 with Localizable

use of de.fhg.igd.geom.Localizable in project hale by halestudio.

the class SpatialIndexInstanceProcessor method getSpatialIndexService.

/**
 * @return the spatial index service
 * @throws IllegalStateException thrown if there is no
 *             {@link ServiceProvider} or no {@link SpatialIndexService}
 *             provided
 */
private SpatialIndexService<Localizable, Localizable> getSpatialIndexService() {
    final ServiceProvider serviceProvider = Optional.ofNullable(this.getServiceProvider()).orElseThrow(() -> new IllegalStateException("No service provider available"));
    @SuppressWarnings("unchecked") SpatialIndexService<Localizable, Localizable> index = Optional.ofNullable(serviceProvider.getService(SpatialIndexService.class)).orElseThrow(() -> new IllegalStateException("No SpatialIndexService was provided."));
    return index;
}
Also used : ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Localizable(de.fhg.igd.geom.Localizable)

Example 7 with Localizable

use of de.fhg.igd.geom.Localizable 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

Localizable (de.fhg.igd.geom.Localizable)7 BoundingBox (de.fhg.igd.geom.BoundingBox)6 ArrayList (java.util.ArrayList)3 Geometry (com.vividsolutions.jts.geom.Geometry)1 ServiceProvider (eu.esdihumboldt.hale.common.core.service.ServiceProvider)1 GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)1 DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)1 InstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser)1 LocalizableInstanceReference (eu.esdihumboldt.hale.common.instance.index.LocalizableInstanceReference)1 TypedInstanceReference (eu.esdihumboldt.hale.common.instance.index.TypedInstanceReference)1