Search in sources :

Example 1 with SrsException

use of org.apache.jena.geosparql.configuration.SrsException 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 SrsException

use of org.apache.jena.geosparql.configuration.SrsException in project jena by apache.

the class Main method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // Apache SIS j.u.l logging redirection.
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    LOGGER.info("Arguments Received: {}", Arrays.asList(args));
    ArgsConfig argsConfig = new ArgsConfig();
    JCommander jCommander = JCommander.newBuilder().addObject(argsConfig).build();
    jCommander.setProgramName("GeoSPARQL Fuseki");
    jCommander.parse(args);
    if (argsConfig.isHelp()) {
        jCommander.usage();
        return;
    }
    // Setup dataset
    try {
        Dataset dataset = DatasetOperations.setup(argsConfig);
        // Configure server
        GeosparqlServer server = new GeosparqlServer(argsConfig.getPort(), argsConfig.getDatsetName(), argsConfig.isLoopbackOnly(), dataset, argsConfig.isUpdateAllowed());
        server.start();
    } catch (SrsException | DatasetException | SpatialIndexException ex) {
        LOGGER.error("GeoSPARQL Server:  Exiting - {}: {}", ex.getMessage(), argsConfig.getDatsetName());
    }
}
Also used : SrsException(org.apache.jena.geosparql.configuration.SrsException) ArgsConfig(org.apache.jena.fuseki.geosparql.cli.ArgsConfig) JCommander(com.beust.jcommander.JCommander) Dataset(org.apache.jena.query.Dataset) SpatialIndexException(org.apache.jena.geosparql.spatial.SpatialIndexException)

Aggregations

SrsException (org.apache.jena.geosparql.configuration.SrsException)2 JCommander (com.beust.jcommander.JCommander)1 ArgsConfig (org.apache.jena.fuseki.geosparql.cli.ArgsConfig)1 SRSInfo (org.apache.jena.geosparql.implementation.SRSInfo)1 SpatialIndexException (org.apache.jena.geosparql.spatial.SpatialIndexException)1 Dataset (org.apache.jena.query.Dataset)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Envelope (org.locationtech.jts.geom.Envelope)1 Geometry (org.locationtech.jts.geom.Geometry)1 Point (org.locationtech.jts.geom.Point)1 DistanceOp (org.locationtech.jts.operation.distance.DistanceOp)1