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]);
}
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());
}
}
Aggregations