Search in sources :

Example 1 with DepthFirstInstanceTraverser

use of eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser in project hale by halestudio.

the class GenericGeometryHandler method createGeometry.

/**
 * @see GeometryHandler#createGeometry(Instance, int, IOProvider)
 */
@Override
public Collection<GeometryProperty<?>> createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    CRSDefinition defaultCrsDef = GMLGeometryUtil.findCRS(instance);
    // depth first traverser that on cancel continues traversal but w/o the
    // children of the current object
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
    GeometryFinder geoFind = new GeometryFinder(defaultCrsDef);
    traverser.traverse(instance, geoFind);
    return createGeometry(instance, geoFind.getGeometries(), defaultCrsDef, reader);
}
Also used : InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)

Example 2 with DepthFirstInstanceTraverser

use of eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser in project hale by halestudio.

the class CalculateArea method evaluate.

/**
 * @see eu.esdihumboldt.hale.common.align.transformation.function.impl.AbstractSingleTargetPropertyTransformation#evaluate(java.lang.String,
 *      eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
 *      com.google.common.collect.ListMultimap, java.lang.String,
 *      eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition,
 *      java.util.Map,
 *      eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
 */
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();
    // depth first traverser that on cancel continues traversal but w/o the
    // children of the current object
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
    GeometryFinder geoFind = new GeometryFinder(null);
    traverser.traverse(inputValue, geoFind);
    List<GeometryProperty<?>> geoms = geoFind.getGeometries();
    Geometry geom = null;
    if (geoms.size() > 1) {
        int area = 0;
        for (GeometryProperty<?> geoProp : geoms) {
            area += geoProp.getGeometry().getArea();
        }
        return area;
    } else {
        geom = geoms.get(0).getGeometry();
    }
    if (geom != null) {
        return geom.getArea();
    } else {
        throw new TransformationException("Geometry for calculate area could not be retrieved.");
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)

Example 3 with DepthFirstInstanceTraverser

use of eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser in project hale by halestudio.

the class Centroid method calculateCentroid.

/**
 * Calculate the centroid for a given geometry or object holding a geometry.
 *
 * @param geometryHolder {@link Geometry}, {@link GeometryProperty} or
 *            {@link Instance} holding a geometry
 * @return the centroid of the geometry
 * @throws TransformationException if the no geometry could be extracted
 *             from the input
 */
public static GeometryProperty<?> calculateCentroid(Object geometryHolder) throws TransformationException {
    // depth first traverser that on cancel continues traversal but w/o the
    // children of the current object
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
    GeometryFinder geoFind = new GeometryFinder(null);
    traverser.traverse(geometryHolder, geoFind);
    List<GeometryProperty<?>> geoms = geoFind.getGeometries();
    Geometry result;
    CRSDefinition oldCRS = null;
    if (geoms.size() > 1) {
        // multiple geometries -> create a multi point
        // XXX is this the desired behavior?
        Point[] centroids = new Point[geoms.size()];
        GeometryFactory geomFactory = new GeometryFactory();
        for (int i = 0; i < geoms.size(); i++) {
            GeometryProperty<?> prop = geoms.get(i);
            centroids[i] = prop.getGeometry().getCentroid();
            if (oldCRS == null) {
                // assume the same CRS for all points
                oldCRS = prop.getCRSDefinition();
            }
        }
        result = geomFactory.createMultiPoint(centroids);
    } else {
        Geometry geom = geoms.get(0).getGeometry();
        oldCRS = geoms.get(0).getCRSDefinition();
        if (geom != null) {
            result = geom.getCentroid();
        } else {
            throw new TransformationException("Geometry for centroid could not be retrieved.");
        }
    }
    return new DefaultGeometryProperty<Geometry>(oldCRS, result);
}
Also used : DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Geometry(com.vividsolutions.jts.geom.Geometry) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)

Example 4 with DepthFirstInstanceTraverser

use of eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser in project hale by halestudio.

the class NetworkExpansion method calculateBuffer.

/**
 * Calculate a buffer geometry.
 *
 * @param geometryHolder the geometry or object holding a geometry
 * @param bufferWidth the buffer width
 * @param log the transformation log, may be <code>null</code>
 * @return the buffer geometry or <code>null</code>
 */
@Nullable
public static GeometryProperty<Geometry> calculateBuffer(Object geometryHolder, double bufferWidth, @Nullable TransformationLog log) {
    // find contained geometries
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
    GeometryFinder geoFind = new GeometryFinder(null);
    traverser.traverse(geometryHolder, geoFind);
    List<GeometryProperty<?>> geometries = geoFind.getGeometries();
    GeometryProperty<?> old_geometry = null;
    if (!geometries.isEmpty()) {
        old_geometry = geometries.get(0);
        if (geometries.size() > 1) {
            if (log != null) {
                log.warn(log.createMessage("Multiple geometries found, but network expansion is only done on the first.", null));
            }
        }
    }
    GeometryProperty<Geometry> result = null;
    if (old_geometry != null) {
        Geometry new_geometry = null;
        BufferParameters bufferParameters = new BufferParameters();
        bufferParameters.setEndCapStyle(CAP_STYLE);
        BufferBuilder bb = new BufferBuilder(new BufferParameters());
        new_geometry = bb.buffer(old_geometry.getGeometry(), bufferWidth);
        result = new DefaultGeometryProperty<Geometry>(old_geometry.getCRSDefinition(), new_geometry);
    }
    return result;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) BufferParameters(com.vividsolutions.jts.operation.buffer.BufferParameters) BufferBuilder(com.vividsolutions.jts.operation.buffer.BufferBuilder) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Nullable(javax.annotation.Nullable)

Example 5 with DepthFirstInstanceTraverser

use of eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser in project hale by halestudio.

the class XMLInspector method getReferencedIdentities.

@Override
public Set<String> getReferencedIdentities(Instance instance) {
    // find all (local) xlink references
    DepthFirstInstanceTraverser traverser = new DepthFirstInstanceTraverser();
    LocalXLinks xlinks = new LocalXLinks();
    traverser.traverse(instance, xlinks);
    return xlinks.getReferencedIDs();
}
Also used : DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)

Aggregations

DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)12 GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)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