use of org.locationtech.jts.geom.Coordinate in project jena by apache.
the class DimensionInfoTest method testFind_List_Geometry.
/**
* Test of find method, of class DimensionInfo.
*/
@Test
public void testFind_List_Geometry() {
List<Coordinate> coordinates = Arrays.asList(new CoordinateXY(1.0, 2.0), new CoordinateXY(10.0, 20.0));
GeometryFactory factory = new GeometryFactory();
Geometry geometry = factory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
DimensionInfo expResult = DimensionInfo.XY_LINESTRING;
DimensionInfo result = DimensionInfo.find(coordinates, geometry);
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.Coordinate in project jena by apache.
the class DimensionInfoTest method testFindCollection.
/**
* Test of findCollection method, of class DimensionInfo.
*/
@Test
public void testFindCollection() {
GeometryFactory factory = new GeometryFactory();
List<Point> points = Arrays.asList(factory.createPoint(new Coordinate(1.0, 2.0)), factory.createPoint(new Coordinate(10.0, 20.0)));
Geometry geometry = factory.createMultiPoint(points.toArray(new Point[points.size()]));
DimensionInfo expResult = DimensionInfo.XY_POINT;
DimensionInfo result = DimensionInfo.findCollection(points, geometry);
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.Coordinate in project jena by apache.
the class GeometryWrapper method distanceGreatCircle.
/**
* Distance (Great Circle) in the Units of Measure stated in URI.
*
* @param targetGeometry
* @param targetDistanceUnitsURI
* @return Distance
* @throws org.opengis.util.FactoryException
* @throws org.opengis.referencing.operation.TransformException
*/
public double distanceGreatCircle(GeometryWrapper targetGeometry, String targetDistanceUnitsURI) throws FactoryException, MismatchedDimensionException, TransformException {
GeometryWrapper transformedSourceGeometry;
if (srsInfo.isGeographic()) {
// Already a geographic SRS.
transformedSourceGeometry = this;
} else {
// Use WGS84 and not CRS84 as assuming WGS8 is more prevalent.
transformedSourceGeometry = this.transform(SRS_URI.WGS84_CRS);
}
GeometryWrapper transformedTargetGeometry = transformedSourceGeometry.checkTransformSRS(targetGeometry);
// Find the nearest pair of coordinates from each Geometry using Euclidean distance (adjusting for wrap around).
// These are then used for Great Circle distance.
CoordinatePair coordinatePair = CoordinatePair.findNearestPair(transformedSourceGeometry, transformedTargetGeometry);
// Check whether the nearest pair are the same, i.e. the overlap or within each other.
if (coordinatePair.isEqual()) {
// Exit early as the distance is zero.
return 0.0;
}
Coordinate coord1 = coordinatePair.getCoord1();
Coordinate coord2 = coordinatePair.getCoord2();
double distance = GreatCircleDistance.haversineFormula(coord1.getY(), coord1.getX(), coord2.getY(), coord2.getX());
// Convert the Great Circle distance from metres into the requested units.
Boolean isTargetUnitsLinear = UnitsRegistry.isLinearUnits(targetDistanceUnitsURI);
double targetDistance;
if (isTargetUnitsLinear) {
// Target units are linear so straight conversion. Distance is in metres already.
targetDistance = UnitsOfMeasure.conversion(distance, Unit_URI.METRE_URL, targetDistanceUnitsURI);
} else {
targetDistance = UnitsOfMeasure.convertBetween(distance, Unit_URI.METRE_URL, targetDistanceUnitsURI, isTargetUnitsLinear, transformedSourceGeometry.getLatitude());
}
return targetDistance;
}
use of org.locationtech.jts.geom.Coordinate in project jena by apache.
the class GeometryReverse method reverseGeometry.
/**
* Reverses coordinate order of the supplied geometry and produces a new
* geometry.
*
* @param geometry
* @return Geometry in x,y coordinate order.
*/
public static Geometry reverseGeometry(Geometry geometry) {
if (geometry.isEmpty()) {
return geometry.copy();
}
GeometryFactory factory = geometry.getFactory();
Geometry finalGeometry;
Coordinate[] coordinates;
String type = geometry.getGeometryType();
switch(type) {
case "LineString":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createLineString(coordinates);
break;
case "LinearRing":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createLinearRing(coordinates);
break;
case "MultiPoint":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createMultiPointFromCoords(coordinates);
break;
case "Polygon":
finalGeometry = reversePolygon(geometry, factory);
break;
case "Point":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createPoint(coordinates[0]);
break;
case "MultiPolygon":
Polygon[] polygons = unpackPolygons((GeometryCollection) geometry);
finalGeometry = factory.createMultiPolygon(polygons);
break;
case "MultiLineString":
LineString[] lineString = unpackLineStrings((GeometryCollection) geometry);
finalGeometry = factory.createMultiLineString(lineString);
break;
case "GeometryCollection":
Geometry[] geometries = unpackGeometryCollection((GeometryCollection) geometry);
finalGeometry = factory.createGeometryCollection(geometries);
break;
default:
finalGeometry = geometry;
break;
}
return finalGeometry;
}
use of org.locationtech.jts.geom.Coordinate in project jena by apache.
the class GeometryReverse method getReversedCoordinates.
private static Coordinate[] getReversedCoordinates(Geometry geometry) {
Coordinate[] original = geometry.getCoordinates();
Coordinate[] reversed = new Coordinate[original.length];
for (int i = 0; i < original.length; i++) {
reversed[i] = new Coordinate(original[i].y, original[i].x);
}
return reversed;
}
Aggregations