Search in sources :

Example 1 with GeometryFinder

use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder in project hale by halestudio.

the class ShapefileInstanceWriter method traverseInstanceForGeometries.

/**
 * Method to traverse instance to find geometries.
 *
 * @param instance instance.
 * @return list of geometries.
 */
private List<GeometryProperty<?>> traverseInstanceForGeometries(Instance instance) {
    // find geometries in the schema.
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
    GeometryFinder geoFind = new GeometryFinder(null);
    traverser.traverse(instance, geoFind);
    List<GeometryProperty<?>> geoms = geoFind.getGeometries();
    return geoms;
}
Also used : InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)

Example 2 with GeometryFinder

use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder 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 3 with GeometryFinder

use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder 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(org.locationtech.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 4 with GeometryFinder

use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder 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);
        new_geometry = BufferOp.bufferOp(old_geometry.getGeometry(), bufferWidth, bufferParameters);
        result = new DefaultGeometryProperty<Geometry>(old_geometry.getCRSDefinition(), new_geometry);
    }
    return result;
}
Also used : Geometry(org.locationtech.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(org.locationtech.jts.operation.buffer.BufferParameters) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Nullable(javax.annotation.Nullable)

Example 5 with GeometryFinder

use of eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder 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(org.locationtech.jts.geom.GeometryFactory) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Geometry(org.locationtech.jts.geom.Geometry) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)

Aggregations

GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)14 DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)13 InstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser)13 Geometry (org.locationtech.jts.geom.Geometry)11 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)10 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)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 Point (org.locationtech.jts.geom.Point)3 CodeDefinition (eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition)2 ArrayList (java.util.ArrayList)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)2 FactoryException (org.opengis.referencing.FactoryException)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 TransformException (org.opengis.referencing.operation.TransformException)2 BoundingBox (de.fhg.igd.geom.BoundingBox)1