Search in sources :

Example 66 with LineString

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

the class CompositeCurveGeometryTest method testCompositeCurveGml32_mismatch.

/**
 * Test composite curve geometries read from a GML 3.2 file
 *
 * @throws Exception if an error occurs
 */
@Test
public void testCompositeCurveGml32_mismatch() throws Exception {
    InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/curve/sample-compositecurve-gml32_mismatch.xml").toURI());
    LineString ls1 = geomFactory.createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1), new Coordinate(2, 2) });
    LineString ls2 = geomFactory.createLineString(new Coordinate[] { new Coordinate(2, 3), new Coordinate(3, 1), new Coordinate(4, 0) });
    LineString ls3 = geomFactory.createLineString(new Coordinate[] { new Coordinate(4, 0), new Coordinate(5, -1), new Coordinate(6, 0), new Coordinate(7, 2), new Coordinate(8, 4) });
    MultiLineString separate = geomFactory.createMultiLineString(new LineString[] { ls1, ls2, ls3 });
    // one instances expected
    ResourceIterator<Instance> it = instances.iterator();
    try {
        // segments with LineStringSegment defined through coordinates
        assertTrue("First sample feature missing", it.hasNext());
        Instance instance = it.next();
        checkSingleGeometry(instance, referenceChecker(separate));
    } finally {
        it.close();
    }
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)

Example 67 with LineString

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

the class MultiLineStringGeometryTest method init.

@Override
public void init() {
    super.init();
    Coordinate[] coordinates = new Coordinate[] { new Coordinate(-39799.68820381, 273207.53980172), new Coordinate(-39841.185, 273182.863), new Coordinate(-39882.89, 273153.86) };
    LineString linestring1 = geomFactory.createLineString(coordinates);
    coordinates = new Coordinate[] { new Coordinate(-39799.8, 273207.7), new Coordinate(-39841.3, 273182.95), new Coordinate(-39882.99, 273153.99) };
    LineString linestring2 = geomFactory.createLineString(coordinates);
    LineString[] lines = new LineString[] { linestring1, linestring2 };
    reference = geomFactory.createMultiLineString(lines);
    checker = referenceChecker(reference);
    gridChecker = combine(referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 68 with LineString

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

the class GridInterpolationTest method gridInterpolationTest.

private LineString gridInterpolationTest(Arc arc, double maxPositionalError, boolean moveAllToGrid) throws IOException {
    GridInterpolation interpol = new GridInterpolation();
    Map<String, String> properties = new HashMap<>();
    if (moveAllToGrid) {
        properties.put(GridInterpolation.PARAMETER_MOVE_ALL_TO_GRID, "true");
    }
    interpol.configure(new GeometryFactory(), maxPositionalError, properties);
    LineString result = interpol.interpolateArc(arc);
    double gridSize = GridUtil.getGridSize(maxPositionalError);
    drawGridInterpolatedArc(arc, gridSize, result);
    // test interpolated geometry
    Coordinate[] coords = result.getCoordinates();
    for (int i = 0; i < coords.length; i++) {
        Coordinate c = coords[i];
        boolean checkGrid = moveAllToGrid || (!c.equals(arc.toArcByPoints().getStartPoint()) && !c.equals(arc.toArcByPoints().getMiddlePoint()) && !c.equals(arc.toArcByPoints().getEndPoint()));
        if (checkGrid) {
            // check if coordinate on grid
            GridUtilTest.checkOnGrid(c, gridSize);
        }
        // check if two coordinates are not the same
        if (i < coords.length - 1) {
            Coordinate c2 = coords[i + 1];
            assertNotEquals("Subsequent coordinates are equal", c, c2);
            if (checkGrid) {
                // better check is to compare difference in x and y based on
                // grid size
                boolean xDifferent = Math.abs(c2.x - c.x) > (gridSize / 2);
                boolean yDifferent = Math.abs(c2.y - c.y) > (gridSize / 2);
                assertTrue("Subsequent coordinates are equal", xDifferent || yDifferent);
            }
        }
        // check distance from center
        double distance = arc.toArcByCenterPoint().getCenterPoint().distance(c);
        double delta = Math.abs(distance - arc.toArcByCenterPoint().getRadius());
        assertTrue(delta <= maxPositionalError);
    }
    return result;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) HashMap(java.util.HashMap) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) LineString(org.locationtech.jts.geom.LineString) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)

Example 69 with LineString

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

the class SplitInterpolationTest method splitInterpolationTest.

private LineString splitInterpolationTest(Arc arc, double maxPositionalError) throws IOException {
    SplitInterpolation interpol = new SplitInterpolation();
    Map<String, String> properties = new HashMap<>();
    interpol.configure(new GeometryFactory(), maxPositionalError, properties);
    LineString result = interpol.interpolateArc(arc);
    drawInterpolatedArc(arc, result);
    // test interpolated geometry
    Coordinate[] coords = result.getCoordinates();
    if (coords.length > 1 && arc instanceof ArcByPoints) {
        // test start and end point
        assertEquals(arc.toArcByPoints().getStartPoint(), coords[0]);
        assertEquals(arc.toArcByPoints().getEndPoint(), coords[coords.length - 1]);
    }
    for (int i = 0; i < coords.length; i++) {
        Coordinate c = coords[i];
        // check if two coordinates are not the same
        if (i < coords.length - 1) {
            Coordinate c2 = coords[i + 1];
            assertNotEquals("Subsequent coordinates are equal", c, c2);
        }
        // check distance from center
        double distance = arc.toArcByCenterPoint().getCenterPoint().distance(c);
        double delta = Math.abs(distance - arc.toArcByCenterPoint().getRadius());
        assertTrue(delta <= maxPositionalError);
    }
    return result;
}
Also used : ArcByPoints(eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) HashMap(java.util.HashMap) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) LineString(org.locationtech.jts.geom.LineString) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)

Example 70 with LineString

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

the class SplitInterpolationTest method splitInterpolationTest.

// utility methods
private LineString splitInterpolationTest(ArcString arcs, double maxPositionalError) throws IOException {
    SplitInterpolation interpol = new SplitInterpolation();
    Map<String, String> properties = new HashMap<>();
    interpol.configure(new GeometryFactory(), maxPositionalError, properties);
    LineString result = interpol.interpolateArcString(arcs);
    drawInterpolatedArcString(arcs, result);
    // test interpolated geometry
    Coordinate[] coords = result.getCoordinates();
    for (int i = 0; i < coords.length; i++) {
        Coordinate c = coords[i];
        // check if two coordinates are not the same
        if (i < coords.length - 1) {
            Coordinate c2 = coords[i + 1];
            assertNotEquals(MessageFormat.format("Subsequent coordinates are equal ({0} and {1})", c, c2), c, c2);
        }
    }
    return result;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) HashMap(java.util.HashMap) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) LineString(org.locationtech.jts.geom.LineString) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)

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