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