Search in sources :

Example 91 with LineString

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

the class GMLWriterTest method testWriteMultiCurve.

@Test
public void testWriteMultiCurve() {
    LineString[] lineStrings = new LineString[2];
    lineStrings[0] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "10 10, 20 20, 10 40"));
    lineStrings[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 30 30, 40 20, 30 10"));
    Geometry geometry = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
    GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, GML_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0));
    String result = GMLWriter.write(geometryWrapper);
    String expResult = "<gml:MultiCurve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:curveMember><gml:LineString srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:posList>10 10 20 20 10 40</gml:posList></gml:LineString></gml:curveMember><gml:curveMember><gml:LineString srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:posList>40 40 30 30 40 20 30 10</gml:posList></gml:LineString></gml:curveMember></gml:MultiCurve>";
    assertEquals(expResult.trim(), result.trim());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) DimensionInfo(org.apache.jena.geosparql.implementation.DimensionInfo) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 92 with LineString

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

the class WKTWriterTest method testWriteLineString.

/**
 * Test of write method, of class WKTWriter.
 */
@Test
public void testWriteLineString() {
    Geometry geometry = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "11.0 12.1, 3 4"));
    GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(2, 2, 1));
    String expResult = "<" + SRS_URI.WGS84_CRS + "> LINESTRING(11 12.1, 3 4)";
    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) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 93 with LineString

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

the class WKTWriter method buildPolygon.

private static String buildPolygon(final Polygon polygon, final boolean isIncludeGeometryType, final String dimensionString) {
    StringBuilder sb = new StringBuilder();
    if (isIncludeGeometryType) {
        sb.append("POLYGON");
    }
    if (!polygon.isEmpty()) {
        if (isIncludeGeometryType) {
            sb.append(dimensionString);
        }
        sb.append("(");
        // Find exterior shell
        LineString lineString = polygon.getExteriorRing();
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
        sb.append(convertToWKTText(coordSequence));
        // Find inner holes
        int interiorRings = polygon.getNumInteriorRing();
        for (int i = 0; i < interiorRings; i++) {
            sb.append(", ");
            LineString innerLineString = polygon.getInteriorRingN(i);
            CustomCoordinateSequence innerCoordSequence = (CustomCoordinateSequence) innerLineString.getCoordinateSequence();
            sb.append(convertToWKTText(innerCoordSequence));
        }
        sb.append(")");
    } else {
        sb.append(" EMPTY");
    }
    return sb.toString();
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 94 with LineString

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

the class WKTWriter method buildMultiLineString.

private static String buildMultiLineString(final MultiLineString multiLineString, final String dimensionString) {
    StringBuilder sb = new StringBuilder("MULTILINESTRING");
    if (!multiLineString.isEmpty()) {
        sb.append(dimensionString);
        sb.append("(");
        // Find first linestring
        LineString lineString = (LineString) multiLineString.getGeometryN(0);
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
        sb.append(buildWKT("", coordSequence));
        // Encode remaining points
        int geomCount = multiLineString.getNumGeometries();
        for (int i = 1; i < geomCount; i++) {
            sb.append(", ");
            lineString = (LineString) multiLineString.getGeometryN(i);
            coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
            sb.append(buildWKT("", coordSequence));
        }
        sb.append(")");
    } else {
        sb.append(" EMPTY");
    }
    return sb.toString();
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 95 with LineString

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

the class GeometryReverseTest method testCheckLineStringNotReversed.

/**
 * Test of check method, of class GeometryReverse.
 */
@Test
public void testCheckLineStringNotReversed() {
    WKTReader reader = new WKTReader();
    try {
        LineString geometry = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");
        String srsURI = SRS_URI.DEFAULT_WKT_CRS84;
        Geometry expResult = reader.read("LINESTRING(0 0, 2 0, 5 0)");
        Geometry result = GeometryReverse.check(geometry, srsURI);
        // 
        // 
        assertEquals(expResult, result);
    } catch (ParseException ex) {
        System.err.println("ParseException: " + ex.getMessage());
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader) Test(org.junit.Test)

Aggregations

LineString (org.locationtech.jts.geom.LineString)120 MultiLineString (org.locationtech.jts.geom.MultiLineString)48 Coordinate (org.locationtech.jts.geom.Coordinate)38 Geometry (org.locationtech.jts.geom.Geometry)35 Point (org.locationtech.jts.geom.Point)32 Test (org.junit.Test)24 Polygon (org.locationtech.jts.geom.Polygon)21 MultiPoint (org.locationtech.jts.geom.MultiPoint)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)14 WKTReader (org.locationtech.jts.io.WKTReader)13 ArrayList (java.util.ArrayList)12 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)12 HashMap (java.util.HashMap)10 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)9 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)9 ParseException (org.locationtech.jts.io.ParseException)9 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)7 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6