Search in sources :

Example 51 with Coordinate

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

the class CurveHelper method combineCurve.

/**
 * Combine the given {@link LineString}s using the given builder.
 *
 * @param lineStrings the line strings
 * @param strict if it should be checked if the geometry fulfills the strict
 *            requirements of a curve
 * @param builder the builder function creating a combination of the
 *            individual {@link LineString}s
 * @return the combined {@link MultiLineString} or <code>null</code> if the
 *         geometry did not meet the requirements of the strict mode
 */
@Nullable
public static <T> T combineCurve(List<? extends LineString> lineStrings, boolean strict, Function<List<LineString>, T> builder) {
    // try to order by start/end point (e.g. for composite curves)
    Map<Coordinate, LineString> endPoints = new HashMap<>();
    for (LineString element : lineStrings) {
        endPoints.put(element.getEndPoint().getCoordinate(), element);
    }
    Map<LineString, Set<LineString>> dependencies = new HashMap<>();
    for (LineString element : lineStrings) {
        // check if there is another line that ends at this line's start
        // and build the dependency map accordingly
        LineString dependsOn = endPoints.get(element.getStartPoint().getCoordinate());
        @SuppressWarnings("unchecked") Set<LineString> deps = (Set<LineString>) ((dependsOn == null) ? Collections.emptySet() : Collections.singleton(dependsOn));
        dependencies.put(element, deps);
    }
    // use dependency ordered list to achieve sorting
    // will only yield a perfect result if all lines can be combined into
    // one
    DependencyOrderedList<LineString> ordered = new DependencyOrderedList<>(dependencies);
    if (strict) {
        Coordinate lastEndPoint = null;
        for (LineString lineString : ordered.getInternalList()) {
            if (lastEndPoint != null) {
                // start point must be equal to last end point
                if (!lineString.getStartPoint().getCoordinate().equals(lastEndPoint)) {
                    // not a strict curve
                    return null;
                }
            }
            lastEndPoint = lineString.getEndPoint().getCoordinate();
        }
    } else {
    // "best effort"
    }
    return builder.apply(ordered.getInternalList());
}
Also used : Set(java.util.Set) Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) HashMap(java.util.HashMap) DependencyOrderedList(eu.esdihumboldt.util.DependencyOrderedList) Nullable(javax.annotation.Nullable)

Example 52 with Coordinate

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

the class ArcByCenterPointImplTest method testCircle1.

@Test
public void testCircle1() throws IOException {
    ArcByCenterPoint arc = new ArcByCenterPointImpl(new Coordinate(0, 0), 1.0, Angle.fromDegrees(0), Angle.fromDegrees(0), false);
    drawArcWithMarkers(arc);
    assertEquals(360.0, arc.getAngleBetween().getDegrees(), 1e-10);
    assertTrue(arc.isCircle());
    assertFalse(InterpolationUtil.isStraightLine(arc));
    ArcByPoints converted = arc.toArcByPoints();
    assertEqualsCoord(new Coordinate(1, 0), converted.getStartPoint());
    assertEqualsCoord(new Coordinate(-1, 0), converted.getMiddlePoint());
    assertEqualsCoord(new Coordinate(1, 0), converted.getEndPoint());
}
Also used : ArcByPoints(eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint) Coordinate(org.locationtech.jts.geom.Coordinate) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Example 53 with Coordinate

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

the class SplitInterpolationTest method testLarge.

@Test
public void testLarge() throws IOException {
    ArcByCenterPoint arc = new ArcByCenterPointImpl(new Coordinate(0, 0), 50.0, Angle.fromDegrees(45), Angle.fromDegrees(135), true);
    splitInterpolationTest(arc, 0.1);
}
Also used : ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint) Coordinate(org.locationtech.jts.geom.Coordinate) ArcByCenterPointImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Example 54 with Coordinate

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

the class SplitInterpolationTest method testByPoints2.

@Test
public void testByPoints2() throws IOException {
    Arc arc = new ArcByPointsImpl(new Coordinate(0, 4), new Coordinate(2, 3), new Coordinate(4, 4));
    splitInterpolationTest(arc, 0.1);
}
Also used : ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) Coordinate(org.locationtech.jts.geom.Coordinate) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Example 55 with Coordinate

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

the class SplitInterpolationTest method testHalfCircle.

@Test
public void testHalfCircle() throws IOException {
    ArcByCenterPoint arc = new ArcByCenterPointImpl(new Coordinate(0, 0), 1.0, Angle.fromDegrees(0), Angle.fromDegrees(180), true);
    splitInterpolationTest(arc, 0.1);
}
Also used : ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint) Coordinate(org.locationtech.jts.geom.Coordinate) ArcByCenterPointImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)348 Test (org.junit.Test)145 Geometry (org.locationtech.jts.geom.Geometry)69 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)65 LineString (org.locationtech.jts.geom.LineString)57 Point (org.locationtech.jts.geom.Point)57 Polygon (org.locationtech.jts.geom.Polygon)47 LinearRing (org.locationtech.jts.geom.LinearRing)45 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)37 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)32 ArrayList (java.util.ArrayList)32 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)27 Test (org.junit.jupiter.api.Test)26 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)20 MultiPoint (org.locationtech.jts.geom.MultiPoint)20 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)17 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)16 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)15 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)14 HashMap (java.util.HashMap)13