Search in sources :

Example 26 with LinearRing

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

the class SurfaceGeometryTest method testSurfaceGml32_patches.

/**
 * Test surface geometry consisting of multiple patches read from a GML 3.2
 * file.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testSurfaceGml32_patches() throws Exception {
    InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-gml32_patches.xml").toURI());
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-4.5, 3), new Coordinate(0.5, 4.5), new Coordinate(5, 3), new Coordinate(8.5, 2), new Coordinate(3, -4.5), new Coordinate(1, 1), new Coordinate(-3, -1), new Coordinate(-4.5, 3) });
    Polygon composedPolygon = geomFactory.createPolygon(shell);
    // one instance expected
    ResourceIterator<Instance> it = instances.iterator();
    try {
        // PolygonPatch with LinearRings defined through coordinates
        assertTrue("First sample feature missing", it.hasNext());
        Instance instance = it.next();
        checkSingleGeometry(instance, referenceChecker(composedPolygon));
    } finally {
        it.close();
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)

Example 27 with LinearRing

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

the class WindingOrder method unifyWindingOrderForPolyGon.

/**
 * Unify order of the polygon as counterClockwise or not including all its
 * holes.
 *
 * @param poly Polygon object for unifying
 * @param counterClockWise boolean value. true, if want shell of Polygon as
 *            counter clock wise and holes as clockwise, else false.
 * @return Polygon unified object.
 */
public static Polygon unifyWindingOrderForPolyGon(Polygon poly, boolean counterClockWise) {
    // Checking and reversing Shell
    LinearRing shell = unifyWindingOrderForLinearRing((LinearRing) poly.getExteriorRing(), counterClockWise);
    Polygon revPoly;
    // Checking and reversing Holes
    if (poly.getNumInteriorRing() > 0) {
        LinearRing[] holes = new LinearRing[poly.getNumInteriorRing()];
        for (int i = 0; i < poly.getNumInteriorRing(); i++) {
            holes[i] = unifyWindingOrderForLinearRing((LinearRing) poly.getInteriorRingN(i), !counterClockWise);
        }
        // Create New Polygon using unified shell and holes both.
        revPoly = factory.createPolygon(shell, holes);
    } else
        // Create New Polygon using unified shell only
        revPoly = factory.createPolygon(shell);
    return revPoly;
}
Also used : LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 28 with LinearRing

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

the class WindingOrderTest method setUp.

/**
 * Setup for different tests
 */
@BeforeClass
public static void setUp() {
    GeometryFactory factory = new GeometryFactory();
    r1 = factory.createLinearRing(new Coordinate[] { new Coordinate(10, 30), new Coordinate(20, 0), new Coordinate(0, 0), new Coordinate(10, 30) });
    r2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87445, 8.64729), new Coordinate(49.87582, 8.65441), new Coordinate(49.87095, 8.65694), new Coordinate(49.86978, 8.65032), new Coordinate(49.87197, 8.64758), new Coordinate(49.87341, 8.64688), new Coordinate(49.87445, 8.64729) });
    h1 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87327, 8.64991), new Coordinate(49.8735, 8.6521), new Coordinate(49.87253, 8.65239), new Coordinate(49.8723, 8.65045), new Coordinate(49.87327, 8.64991) });
    h2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87203, 8.65208), new Coordinate(49.87209, 8.6531), new Coordinate(49.87156, 8.65312), new Coordinate(49.87145, 8.65227), new Coordinate(49.87203, 8.65208) });
    clockWise1 = factory.createPolygon(r1);
    clockWise2 = factory.createPolygon(r2, new LinearRing[] { h1, h2 });
    clockWise2WOHoles = factory.createPolygon(r2);
    clockWise3 = factory.createMultiPolygon(new Polygon[] { clockWise1, clockWise2 });
    clockWise4 = factory.createGeometryCollection(new Geometry[] { clockWise2, clockWise2WOHoles, clockWise3, r2 });
    if (crs1 == null) {
        try {
            crs1 = CRS_CACHE.get(code1);
        } catch (Exception e) {
            throw new IllegalStateException("Invalid CRS code", e);
        }
    }
    if (crs2 == null) {
        try {
            crs2 = CRS_CACHE.get(code2);
        } catch (Exception e) {
            throw new IllegalStateException("Invalid CRS code", e);
        }
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) BeforeClass(org.junit.BeforeClass)

Example 29 with LinearRing

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

the class InteriorPointTest method testTriangle.

/**
 * Test with a simple triangular polygon.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testTriangle() throws Exception {
    LinearRing outer = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87401, 8.65491), new Coordinate(49.87318, 8.65606), new Coordinate(49.87297, 8.6545), new Coordinate(49.87401, 8.65491) });
    Polygon geom = factory.createPolygon(outer);
    testPointWithin(geom);
}
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) Test(org.junit.Test)

Example 30 with LinearRing

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

the class InteriorPointTest method testFootprint2Hole.

/**
 * Test with a complex polygon describing a rough building footprint.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testFootprint2Hole() throws Exception {
    LinearRing outer = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87517, 8.64862), new Coordinate(49.87491, 8.64873), new Coordinate(49.87497, 8.64913), new Coordinate(49.87521, 8.64904), new Coordinate(49.87525, 8.64924), new Coordinate(49.87424, 8.64958), new Coordinate(49.8742, 8.64937), new Coordinate(49.87446, 8.64929), new Coordinate(49.87441, 8.6489), new Coordinate(49.87414, 8.64897), new Coordinate(49.87411, 8.64877), new Coordinate(49.87514, 8.64844), new Coordinate(49.87517, 8.64862) });
    LinearRing inner = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87478, 8.6488), new Coordinate(49.87482, 8.64914), new Coordinate(49.8746, 8.64924), new Coordinate(49.87454, 8.64887), new Coordinate(49.87478, 8.6488) });
    Polygon geom = factory.createPolygon(outer, new LinearRing[] { inner });
    testPointWithin(geom);
}
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) Test(org.junit.Test)

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