Search in sources :

Example 26 with Coordinate

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

the class DimensionInfo method findCollection.

public static DimensionInfo findCollection(List<? extends Geometry> geometries, Geometry geometry) {
    Coordinate coordinate;
    if (geometries.isEmpty()) {
        coordinate = XY_COORDINATE;
    } else {
        Geometry geom = geometries.get(0);
        coordinate = geom.getCoordinate();
    }
    return find(coordinate, geometry);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 27 with Coordinate

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

the class CoordinatePair method findNearestPair.

public static final CoordinatePair findNearestPair(GeometryWrapper sourceGeometry, GeometryWrapper targetGeometry) throws SrsException {
    // Both GeoemtryWrappers should be same SRS andn Geographic.
    SRSInfo sourceSRSInfo = sourceGeometry.getSrsInfo();
    SRSInfo targetSRSInfo = targetGeometry.getSrsInfo();
    if (!(sourceSRSInfo.isGeographic() && targetSRSInfo.isGeographic()) || !(sourceSRSInfo.getSrsURI().equals(targetSRSInfo.getSrsURI()))) {
        throw new SrsException("Expected same Geographic SRS for GeometryWrappers. " + sourceGeometry + " : " + targetGeometry);
    }
    // Find nearest points.
    Point point1 = null;
    Point point2 = null;
    Geometry sourceXYGeometry = sourceGeometry.getXYGeometry();
    Geometry targetXYGeometry = targetGeometry.getXYGeometry();
    // Check whether only dealing with Point geometries.
    if (sourceXYGeometry instanceof Point) {
        point1 = (Point) sourceXYGeometry;
    }
    if (targetXYGeometry instanceof Point) {
        point2 = (Point) targetXYGeometry;
    }
    // Exit if both are points.
    if (point1 != null && point2 != null) {
        return new CoordinatePair(point1.getCoordinate(), point2.getCoordinate());
    }
    // Both same SRS so same domain range.
    Envelope sourceEnvelope = sourceGeometry.getEnvelope();
    Envelope targetEnvelope = targetGeometry.getEnvelope();
    double domainRange = sourceSRSInfo.getDomainRangeX();
    double halfRange = domainRange / 2;
    double diff = targetEnvelope.getMaxX() - sourceEnvelope.getMinX();
    Geometry adjustedSource;
    Geometry adjustedTarget;
    if (diff > halfRange) {
        // Difference is greater than positive half range, then translate source by the range.
        adjustedSource = sourceGeometry.translateXYGeometry();
        adjustedTarget = targetXYGeometry;
    } else if (diff < -halfRange) {
        // Difference is less than negative half range, then translate target by the range.
        adjustedSource = sourceXYGeometry;
        adjustedTarget = targetGeometry.translateXYGeometry();
    } else {
        // Difference is between the ranges so don't translate.
        adjustedSource = sourceXYGeometry;
        adjustedTarget = targetXYGeometry;
    }
    DistanceOp distanceOp = new DistanceOp(adjustedSource, adjustedTarget);
    Coordinate[] nearest = distanceOp.nearestPoints();
    return new CoordinatePair(nearest[0], nearest[1]);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) SrsException(org.apache.jena.geosparql.configuration.SrsException) SRSInfo(org.apache.jena.geosparql.implementation.SRSInfo) Coordinate(org.locationtech.jts.geom.Coordinate) DistanceOp(org.locationtech.jts.operation.distance.DistanceOp) Point(org.locationtech.jts.geom.Point) Envelope(org.locationtech.jts.geom.Envelope)

Example 28 with Coordinate

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

the class GeometryTransformation method transformCoordSeq.

private static CoordinateSequence transformCoordSeq(CoordinateSequence coordSeq, MathTransform transform) throws TransformException {
    int size = coordSeq.size();
    int sourceDims = transform.getSourceDimensions();
    int targetDims = transform.getTargetDimensions();
    double[] sourcePts = new double[size * sourceDims];
    double[] targetPts = new double[size * targetDims];
    // Setup source array for transform.
    boolean isZSource = sourceDims > 2;
    for (int i = 0; i < size; i++) {
        Coordinate coord = coordSeq.getCoordinate(i);
        int j = i * targetDims;
        sourcePts[j] = coord.getX();
        sourcePts[j + 1] = coord.getY();
        if (isZSource) {
            sourcePts[j + 2] = coord.getZ();
        }
    }
    // Transform the ordinates.
    transform.transform(sourcePts, 0, targetPts, 0, size);
    // Extract into coordiante sequence.
    double[] x = new double[size];
    double[] y = new double[size];
    double[] z = new double[size];
    double[] m = new double[size];
    boolean isZTransformed = sourceDims > 2 && targetDims > 2;
    for (int i = 0; i < size; i++) {
        Coordinate coord = coordSeq.getCoordinate(i);
        int j = i * targetDims;
        x[i] = cleanUpPrecision(targetPts[j]);
        y[i] = cleanUpPrecision(targetPts[j + 1]);
        if (isZTransformed) {
            z[i] = cleanUpPrecision(targetPts[j + 2]);
        } else {
            if (coordSeq.hasZ()) {
                z[i] = cleanUpPrecision(coord.getZ());
            } else {
                z[i] = Double.NaN;
            }
        }
        if (coordSeq.hasM()) {
            m[i] = coord.getM();
        } else {
            m[i] = Double.NaN;
        }
    }
    return new CustomCoordinateSequence(x, y, z, m);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 29 with Coordinate

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

the class GMLReaderTest method testFindCentre.

/**
 * Test of findCentre method, of class GMLReader.
 */
@Test
public void testFindCentre() {
    List<Coordinate> coordinates = Arrays.asList(new Coordinate(-3, 4), new Coordinate(4, 5), new Coordinate(1, -4));
    Coordinate expResult = new Coordinate(1, 1);
    Coordinate result = GMLReader.findCentre(coordinates);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Test(org.junit.Test)

Example 30 with Coordinate

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

the class GMLReaderTest method testExtractCircleByCentrePoint.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractCircleByCentrePoint() throws JDOMException, IOException {
    GeometricShapeFactory shapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    shapeFactory.setCentre(new Coordinate(0, 0));
    shapeFactory.setSize(10);
    Geometry circle = shapeFactory.createCircle().getExteriorRing();
    GMLReader expResult = new GMLReader(circle, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:Curve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:segments><gml:CircleByCenterPoint ><gml:pos>0 0</gml:pos><gml:radius uom=\"http://www.opengis.net/def/uom/OGC/1.0/metre\">5.0</gml:radius></gml:CircleByCenterPoint></gml:segments></gml:Curve>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

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