Search in sources :

Example 41 with LineString

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

the class GeometryTransformation method transformMultiLineString.

private static MultiLineString transformMultiLineString(Geometry sourceGeometry, MathTransform transform) throws TransformException {
    GeometryFactory geometryFactory = sourceGeometry.getFactory();
    MultiLineString multiLineString = (MultiLineString) sourceGeometry;
    int geometryNumber = multiLineString.getNumGeometries();
    ArrayList<LineString> lineStrings = new ArrayList<>();
    for (int i = 0; i < geometryNumber; i++) {
        LineString lineString = transformLineString(multiLineString.getGeometryN(i), transform);
        lineStrings.add(lineString);
    }
    return geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) ArrayList(java.util.ArrayList) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 42 with LineString

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

the class GeometryTransformation method transformLineString.

private static LineString transformLineString(Geometry sourceGeometry, MathTransform transform) throws TransformException {
    GeometryFactory geometryFactory = sourceGeometry.getFactory();
    LineString lineString = (LineString) sourceGeometry;
    CoordinateSequence coordSeq = lineString.getCoordinateSequence();
    CoordinateSequence transformCoordSeq = transformCoordSeq(coordSeq, transform);
    return geometryFactory.createLineString(transformCoordSeq);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 43 with LineString

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

the class GMLReaderTest method testExtractMutliCurve.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractMutliCurve() throws JDOMException, IOException {
    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);
    GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:MultiCurve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:curveMember><gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:posList>10 10 20 20 10 40</gml:posList></gml:LineString></gml:curveMember><gml:curveMember><gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:posList>40 40 30 30 40 20 30 10</gml:posList></gml:LineString></gml:curveMember></gml:MultiCurve>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 44 with LineString

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

the class WKTWriterTest method testWriteGeometryCollection.

/**
 * Test of write method, of class WKTWriter.
 */
@Test
public void testWriteGeometryCollection() {
    Geometry[] geometries = new Geometry[2];
    geometries[0] = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "4 6 0 1"));
    geometries[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "4 6 0 1,7 10 0 1"));
    Geometry geometry = GEOMETRY_FACTORY.createGeometryCollection(geometries);
    GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(4, 3, 1));
    String expResult = "<" + SRS_URI.WGS84_CRS + "> GEOMETRYCOLLECTION ZM(POINT ZM(4 6 0 1), LINESTRING ZM(4 6 0 1, 7 10 0 1))";
    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 45 with LineString

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

the class WKTWriterTest method testWriteLineStringEmpty.

/**
 * Test of writeLineStringEmpty method, of class WKTWriter.
 */
@Test
public void testWriteLineStringEmpty() {
    Geometry geometry = GEOMETRY_FACTORY.createLineString();
    GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(2, 2, 1));
    String result = WKTWriter.write(geometryWrapper);
    String expResult = "LINESTRING EMPTY";
    // 
    // 
    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) 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