Search in sources :

Example 21 with Polygon

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

the class WKTWriter method expand.

private static String expand(final Geometry geometry, final CoordinateSequenceDimensions dimensions) {
    String wktString = "";
    String dimensionString = CoordinateSequenceDimensions.convertDimensions(dimensions);
    switch(geometry.getGeometryType()) {
        case "Point":
            Point point = (Point) geometry;
            wktString = buildWKT("POINT", point.getCoordinateSequence(), dimensionString);
            break;
        case "LineString":
        case "LinearRing":
            LineString lineString = (LineString) geometry;
            wktString = buildWKT("LINESTRING", lineString.getCoordinateSequence(), dimensionString);
            break;
        case "Polygon":
            Polygon polygon = (Polygon) geometry;
            wktString = buildPolygon(polygon, true, dimensionString);
            break;
        case "MultiPoint":
            MultiPoint multiPoint = (MultiPoint) geometry;
            wktString = buildMultiPoint(multiPoint, dimensionString);
            break;
        case "MultiLineString":
            MultiLineString multiLineString = (MultiLineString) geometry;
            wktString = buildMultiLineString(multiLineString, dimensionString);
            break;
        case "MultiPolygon":
            MultiPolygon multiPolygon = (MultiPolygon) geometry;
            wktString = buildMultiPolygon(multiPolygon, dimensionString);
            break;
        case "GeometryCollection":
            GeometryCollection geometryCollection = (GeometryCollection) geometry;
            wktString = buildGeometryCollection(geometryCollection, dimensions);
            break;
    }
    return wktString;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 22 with Polygon

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

the class WKTWriter method buildMultiPolygon.

private static String buildMultiPolygon(final MultiPolygon multiPolygon, final String dimensionString) {
    StringBuilder sb = new StringBuilder("MULTIPOLYGON");
    if (!multiPolygon.isEmpty()) {
        sb.append(dimensionString);
        sb.append("(");
        // Find first polygon
        Polygon polygon = (Polygon) multiPolygon.getGeometryN(0);
        sb.append(buildPolygon(polygon, false, dimensionString));
        // Encode remaining points
        int geomCount = multiPolygon.getNumGeometries();
        for (int i = 1; i < geomCount; i++) {
            sb.append(", ");
            polygon = (Polygon) multiPolygon.getGeometryN(i);
            sb.append(buildPolygon(polygon, false, dimensionString));
        }
        sb.append(")");
    } else {
        sb.append(" EMPTY");
    }
    return sb.toString();
}
Also used : Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 23 with Polygon

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

the class GMLWriterTest method testWriteMultiSurface2.

@Test
public void testWriteMultiSurface2() {
    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);
    GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, GML_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0));
    String result = GMLWriter.write(geometryWrapper);
    String expResult = "<gml:MultiSurface xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:surfaceMember><gml:Polygon srsName=\"urn:ogc:def:crs:EPSG::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=\"urn:ogc:def:crs:EPSG::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>";
    assertEquals(expResult.trim(), result.trim());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) DimensionInfo(org.apache.jena.geosparql.implementation.DimensionInfo) 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)

Example 24 with Polygon

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

the class WKTWriterTest method testWriteMultiPolygon.

/**
 * Test of extract method, of class WKTWriter.
 */
@Test
public void testWriteMultiPolygon() {
    Polygon[] polygons = new Polygon[2];
    polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 20 45, 45 30, 40 40"));
    polygons[1] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 35, 10 30, 10 10, 30 5, 45 20, 20 35"));
    Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
    GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(2, 2, 2));
    String expResult = "<" + SRS_URI.WGS84_CRS + "> MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35)))";
    String result = WKTWriter.write(geometryWrapper);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) DimensionInfo(org.apache.jena.geosparql.implementation.DimensionInfo) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 25 with Polygon

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

the class GeoJSONTest method randomPolygon.

private Polygon randomPolygon(int srid) {
    Polygon geometry = geometryFactory.createPolygon(randomLinearRing(srid), new LinearRing[] { randomLinearRing(srid), randomLinearRing(srid), randomLinearRing(srid) });
    geometry.setSRID(srid);
    return geometry;
}
Also used : Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Aggregations

Polygon (org.locationtech.jts.geom.Polygon)56 LineString (org.locationtech.jts.geom.LineString)23 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)22 Point (org.locationtech.jts.geom.Point)22 Geometry (org.locationtech.jts.geom.Geometry)20 Coordinate (org.locationtech.jts.geom.Coordinate)16 MultiPoint (org.locationtech.jts.geom.MultiPoint)15 Test (org.junit.Test)13 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)11 LinearRing (org.locationtech.jts.geom.LinearRing)10 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)8 MultiLineString (org.locationtech.jts.geom.MultiLineString)8 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)5 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)5 WKTReader (org.locationtech.jts.io.WKTReader)5 AreaIndex (com.graphhopper.routing.util.AreaIndex)4 CustomArea (com.graphhopper.routing.util.CustomArea)3 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)3