Event event = entityManager.find( Event.class, addressId); Coordinate coordinate = event.getLocation().getCoordinate(); assertEquals( 10.0d, coordinate.getOrdinate( Coordinate.X), 0.1); assertEquals( 5.0d, coordinate.getOrdinate( Coordinate.Y), 0.1); }); assertEquals( 10.0d, coordinate.getOrdinate( Coordinate.X), 0.1); assertEquals( 5.0d, coordinate.getOrdinate( Coordinate.Y), 0.1); });
/** * Helper method that just inserts the coordinates of the provided array into the provide * coordinates sequence. */ private void insertCoordinates( Coordinate[] coordinates, CoordinateSequence coordinateSequence) { for (int i = 0; i < coordinates.length; i++) { Coordinate coordinate = coordinates[i]; for (int j = 0; j < coordinateSequence.getDimension(); j++) { // j is the index of the ordinate, i.e. X, Y, Z or M coordinateSequence.setOrdinate(i, j, coordinate.getOrdinate(j)); } } }
@Override public void filter(Coordinate coord) { assertEquals(90.0, Math.abs(coord.getOrdinate(0)), 0.1); assertEquals(180.0, Math.abs(coord.getOrdinate(1)), 5); } });
/** Helper method that converts an array of coordinates to an array of ordinates. */ private List<Double> getOrdinates(CoordinateSequence coordinateSequence) { List<Double> ordinates = new ArrayList<>(); for (Coordinate coordinate : coordinateSequence.toCoordinateArray()) { // let's get all the coordinates ordinates for (int i = 0; i < coordinateSequence.getDimension(); i++) { ordinates.add(coordinate.getOrdinate(i)); } } return ordinates; }
private void assertCoordinates(Coordinate[] coords, double[] expectedOrdinates, int dim) { assertEquals(expectedOrdinates.length / dim, coords.length); for (int i = 0; i < expectedOrdinates.length; i += dim) { Coordinate c = coords[i / dim]; for (int j = 0; j < dim; j++) { assertEquals(expectedOrdinates[i + j], c.getOrdinate(j), EPS); } } } }
if (wgs84Point.getCoordinate().getOrdinate(fc.northDimension) >= 0) { fb.add("N"); } else {
/** * @see org.locationtech.jts.geom.CoordinateSequence#getOrdinate(int, int) */ public double getOrdinate(int index, int ordinateIndex) { switch (ordinateIndex) { case CoordinateSequence.X: return coordinates[index].x; case CoordinateSequence.Y: return coordinates[index].y; default: return coordinates[index].getOrdinate(ordinateIndex); } }
/** * Return true if the values of the two {@link Coordinate} are equal when their * first and second ordinates are cast as ints. Ignores 3rd ordinate. * * @param a first coordinate to compare * @param b second coordinate to compare * @return true if the values of the two {@link Coordinate} are equal when their * first and second ordinates are cast as ints */ private static boolean equalAsInts2d(Coordinate a, Coordinate b) { return ((int)a.getOrdinate(0)) == ((int)b.getOrdinate(0)) && ((int)a.getOrdinate(1)) == ((int)b.getOrdinate(1)); }
protected double lng(Coordinate coordinate) { return coordinate.getOrdinate(0); }
/** * Return true if the values of the two {@link Coordinate} are equal when their first and second * ordinates are cast as ints. Ignores 3rd ordinate. * * @param a first coordinate to compare * @param b second coordinate to compare * @return true if the values of the two {@link Coordinate} are equal when their * first and second ordinates are cast as ints */ private static boolean equalAsInts2d(Coordinate a, Coordinate b) { return ((int) a.getOrdinate(0)) == ((int) b.getOrdinate(0)) && ((int) a.getOrdinate(1)) == ((int) b.getOrdinate(1)); }
protected double lat(Coordinate coordinate) { return coordinate.getOrdinate(1); }
/** * Builds a new packed coordinate sequence out of a coordinate array * * @param coordinates * @param dimensions * @param measures */ public Double(Coordinate[] coordinates, int dimension, int measures) { super(dimension,measures); if (coordinates == null) coordinates = new Coordinate[0]; coords = new double[coordinates.length * this.dimension]; for (int i = 0; i < coordinates.length; i++) { coords[i * this.dimension] = coordinates[i].x; if (this.dimension >= 2) coords[i * this.dimension + 1] = coordinates[i].y; if (this.dimension >= 3) coords[i * this.dimension + 2] = coordinates[i].getOrdinate(2); // Z or M if (this.dimension >= 4) coords[i * this.dimension + 3] = coordinates[i].getOrdinate(3); // M } } /**
/** * Scales the given geometry by multiplying the coordinates by the * indicated x, y and z scale factors. * * @param geom Geometry * @param xFactor x scale factor * @param yFactor y scale factor * @param zFactor z scale factor * @return The geometry scaled by the given x, y and z scale factors */ public static Geometry scale(Geometry geom, double xFactor, double yFactor, double zFactor) { if (geom != null) { Geometry scaledGeom = geom.copy(); for (Coordinate c : scaledGeom.getCoordinates()) { c.setOrdinate(Coordinate.X, c.getOrdinate(Coordinate.X) * xFactor); c.setOrdinate(Coordinate.Y, c.getOrdinate(Coordinate.Y) * yFactor); c.setOrdinate(Coordinate.Z, c.getOrdinate(Coordinate.Z) * zFactor); } return scaledGeom; } else { return null; } } }
public void testGetOrdinate() { Coordinate c = new Coordinate(350.2, 4566.8, 5266.3); assertEquals(c.getOrdinate(Coordinate.X), 350.2); assertEquals(c.getOrdinate(Coordinate.Y), 4566.8); assertEquals(c.getOrdinate(Coordinate.Z), 5266.3); } public void testSetOrdinate()
modifier.setOrdinate(i, coord.getOrdinate(i));
public void testSetOrdinate() { Coordinate c = new Coordinate(); c.setOrdinate(Coordinate.X, 111); c.setOrdinate(Coordinate.Y, 222); c.setOrdinate(Coordinate.Z, 333); assertEquals(c.getOrdinate(Coordinate.X), 111.0); assertEquals(c.getOrdinate(Coordinate.Y), 222.0); assertEquals(c.getOrdinate(Coordinate.Z), 333.0); } public void testEquals()
@Test public void test() { Long addressId = doInJPA(entityManager -> { try { Address address = new Address(); address.setId(1L); address.setStreet("5th Avenue"); address.setNumber("1 A"); address.setLocation((Point) new WKTReader().read("POINT(60 12)")); entityManager.persist(address); return address.getId(); } catch (ParseException e) { throw new RuntimeException(e); } }); doInJPA(entityManager -> { Address address = entityManager.find(Address.class, addressId); Coordinate coordinate = address.getLocation().getCoordinate(); assertEquals(60.0d, coordinate.getOrdinate(Coordinate.X), 0.1); assertEquals(12.0d, coordinate.getOrdinate(Coordinate.Y), 0.1); }); }
map.getWidth(), map.getHeight()); double[] p = new double[] {c.getOrdinate(0), c.getOrdinate(1)}; MathTransform tx = CRS.findMathTransform(map.getCrs(), WGS84, true); tx.transform(p, 0, p, 0, 1);
boolean isAllCoordsEqual(CoordinateSequence seq, Coordinate coord) { for (int i = 0; i < seq.size(); i++) { if (!coord.equals(seq.getCoordinate(i))) return false; if (coord.x != seq.getOrdinate(i, CoordinateSequence.X)) return false; if (coord.y != seq.getOrdinate(i, CoordinateSequence.Y)) return false; if (seq.hasZ()) { if (coord.getZ() != seq.getZ(i)) return false; } if (seq.hasM()) { if (coord.getM() != seq.getM(i)) return false; } if (seq.getDimension() > 2) { if (coord.getOrdinate(2) != seq.getOrdinate(i, 2)) return false; } if (seq.getDimension() > 3) { if (coord.getOrdinate(3) != seq.getOrdinate(i, 3)) return false; } } return true; }
if (!isEqual(coords[i].y,seq.getOrdinate(i, CoordinateSequence.Y))) return false; if (seq.getDimension() > 2) { if (!isEqual(coords[i].getOrdinate(2),seq.getOrdinate(i, 2))) return false; if (!isEqual(coords[i].getOrdinate(3),seq.getOrdinate(i, 3))) return false;