Search in sources :

Example 36 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class RingHandler method createGeometry.

/**
 * Create a {@link LinearRing} geometry from the given instance.
 *
 * @param instance the instance
 * @param srsDimension the SRS dimension
 * @param allowTryOtherDimension if trying another dimension is allowed on
 *            failure (e.g. 3D instead of 2D)
 * @param reader the I/O Provider to get value
 * @return the {@link LinearRing} geometry
 * @throws GeometryNotSupportedException if the type definition doesn't
 *             represent a geometry type supported by the handler
 */
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing ring = null;
    // for use with GML 2, 3, 3.1, 3.2
    // use generic geometry handler to read curveMembers as MultiLineString
    // or LineString
    Collection<GeometryProperty<?>> properties = genericHandler.createGeometry(instance, srsDimension, reader);
    if (properties != null) {
        if (properties.size() == 1) {
            // geometry could be combined
            GeometryProperty<?> prop = properties.iterator().next();
            try {
                ring = getGeometryFactory().createLinearRing(filterDuplicates(prop.getGeometry().getCoordinates()));
            } catch (IllegalArgumentException e) {
                if (allowTryOtherDimension) {
                    // the error
                    // "Points of LinearRing do not form a closed
                    // linestring"
                    // can be an expression of a wrong dimension being used
                    // we try an alternative, to be sure (e.g. 3D instead of
                    // 2D)
                    int alternativeDimension = (srsDimension == 2) ? (3) : (2);
                    GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
                    log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
                    return geom;
                }
                throw e;
            }
            if (ring != null) {
                CRSDefinition crsDef = prop.getCRSDefinition();
                if (crsDef == null) {
                    GMLGeometryUtil.findCRS(instance);
                }
                return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
            }
        } else {
            throw new GeometryNotSupportedException("Ring components could not be combined to a geometry");
        }
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 37 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class PolygonPatchGeometryTest method init.

@Override
public void init() {
    super.init();
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) });
    LinearRing[] holes = new LinearRing[2];
    LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(0, -1), new Coordinate(-1, -1), new Coordinate(0, 1) });
    LinearRing hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 2), new Coordinate(2, 2), new Coordinate(0, -2), new Coordinate(-2, -2), new Coordinate(0, 2) });
    holes[0] = hole1;
    holes[1] = hole2;
    reference = geomFactory.createPolygon(shell, holes);
    checker = combine(noCoordinatePairs(), referenceChecker(reference));
    gridChecker = combine(noCoordinatePairs(), referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 38 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class RectangleGeometryTest method init.

@Override
public void init() {
    super.init();
    Coordinate[] coordinates = new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) };
    LinearRing linearRing = geomFactory.createLinearRing(coordinates);
    referencePolygon = geomFactory.createPolygon(linearRing, null);
    checker = combine(noCoordinatePairs(), referenceChecker(referencePolygon));
    gridChecker = combine(noCoordinatePairs(), referenceChecker(referencePolygon, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 39 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class TriangleGeometryTest method init.

@Override
public void init() {
    super.init();
    Coordinate[] coordinates = new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) };
    LinearRing linearRing = geomFactory.createLinearRing(coordinates);
    referencePolygon = geomFactory.createPolygon(linearRing, null);
    checker = combine(noCoordinatePairs(), referenceChecker(referencePolygon));
    gridChecker = combine(noCoordinatePairs(), referenceChecker(referencePolygon, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 40 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class LinearRingHandler method createGeometry.

/**
 * Create a {@link LinearRing} geometry from the given instance.
 *
 * @param instance the instance
 * @param srsDimension the SRS dimension
 * @param allowTryOtherDimension if trying another dimension is allowed on
 *            failure (e.g. 3D instead of 2D)
 * @param reader the I/O Provider to get value
 * @return the {@link LinearRing} geometry
 * @throws GeometryNotSupportedException if the type definition doesn't
 *             represent a geometry type supported by the handler
 */
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing ring = null;
    LineStringHandler handler = new LineStringHandler();
    // for use with GML 2, 3, 3.1, 3.2
    @SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> linestring = (DefaultGeometryProperty<LineString>) handler.createGeometry(instance, srsDimension, reader);
    try {
        ring = getGeometryFactory().createLinearRing(linestring.getGeometry().getCoordinates());
    } catch (IllegalArgumentException e) {
        if (allowTryOtherDimension) {
            // the error
            // "Points of LinearRing do not form a closed linestring"
            // can be an expression of a wrong dimension being used
            // we try an alternative, to be sure (e.g. 3D instead of 2D)
            int alternativeDimension = (srsDimension == 2) ? (3) : (2);
            GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
            log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
            return geom;
        }
        throw e;
    }
    if (ring != null) {
        CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
        return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LineString(org.locationtech.jts.geom.LineString) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) LinearRing(org.locationtech.jts.geom.LinearRing)

Aggregations

LinearRing (org.locationtech.jts.geom.LinearRing)66 Coordinate (org.locationtech.jts.geom.Coordinate)39 Polygon (org.locationtech.jts.geom.Polygon)33 Test (org.junit.Test)27 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)23 LineString (org.locationtech.jts.geom.LineString)14 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)10 Geometry (org.locationtech.jts.geom.Geometry)10 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)8 Point (org.locationtech.jts.geom.Point)8 MultiPoint (org.locationtech.jts.geom.MultiPoint)7 ArrayList (java.util.ArrayList)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)6 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)6 Test (org.junit.jupiter.api.Test)4 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)3