Search in sources :

Example 1 with SRSInfo

use of org.apache.jena.geosparql.implementation.SRSInfo 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 2 with SRSInfo

use of org.apache.jena.geosparql.implementation.SRSInfo in project jena by apache.

the class WKTWriter method write.

public static final String write(GeometryWrapper geometryWrapper) {
    StringBuilder sb = new StringBuilder();
    SRSInfo srsInfo = geometryWrapper.getSrsInfo();
    if (!srsInfo.isWktDefault()) {
        sb.append("<").append(geometryWrapper.getSrsURI()).append("> ");
    }
    Geometry geometry = geometryWrapper.getParsingGeometry();
    CoordinateSequenceDimensions dimensions = geometryWrapper.getCoordinateSequenceDimensions();
    String wktText = expand(geometry, dimensions);
    sb.append(wktText);
    return sb.toString();
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) SRSInfo(org.apache.jena.geosparql.implementation.SRSInfo) CoordinateSequenceDimensions(org.apache.jena.geosparql.implementation.jts.CoordinateSequenceDimensions) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 3 with SRSInfo

use of org.apache.jena.geosparql.implementation.SRSInfo in project jena by apache.

the class SRSRegistry method setupDefaultSRS.

public static final void setupDefaultSRS() {
    // CRS_84
    SRSInfo srsInfo = SRSInfo.getDefaultWktCRS84(SRS_URI.DEFAULT_WKT_CRS84);
    SRS_REGISTRY.put(SRS_URI.DEFAULT_WKT_CRS84, srsInfo);
    // WGS_84 Legacy for CRS_84
    SRS_REGISTRY.put(SRS_URI.WGS84_CRS_GEOSPARQL_LEGACY, SRSInfo.getDefaultWktCRS84(SRS_URI.WGS84_CRS_GEOSPARQL_LEGACY));
    // Add the Units of Measure
    UnitsRegistry.addUnit(srsInfo.getUnitsOfMeasure());
}
Also used : SRSInfo(org.apache.jena.geosparql.implementation.SRSInfo)

Aggregations

SRSInfo (org.apache.jena.geosparql.implementation.SRSInfo)3 Geometry (org.locationtech.jts.geom.Geometry)2 SrsException (org.apache.jena.geosparql.configuration.SrsException)1 CoordinateSequenceDimensions (org.apache.jena.geosparql.implementation.jts.CoordinateSequenceDimensions)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Envelope (org.locationtech.jts.geom.Envelope)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 Point (org.locationtech.jts.geom.Point)1 DistanceOp (org.locationtech.jts.operation.distance.DistanceOp)1