Search in sources :

Example 56 with LinearRing

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

the class SurfaceGeometryTest 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 = combine(noCoordinatePairs(), referenceChecker(reference));
    gridChecker = combine(noCoordinatePairs(), referenceChecker(reference, maxPositionalError), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 57 with LinearRing

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

the class SurfaceGeometryTest method testSurfaceGml32_patches_hole.

/**
 * Test surface geometry consisting of multiple patches (including holes)
 * read from a GML 3.2 file.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testSurfaceGml32_patches_hole() throws Exception {
    InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-gml32_patches_hole.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) });
    LinearRing[] holes = new LinearRing[] { geomFactory.createLinearRing(new Coordinate[] { new Coordinate(3, 0.5), new Coordinate(4, -2), new Coordinate(6.5, 1.5), new Coordinate(4.5, 2), new Coordinate(3, 0.5) }) };
    Polygon composedPolygon = geomFactory.createPolygon(shell, holes);
    // 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 58 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project series-rest-api by 52North.

the class GeoJSONTest method randomLinearRing.

private LinearRing randomLinearRing(int srid) {
    Coordinate p = randomCoordinate();
    LinearRing geometry = geometryFactory.createLinearRing(new Coordinate[] { p, randomCoordinate(), randomCoordinate(), randomCoordinate(), p });
    geometry.setSRID(srid);
    return geometry;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 59 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project graphhopper by graphhopper.

the class AreaIndexTest method testHole.

@Test
public void testHole() {
    GeometryFactory gf = new GeometryFactory();
    LinearRing shell = gf.createLinearRing(new Coordinate[] { new Coordinate(1, 1), new Coordinate(7, 1), new Coordinate(7, 7), new Coordinate(1, 7), new Coordinate(1, 1) });
    LinearRing hole = gf.createLinearRing(new Coordinate[] { new Coordinate(4, 2), new Coordinate(6, 2), new Coordinate(6, 4), new Coordinate(4, 6), new Coordinate(4, 2) });
    {
        Polygon p = gf.createPolygon(shell, new LinearRing[] { hole });
        AreaIndex<CustomArea> index = new AreaIndex<>(Collections.singletonList(createCustomArea("1", p)));
        testQuery(index, 3, 5);
    }
    {
        Polygon p = gf.createPolygon(hole);
        AreaIndex<CustomArea> index = new AreaIndex<>(Collections.singletonList(createCustomArea("2", p)));
        testQuery(index, 3, 5, "2");
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) AreaIndex(com.graphhopper.routing.util.AreaIndex) Test(org.junit.jupiter.api.Test)

Example 60 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project ddf by codice.

the class Polygon method buildPolygon.

public static org.locationtech.jts.geom.Polygon buildPolygon(List coordinates) {
    // according to the GeoJson specification, first ring is the exterior
    LinearRing exterior = GEOMETRY_FACTORY.createLinearRing(getCoordinates((List) coordinates.get(0)));
    LinearRing[] interiorHoles = new LinearRing[coordinates.size() - 1];
    for (int i = 1; i < coordinates.size(); i++) {
        interiorHoles[i - 1] = GEOMETRY_FACTORY.createLinearRing(getCoordinates((List) coordinates.get(i)));
    }
    return GEOMETRY_FACTORY.createPolygon(exterior, interiorHoles);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) LinearRing(org.locationtech.jts.geom.LinearRing)

Aggregations

LinearRing (org.locationtech.jts.geom.LinearRing)69 Coordinate (org.locationtech.jts.geom.Coordinate)42 Polygon (org.locationtech.jts.geom.Polygon)34 Test (org.junit.Test)27 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)23 LineString (org.locationtech.jts.geom.LineString)15 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)10 Geometry (org.locationtech.jts.geom.Geometry)10 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)10 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