Search in sources :

Example 21 with Coordinate

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

the class DimensionInfoTest method testFind_List_Geometry.

/**
 * Test of find method, of class DimensionInfo.
 */
@Test
public void testFind_List_Geometry() {
    List<Coordinate> coordinates = Arrays.asList(new CoordinateXY(1.0, 2.0), new CoordinateXY(10.0, 20.0));
    GeometryFactory factory = new GeometryFactory();
    Geometry geometry = factory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
    DimensionInfo expResult = DimensionInfo.XY_LINESTRING;
    DimensionInfo result = DimensionInfo.find(coordinates, geometry);
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateXY(org.locationtech.jts.geom.CoordinateXY) Test(org.junit.Test)

Example 22 with Coordinate

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

the class DimensionInfoTest method testFindCollection.

/**
 * Test of findCollection method, of class DimensionInfo.
 */
@Test
public void testFindCollection() {
    GeometryFactory factory = new GeometryFactory();
    List<Point> points = Arrays.asList(factory.createPoint(new Coordinate(1.0, 2.0)), factory.createPoint(new Coordinate(10.0, 20.0)));
    Geometry geometry = factory.createMultiPoint(points.toArray(new Point[points.size()]));
    DimensionInfo expResult = DimensionInfo.XY_POINT;
    DimensionInfo result = DimensionInfo.findCollection(points, geometry);
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 23 with Coordinate

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

the class GeometryWrapper method distanceGreatCircle.

/**
 * Distance (Great Circle) in the Units of Measure stated in URI.
 *
 * @param targetGeometry
 * @param targetDistanceUnitsURI
 * @return Distance
 * @throws org.opengis.util.FactoryException
 * @throws org.opengis.referencing.operation.TransformException
 */
public double distanceGreatCircle(GeometryWrapper targetGeometry, String targetDistanceUnitsURI) throws FactoryException, MismatchedDimensionException, TransformException {
    GeometryWrapper transformedSourceGeometry;
    if (srsInfo.isGeographic()) {
        // Already a geographic SRS.
        transformedSourceGeometry = this;
    } else {
        // Use WGS84 and not CRS84 as assuming WGS8 is more prevalent.
        transformedSourceGeometry = this.transform(SRS_URI.WGS84_CRS);
    }
    GeometryWrapper transformedTargetGeometry = transformedSourceGeometry.checkTransformSRS(targetGeometry);
    // Find the nearest pair of coordinates from each Geometry using Euclidean distance (adjusting for wrap around).
    // These are then used for Great Circle distance.
    CoordinatePair coordinatePair = CoordinatePair.findNearestPair(transformedSourceGeometry, transformedTargetGeometry);
    // Check whether the nearest pair are the same, i.e. the overlap or within each other.
    if (coordinatePair.isEqual()) {
        // Exit early as the distance is zero.
        return 0.0;
    }
    Coordinate coord1 = coordinatePair.getCoord1();
    Coordinate coord2 = coordinatePair.getCoord2();
    double distance = GreatCircleDistance.haversineFormula(coord1.getY(), coord1.getX(), coord2.getY(), coord2.getX());
    // Convert the Great Circle distance from metres into the requested units.
    Boolean isTargetUnitsLinear = UnitsRegistry.isLinearUnits(targetDistanceUnitsURI);
    double targetDistance;
    if (isTargetUnitsLinear) {
        // Target units are linear so straight conversion. Distance is in metres already.
        targetDistance = UnitsOfMeasure.conversion(distance, Unit_URI.METRE_URL, targetDistanceUnitsURI);
    } else {
        targetDistance = UnitsOfMeasure.convertBetween(distance, Unit_URI.METRE_URL, targetDistanceUnitsURI, isTargetUnitsLinear, transformedSourceGeometry.getLatitude());
    }
    return targetDistance;
}
Also used : CoordinatePair(org.apache.jena.geosparql.implementation.great_circle.CoordinatePair) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 24 with Coordinate

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

the class GeometryReverse method reverseGeometry.

/**
 * Reverses coordinate order of the supplied geometry and produces a new
 * geometry.
 *
 * @param geometry
 * @return Geometry in x,y coordinate order.
 */
public static Geometry reverseGeometry(Geometry geometry) {
    if (geometry.isEmpty()) {
        return geometry.copy();
    }
    GeometryFactory factory = geometry.getFactory();
    Geometry finalGeometry;
    Coordinate[] coordinates;
    String type = geometry.getGeometryType();
    switch(type) {
        case "LineString":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createLineString(coordinates);
            break;
        case "LinearRing":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createLinearRing(coordinates);
            break;
        case "MultiPoint":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createMultiPointFromCoords(coordinates);
            break;
        case "Polygon":
            finalGeometry = reversePolygon(geometry, factory);
            break;
        case "Point":
            coordinates = getReversedCoordinates(geometry);
            finalGeometry = factory.createPoint(coordinates[0]);
            break;
        case "MultiPolygon":
            Polygon[] polygons = unpackPolygons((GeometryCollection) geometry);
            finalGeometry = factory.createMultiPolygon(polygons);
            break;
        case "MultiLineString":
            LineString[] lineString = unpackLineStrings((GeometryCollection) geometry);
            finalGeometry = factory.createMultiLineString(lineString);
            break;
        case "GeometryCollection":
            Geometry[] geometries = unpackGeometryCollection((GeometryCollection) geometry);
            finalGeometry = factory.createGeometryCollection(geometries);
            break;
        default:
            finalGeometry = geometry;
            break;
    }
    return finalGeometry;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon)

Example 25 with Coordinate

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

the class GeometryReverse method getReversedCoordinates.

private static Coordinate[] getReversedCoordinates(Geometry geometry) {
    Coordinate[] original = geometry.getCoordinates();
    Coordinate[] reversed = new Coordinate[original.length];
    for (int i = 0; i < original.length; i++) {
        reversed[i] = new Coordinate(original[i].y, original[i].x);
    }
    return reversed;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)330 Test (org.junit.Test)135 Geometry (org.locationtech.jts.geom.Geometry)64 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)62 LineString (org.locationtech.jts.geom.LineString)54 Point (org.locationtech.jts.geom.Point)51 Polygon (org.locationtech.jts.geom.Polygon)44 LinearRing (org.locationtech.jts.geom.LinearRing)42 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)37 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)32 ArrayList (java.util.ArrayList)31 Test (org.junit.jupiter.api.Test)26 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)25 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)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 MultiPoint (org.locationtech.jts.geom.MultiPoint)15 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)14 HashMap (java.util.HashMap)13