Search in sources :

Example 16 with GeometryProperty

use of eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty in project hale by halestudio.

the class InstanceMarker method doPaintMarker.

/**
 * @see BoundingBoxMarker#doPaintMarker(Graphics2D, SelectableWaypoint,
 *      PixelConverter, int, int, int, int, int, Rectangle, boolean)
 */
@Override
protected Area doPaintMarker(Graphics2D g, InstanceWaypoint context, PixelConverter converter, int zoom, int minX, int minY, int maxX, int maxY, Rectangle gBounds, boolean calulateArea) {
    List<Area> areas = (!calulateArea) ? (null) : (new ArrayList<Area>());
    List<GeometryProperty<?>> geometries = context.getGeometries();
    // map CRS
    CoordinateReferenceSystem mapCRS;
    try {
        mapCRS = CRSDecode.getLonLatCRS(converter.getMapEpsg());
    // map (GeoPosition) assumes lon/lat order
    } catch (Throwable e) {
        log.error("Could not decode map CRS", e);
        return null;
    }
    // paint each geometry
    for (GeometryProperty<?> geometry : geometries) {
        Area geometryArea = paintGeometry(g, geometry.getCRSDefinition(), geometry.getGeometry(), context, converter, zoom, geometries.size() == 1, gBounds, mapCRS, calulateArea);
        if (areas != null && geometryArea != null) {
            areas.add(geometryArea);
        }
    }
    if (areas == null) {
        return null;
    }
    if (areas.size() == 1) {
        return areas.get(0);
    } else if (!areas.isEmpty()) {
        return new MultiArea(areas);
    }
    return null;
}
Also used : Area(de.fhg.igd.mapviewer.marker.area.Area) PolygonArea(de.fhg.igd.mapviewer.marker.area.PolygonArea) MultiArea(de.fhg.igd.mapviewer.marker.area.MultiArea) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) ArrayList(java.util.ArrayList) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) MultiArea(de.fhg.igd.mapviewer.marker.area.MultiArea)

Example 17 with GeometryProperty

use of eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty in project hale by halestudio.

the class CalculateLength 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 length = 0;
        for (GeometryProperty<?> geoProp : geoms) {
            length += geoProp.getGeometry().getLength();
        }
        return length;
    } else {
        geom = geoms.get(0).getGeometry();
    }
    if (geom != null) {
        return geom.getLength();
    } else {
        throw new TransformationException("Geometry for calculate length 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 18 with GeometryProperty

use of eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty in project hale by halestudio.

the class ReprojectGeometry method evaluate.

@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("source").get(0);
    Object inputValue = input.getValue();
    InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
    GeometryFinder geoFind = new GeometryFinder(null);
    traverser.traverse(inputValue, geoFind);
    List<GeometryProperty<?>> geoms = geoFind.getGeometries();
    Geometry sourceGeometry = geoms.get(0).getGeometry();
    CRSDefinition crsDef = geoms.get(0).getCRSDefinition();
    if (crsDef == null) {
        throw new TransformationException("Geometry does not have an associated Coordinate Reference System");
    }
    CoordinateReferenceSystem sourceCRS = crsDef.getCRS();
    Geometry resultGeometry = sourceGeometry;
    CoordinateReferenceSystem targetCRS = sourceCRS;
    // Get input parameter
    String srs = getParameterChecked(PARAMETER_REFERENCE_SYSTEM).as(String.class);
    if (srs != null) {
        try {
            targetCRS = parseReferenceSystemParamter(srs);
        } catch (Exception e) {
            throw new TransformationException("Error determining destination Cordinate Reference System.", e);
        }
        // Retrieve transformation from cell context, or create a new
        // instance
        Map<Object, Object> cellContext = getExecutionContext().getCellContext();
        MathTransform transform = getOrCreateMathTransform(sourceCRS, targetCRS, cellContext);
        // Apply transformation
        try {
            resultGeometry = JTS.transform(sourceGeometry, transform);
        } catch (MismatchedDimensionException | TransformException e) {
            throw new TransformationException("Problem on execute transformation from: " + sourceCRS + " to " + targetCRS, e);
        }
    }
    return new DefaultGeometryProperty<Geometry>(new CodeDefinition(CRS.toSRS(targetCRS), targetCRS), resultGeometry);
}
Also used : 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) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) MathTransform(org.opengis.referencing.operation.MathTransform) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) TransformException(org.opengis.referencing.operation.TransformException) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) FactoryException(org.opengis.referencing.FactoryException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) TransformException(org.opengis.referencing.operation.TransformException) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Geometry(com.vividsolutions.jts.geom.Geometry) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) CodeDefinition(eu.esdihumboldt.hale.common.instance.geometry.impl.CodeDefinition) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 19 with GeometryProperty

use of eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty in project hale by halestudio.

the class InteriorPoint method calculateInteriorPoint.

/**
 * Calculate an interior point for a given geometry or object holding a
 * geometry.
 *
 * @param geometryHolder {@link Geometry}, {@link GeometryProperty} or
 *            {@link Instance} holding a geometry
 * @return an interior point of the geometry
 * @throws TransformationException if the interior point could not be
 *             calculated
 */
public static GeometryProperty<?> calculateInteriorPoint(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;
    // use the first geometry encountered
    int index = 0;
    Geometry geom = null;
    while (geom == null && index < geoms.size()) {
        geom = geoms.get(index).getGeometry();
        oldCRS = geoms.get(index).getCRSDefinition();
        index++;
    }
    if (geom != null) {
        try {
            result = geom.getInteriorPoint();
        } catch (TopologyException e) {
            // calculate the point for a geometry with a small buffer to
            // avoid error with polygons that have overlapping lines
            result = geom.buffer(0.000001).getInteriorPoint();
            if (!result.within(geom)) {
                // geometry
                throw new TransformationException("Could not determine interior point for geometry");
            }
        }
    } else {
        return null;
    }
    return new DefaultGeometryProperty<Geometry>(oldCRS, result);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) 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) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) TopologyException(com.vividsolutions.jts.geom.TopologyException) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)

Example 20 with GeometryProperty

use of eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty in project hale by halestudio.

the class AbstractHandlerTest method checkSingleGeometry.

/**
 * Check a single geometry contained in an instance (at an arbitrary path).
 *
 * @param instance the geometry instance
 * @param checker the checker (should throw an exception when the check
 *            fails)
 * @return the collection of encountered geometries
 */
protected Collection<GeometryProperty<?>> checkSingleGeometry(Instance instance, @Nullable Consumer<Geometry> checker) {
    GeometryFinder finder = new GeometryFinder(null);
    BreadthFirstInstanceTraverser traverser = new BreadthFirstInstanceTraverser();
    traverser.traverse(instance, finder);
    List<GeometryProperty<?>> geoms = finder.getGeometries();
    assertFalse("No geometry found in instances", geoms.isEmpty());
    assertEquals("More than one geometry found in instance", 1, geoms.size());
    Geometry geom = geoms.get(0).getGeometry();
    if (checker != null) {
        checker.accept(geom);
    }
    return geoms;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) BreadthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.BreadthFirstInstanceTraverser)

Aggregations

GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)25 Geometry (com.vividsolutions.jts.geom.Geometry)17 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)11 ArrayList (java.util.ArrayList)11 GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)8 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)8 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)8 DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)7 InstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser)7 Polygon (com.vividsolutions.jts.geom.Polygon)5 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)5 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)4 Collection (java.util.Collection)4 LinearRing (com.vividsolutions.jts.geom.LinearRing)3 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 Point (com.vividsolutions.jts.geom.Point)3 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)3 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)3 QName (javax.xml.namespace.QName)3 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)3