Search in sources :

Example 66 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project janusgraph by JanusGraph.

the class GeoToWktConverterTest method testConvertGeoshapePolygonToWktString.

@Test
public void testConvertGeoshapePolygonToWktString() throws BackendException {
    GeometryFactory gf = new GeometryFactory();
    Geoshape p1 = Geoshape.polygon(Arrays.asList(new double[][] { { 35.4, 48.9 }, { 35.6, 48.9 }, { 35.6, 49.1 }, { 35.4, 49.1 }, { 35.4, 48.9 } }));
    Geoshape p2 = HELPER.geoshape(gf.createPolygon(gf.createLinearRing(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 10), new Coordinate(20, 20), new Coordinate(10, 20), new Coordinate(10, 10) }), new LinearRing[] { gf.createLinearRing(new Coordinate[] { new Coordinate(13, 13), new Coordinate(17, 13), new Coordinate(17, 17), new Coordinate(13, 17), new Coordinate(13, 13) }) }));
    String wkt1 = "POLYGON ((35.4 48.9, 35.6 48.9, 35.6 49.1, 35.4 49.1, 35.4 48.9))";
    String actualWkt1 = GeoToWktConverter.convertToWktString(p1);
    assertEquals(wkt1, actualWkt1);
    String wkt2 = "POLYGON ((10 10, 20 10, 20 20, 10 20, 10 10), (13 13, 17 13, 17 17, 13 17, 13 13))";
    String actualWkt2 = GeoToWktConverter.convertToWktString(p2);
    assertEquals(wkt2, actualWkt2);
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LineString(org.locationtech.jts.geom.LineString) LinearRing(org.locationtech.jts.geom.LinearRing) Test(org.junit.jupiter.api.Test)

Example 67 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project presto by prestodb.

the class JtsGeometrySerde method readPolygon.

private static Geometry readPolygon(SliceInput input, boolean multitype) {
    skipEsriType(input);
    skipEnvelope(input);
    int partCount = input.readInt();
    if (partCount == 0) {
        if (multitype) {
            return GEOMETRY_FACTORY.createMultiPolygon();
        }
        return GEOMETRY_FACTORY.createPolygon();
    }
    int pointCount = input.readInt();
    int[] startIndexes = new int[partCount];
    for (int i = 0; i < partCount; i++) {
        startIndexes[i] = input.readInt();
    }
    int[] partLengths = new int[partCount];
    if (partCount > 1) {
        partLengths[0] = startIndexes[1];
        for (int i = 1; i < partCount - 1; i++) {
            partLengths[i] = startIndexes[i + 1] - startIndexes[i];
        }
    }
    partLengths[partCount - 1] = pointCount - startIndexes[partCount - 1];
    LinearRing shell = null;
    List<LinearRing> holes = new ArrayList<>();
    List<Polygon> polygons = new ArrayList<>();
    try {
        for (int i = 0; i < partCount; i++) {
            Coordinate[] coordinates = readCoordinates(input, partLengths[i]);
            if (isClockwise(coordinates)) {
                // next polygon has started
                if (shell != null) {
                    polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
                    holes.clear();
                }
                shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
            } else {
                holes.add(GEOMETRY_FACTORY.createLinearRing(coordinates));
            }
        }
        polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
    } catch (IllegalArgumentException e) {
        throw new TopologyException("Error constructing Polygon: " + e.getMessage());
    }
    if (multitype) {
        return GEOMETRY_FACTORY.createMultiPolygon(polygons.toArray(new Polygon[0]));
    }
    return getOnlyElement(polygons);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) TopologyException(org.locationtech.jts.geom.TopologyException)

Example 68 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project sldeditor by robward-scisys.

the class ExamplePolygonImpl method getPolygon.

/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.datasource.impl.ExamplePolygonInterface#getPolygon()
     */
@Override
public Polygon getPolygon() {
    if (polygon == null) {
        // CHECKSTYLE:OFF
        double[][] rawLocations = new double[][] { { -4.49210295036, 54.4153472858 }, { -4.4634856663, 54.4269825687 }, { -4.43426958965, 54.4117153967 }, { -4.40869623532, 54.4326291409 }, { -4.32782927985, 54.4641980089 }, { -4.3659606463, 54.4197683392 }, { -4.33467823679, 54.4265693547 }, { -4.32454274819, 54.4024986924 }, { -4.34126081686, 54.3660155026 }, { -4.3424304253, 54.3042112639 }, { -4.37506398925, 54.3014094498 }, { -4.41392105869, 54.2658635384 }, { -4.44375514123, 54.2532227674 }, { -4.44763651915, 54.196776024 }, { -4.48315404347, 54.1850220956 }, { -4.52311962815, 54.1455956993 }, { -4.58362722513, 54.1091637546 }, { -4.62431015799, 54.0527236394 }, { -4.71452726534, 54.0188283696 }, { -4.71863162723, 54.0497614848 }, { -4.75157122164, 54.0647816773 }, { -4.79755603397, 54.0685543663 }, { -4.79717105693, 54.122792557 }, { -4.74451711581, 54.1875314993 }, { -4.73842361793, 54.2081776896 }, { -4.71656215204, 54.2185876346 }, { -4.71759940991, 54.2322672444 }, { -4.73514361565, 54.2446507516 }, { -4.69488449392, 54.2771110727 }, { -4.65558887927, 54.2914459801 }, { -4.65220617099, 54.3116519242 }, { -4.63949760848, 54.3400051903 }, { -4.58879948143, 54.3629767901 }, { -4.57315512904, 54.3829958979 }, { -4.54023908795, 54.387968746 }, { -4.51678123729, 54.4207829193 }, { -4.50855200379, 54.405875113 }, { -4.49210295036, 54.4153472858 } };
        // CHECKSTYLE:ON
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
        Coordinate[] coords = new Coordinate[rawLocations.length];
        int index = 0;
        for (double[] point : rawLocations) {
            Coordinate c = new Coordinate(point[0], point[1]);
            coords[index] = c;
            index++;
        }
        LinearRing ring = geometryFactory.createLinearRing(coords);
        // use LinearRing[] to represent holes
        LinearRing[] holes = null;
        polygon = geometryFactory.createPolygon(ring, holes);
    }
    return polygon;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 69 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project sldeditor by robward-scisys.

the class ExamplePolygonImplIOM method getPolygon.

/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.datasource.impl.ExamplePolygonInterface#getPolygon()
     */
@Override
public Polygon getPolygon() {
    if (polygon == null) {
        // CHECKSTYLE:OFF
        double[][] rawLocations = new double[][] { { -4.652710, 54.069059 }, { -4.634857, 54.075506 }, { -4.629364, 54.059388 }, { -4.600525, 54.087590 }, { -4.574432, 54.102892 }, { -4.548340, 54.103697 }, { -4.522247, 54.124626 }, { -4.476929, 54.143132 }, { -4.470062, 54.162434 }, { -4.428864, 54.169670 }, { -4.383545, 54.194583 }, { -4.398651, 54.209846 }, { -4.397278, 54.223496 }, { -4.373932, 54.229919 }, { -4.364319, 54.249180 }, { -4.301147, 54.303704 }, { -4.372559, 54.315722 }, { -4.380798, 54.344550 }, { -4.365692, 54.389354 }, { -4.364319, 54.420528 }, { -4.459076, 54.402946 }, { -4.534607, 54.373359 }, { -4.578552, 54.322931 }, { -4.601898, 54.285270 }, { -4.636230, 54.258807 }, { -4.671936, 54.237143 }, { -4.703522, 54.229919 }, { -4.728241, 54.187352 }, { -4.743347, 54.173689 }, { -4.735107, 54.143132 }, { -4.755707, 54.110138 }, { -4.783173, 54.101281 }, { -4.777679, 54.086784 }, { -4.822998, 54.049714 }, { -4.737854, 54.066642 }, { -4.709015, 54.082757 }, { -4.682922, 54.062612 }, { -4.652710, 54.069059 } };
        // CHECKSTYLE:ON
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
        Coordinate[] coords = new Coordinate[rawLocations.length];
        int index = 0;
        for (double[] point : rawLocations) {
            Coordinate c = new Coordinate(point[0], point[1]);
            coords[index] = c;
            index++;
        }
        LinearRing ring = geometryFactory.createLinearRing(coords);
        // use LinearRing[] to represent holes
        LinearRing[] holes = null;
        polygon = geometryFactory.createPolygon(ring, holes);
    }
    return polygon;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) 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