Search in sources :

Example 21 with LinearRing

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

the class ExtendedWKBReader method readPolygon.

@SuppressWarnings("null")
private Polygon readPolygon() throws IOException {
    int numRings = dis.readInt();
    LinearRing[] holes = null;
    if (numRings > 1)
        holes = new LinearRing[numRings - 1];
    LinearRing shell = readLinearRing();
    for (int i = 0; i < numRings - 1; i++) {
        holes[i] = readLinearRing();
    }
    return factory.createPolygon(shell, holes);
}
Also used : LinearRing(org.locationtech.jts.geom.LinearRing) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 22 with LinearRing

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

the class PolygonHandlerTest method init.

// XXX no test for geometry properties
@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 23 with LinearRing

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

the class CompositeSurfaceGeometryTest 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;
    Polygon polygon1 = geomFactory.createPolygon(shell, holes);
    shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(6.01, 9.2), new Coordinate(9.33, 9.33), new Coordinate(6.01, -9.2), new Coordinate(-9.33, -9.2), new Coordinate(6.01, 9.2) });
    holes = new LinearRing[2];
    hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(2, 3), new Coordinate(3, 3), new Coordinate(2, -3), new Coordinate(-3, -3), new Coordinate(2, 3) });
    hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(2, 4), new Coordinate(4, 4), new Coordinate(2, -4), new Coordinate(-4, -4), new Coordinate(2, 4) });
    holes[0] = hole1;
    holes[1] = hole2;
    Polygon polygon2 = geomFactory.createPolygon(shell, holes);
    Polygon[] polygons = new Polygon[] { polygon1, polygon2 };
    reference = geomFactory.createMultiPolygon(polygons);
    checker = referenceChecker(reference);
    gridChecker = combine(referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 24 with LinearRing

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

the class OrientableSurfaceGeometryTest method init.

@Override
public void init() {
    super.init();
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-122.44, 37.80), new Coordinate(-122.45, 37.80), new Coordinate(-122.45, 37.78), new Coordinate(-122.44, 37.78), new Coordinate(-122.44, 37.80) });
    LinearRing[] holes = new LinearRing[1];
    LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-122.24, 37.60), new Coordinate(-122.25, 37.60), new Coordinate(-122.25, 37.58), new Coordinate(-122.24, 37.58), new Coordinate(-122.24, 37.60) });
    holes[0] = hole1;
    reference = geomFactory.createPolygon(shell, holes);
    checker = referenceChecker(reference);
    gridChecker = combine(referenceChecker(reference, maxPositionalError), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 25 with LinearRing

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

the class PolygonHandler method createGeometry.

/**
 * @see GeometryHandler#createGeometry(Instance, int, IOProvider)
 */
@SuppressWarnings("unchecked")
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing[] holes = null;
    Polygon polygon = null;
    CRSDefinition crs = null;
    // for use with GML 2
    // to parse outer linear rings
    Collection<Object> values = PropertyResolver.getValues(instance, "outerBoundaryIs.LinearRing", false);
    if (values != null && !values.isEmpty()) {
        Iterator<Object> iterator = values.iterator();
        List<LinearRing> outerRing = new ArrayList<>(1);
        while (iterator.hasNext()) {
            Object value = iterator.next();
            if (value instanceof Instance) {
                // outerRing must be a
                // GeometryProperty<LinearRing> instance
                GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                outerRing.add(ring.getGeometry());
                crs = checkCommonCrs(crs, ring.getCRSDefinition());
            }
        }
        // to parse inner linear rings
        values = PropertyResolver.getValues(instance, "innerBoundaryIs.LinearRing", false);
        if (values != null && !values.isEmpty()) {
            iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
    }
    // to parse inner linear rings
    if (polygon == null) {
        values = PropertyResolver.getValues(instance, "interior.LinearRing", false);
        Collection<Object> ringValues = PropertyResolver.getValues(instance, "interior.Ring", false);
        values = combineCollections(values, ringValues);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        // to parse outer linear rings
        values = PropertyResolver.getValues(instance, "exterior.LinearRing", false);
        ringValues = PropertyResolver.getValues(instance, "exterior.Ring", false);
        values = combineCollections(values, ringValues);
        List<LinearRing> outerRing = new ArrayList<>(1);
        if (values != null && !values.isEmpty()) {
            LinearRing outer = null;
            Iterator<Object> iterator = values.iterator();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // outerRing must be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    outer = ring.getGeometry();
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            outerRing.add(outer);
            polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
        }
    }
    if (polygon != null) {
        if (crs == null) {
            crs = GMLGeometryUtil.findCRS(instance);
        }
        return new DefaultGeometryProperty<Polygon>(crs, polygon);
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon)

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