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