Search in sources :

Example 6 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project jena by apache.

the class WKTReader method buildPolygon.

private Polygon buildPolygon(String coordinates) {
    Polygon polygon;
    String[] splitCoordinates = splitCoordinates(coordinates);
    if (splitCoordinates.length == 1) {
        // Polygon without holes.
        CustomCoordinateSequence shellSequence = new CustomCoordinateSequence(dims, clean(coordinates));
        polygon = GEOMETRY_FACTORY.createPolygon(shellSequence);
    } else {
        // Polygon with holes
        String shellCoordinates = splitCoordinates[0];
        CustomCoordinateSequence shellSequence = new CustomCoordinateSequence(dims, clean(shellCoordinates));
        LinearRing shellLinearRing = GEOMETRY_FACTORY.createLinearRing(shellSequence);
        String[] splitHoleCoordinates = Arrays.copyOfRange(splitCoordinates, 1, splitCoordinates.length);
        LinearRing[] holesLinearRing = splitLinearRings(dims, splitHoleCoordinates);
        polygon = GEOMETRY_FACTORY.createPolygon(shellLinearRing, holesLinearRing);
    }
    return polygon;
}
Also used : LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 7 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project jena by apache.

the class WKTReader method splitLinearRings.

private LinearRing[] splitLinearRings(CoordinateSequenceDimensions dims, String[] splitCoordinates) {
    LinearRing[] linearRings = new LinearRing[splitCoordinates.length];
    for (int i = 0; i < splitCoordinates.length; i++) {
        CustomCoordinateSequence sequence = new CustomCoordinateSequence(dims, clean(splitCoordinates[i]));
        LinearRing linearRing = GEOMETRY_FACTORY.createLinearRing(sequence);
        linearRings[i] = linearRing;
    }
    return linearRings;
}
Also used : LinearRing(org.locationtech.jts.geom.LinearRing) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 8 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project jena by apache.

the class GeometryTransformation method transformLinearRing.

private static LinearRing transformLinearRing(Geometry sourceGeometry, MathTransform transform) throws TransformException {
    GeometryFactory geometryFactory = sourceGeometry.getFactory();
    LinearRing linearRing = (LinearRing) sourceGeometry;
    CoordinateSequence coordSeq = linearRing.getCoordinateSequence();
    CoordinateSequence transformCoordSeq = transformCoordSeq(coordSeq, transform);
    return geometryFactory.createLinearRing(transformCoordSeq);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 9 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project jena by apache.

the class GMLReaderTest method testExtractPolygonHole.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractPolygonHole() throws JDOMException, IOException {
    LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 10, 40 40, 20 40, 10 20, 30 10"));
    LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 30, 35 35, 30 20, 20 30")) };
    Geometry geometry = GEOMETRY_FACTORY.createPolygon(shell, holes);
    GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>30 10 40 40 20 40 10 20 30 10</gml:posList></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:posList>20 30 35 35 30 20 20 30</gml:posList></gml:LinearRing></gml:interior></gml:Polygon>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) LinearRing(org.locationtech.jts.geom.LinearRing) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 10 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project jena by apache.

the class GMLReaderTest method testExtractMultiSurface2.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractMultiSurface2() throws JDOMException, IOException {
    Polygon[] polygons = new Polygon[2];
    polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 20 45, 45 30, 40 40"));
    LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 35, 10 30, 10 10, 30 5, 45 20, 20 35"));
    LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 20, 20 15, 20 25, 30 20")) };
    polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes);
    Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
    GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:MultiSurface xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:surfaceMember><gml:Polygon srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>40 40 20 45 45 30 40 40</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>20 35 10 30 10 10 30 5 45 20 20 35</gml:posList></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:posList>30 20 20 15 20 25 30 20</gml:posList></gml:LinearRing></gml:interior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) LinearRing(org.locationtech.jts.geom.LinearRing) 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