Search in sources :

Example 71 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class InterpolationAlgorithm method interpolateArcString.

/**
 * Interpolate an arc string.
 *
 * @param arcs the arc string to interpolate
 * @return the interpolated geometry
 */
default LineString interpolateArcString(ArcString arcs) {
    List<Coordinate> coords = new ArrayList<>();
    List<Arc> arcList = new ArrayList<>(arcs.getArcs());
    for (int i = 0; i < arcList.size(); i++) {
        Arc arc = arcList.get(i);
        LineString interpolated = interpolateArc(arc);
        Coordinate[] lineCoords = interpolated.getCoordinates();
        int startIndex = 1;
        if (i == 0) {
            startIndex = 0;
        }
        for (int j = startIndex; j < lineCoords.length; j++) {
            Coordinate coord = lineCoords[j];
            coords.add(coord);
        }
    }
    return new InterpolatedLineString(getGeometryFactory().getCoordinateSequenceFactory().create(coords.toArray(new Coordinate[coords.size()])), getGeometryFactory(), arcs);
}
Also used : Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) ArrayList(java.util.ArrayList)

Example 72 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class StreamGmlWriterTest method testGeometry_2_LineString.

/**
 * Test writing a {@link LineString} to a GML 2 geometry type
 *
 * @throws Exception if an error occurs
 */
@Ignore
// GML 2 stuff currently not working (because of unrelated schemas)
@Test
public void testGeometry_2_LineString() throws Exception {
    // create the geometry
    LineString lineString = createLineString(0.0);
    Map<List<QName>, Object> values = new HashMap<List<QName>, Object>();
    // $NON-NLS-1$
    values.put(GEOMETRY_PROPERTY, lineString);
    IOReport report = fillFeatureTest(// $NON-NLS-1$
    "Test", // $NON-NLS-1$
    getClass().getResource("/data/geom_schema/geom-gml2.xsd").toURI(), values, "geometry_2_LineString", // $NON-NLS-1$
    DEF_SRS_NAME);
    // $NON-NLS-1$
    assertTrue("Expected GML output to be valid", report.isSuccess());
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) List(java.util.List) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 73 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class StreamGmlWriterTest method testGeometryAggregate_32_LineString.

/**
 * Test writing a {@link LineString} to a GML 3.2 geometry aggregate type
 *
 * @throws Exception if an error occurs
 */
@Test
public void testGeometryAggregate_32_LineString() throws Exception {
    // create the geometry
    LineString lineString = createLineString(0.0);
    Map<List<QName>, Object> values = new HashMap<List<QName>, Object>();
    // $NON-NLS-1$
    values.put(GEOMETRY_PROPERTY, lineString);
    IOReport report = fillFeatureTest(// $NON-NLS-1$
    "AggregateTest", // $NON-NLS-1$
    getClass().getResource("/data/geom_schema/geom-gml32.xsd").toURI(), // $NON-NLS-1$
    values, // $NON-NLS-1$
    "geometryAggregate_32_LineString", // $NON-NLS-1$
    DEF_SRS_NAME, true, false);
    // $NON-NLS-1$
    assertTrue("Expected GML output to be valid", report.isSuccess());
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) List(java.util.List) Test(org.junit.Test)

Example 74 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class PolygonToLineStringTest method testBox.

/**
 * Test conversion with a simple box
 */
@Test
public void testBox() {
    Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = coordinates[4] = new Coordinate(0, 0);
    coordinates[1] = new Coordinate(1, 0);
    coordinates[2] = new Coordinate(1, 1);
    coordinates[3] = new Coordinate(0, 1);
    LinearRing shell = geomFactory.createLinearRing(coordinates);
    Polygon poly = geomFactory.createPolygon(shell, null);
    PolygonToLineString converter = new PolygonToLineString();
    LineString mls = converter.convert(poly);
    // $NON-NLS-1$
    assertEquals("Expecting 1 lines", 1, mls.getNumGeometries());
    // $NON-NLS-1$
    assertEquals("Should have 5 points", 5, mls.getNumPoints());
    // first point
    assertEquals(coordinates[0], mls.getCoordinateN(0));
    // second point
    assertEquals(coordinates[0], mls.getCoordinateN(4));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Example 75 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class LinearRingHandler method createGeometry.

/**
 * Create a {@link LinearRing} geometry from the given instance.
 *
 * @param instance the instance
 * @param srsDimension the SRS dimension
 * @param allowTryOtherDimension if trying another dimension is allowed on
 *            failure (e.g. 3D instead of 2D)
 * @param reader the I/O Provider to get value
 * @return the {@link LinearRing} geometry
 * @throws GeometryNotSupportedException if the type definition doesn't
 *             represent a geometry type supported by the handler
 */
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing ring = null;
    LineStringHandler handler = new LineStringHandler();
    // for use with GML 2, 3, 3.1, 3.2
    @SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> linestring = (DefaultGeometryProperty<LineString>) handler.createGeometry(instance, srsDimension, reader);
    try {
        ring = getGeometryFactory().createLinearRing(linestring.getGeometry().getCoordinates());
    } catch (IllegalArgumentException e) {
        if (allowTryOtherDimension) {
            // the error
            // "Points of LinearRing do not form a closed linestring"
            // can be an expression of a wrong dimension being used
            // we try an alternative, to be sure (e.g. 3D instead of 2D)
            int alternativeDimension = (srsDimension == 2) ? (3) : (2);
            GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
            log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
            return geom;
        }
        throw e;
    }
    if (ring != null) {
        CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
        return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LineString(org.locationtech.jts.geom.LineString) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) LinearRing(org.locationtech.jts.geom.LinearRing)

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