use of com.vividsolutions.jts.geom.Point in project hibernate-orm by hibernate.
the class SpatialTest method test.
@Test
public void test() {
Long addressId = doInJPA(this::entityManagerFactory, entityManager -> {
Event event = new Event();
event.setId(1L);
event.setName("Hibernate ORM presentation");
Point point = geometryFactory.createPoint(new Coordinate(10, 5));
event.setLocation(point);
entityManager.persist(event);
return event.getId();
});
doInJPA(this::entityManagerFactory, entityManager -> {
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);
});
doInJPA(this::entityManagerFactory, entityManager -> {
Coordinate[] coordinates = new Coordinate[] { new Coordinate(1, 1), new Coordinate(20, 1), new Coordinate(20, 20), new Coordinate(1, 20), new Coordinate(1, 1) };
Polygon window = geometryFactory.createPolygon(coordinates);
Event event = entityManager.createQuery("select e " + "from Event e " + "where within(e.location, :window) = true", Event.class).setParameter("window", window).getSingleResult();
Coordinate coordinate = event.getLocation().getCoordinate();
assertEquals(10.0d, coordinate.getOrdinate(Coordinate.X), 0.1);
assertEquals(5.0d, coordinate.getOrdinate(Coordinate.Y), 0.1);
});
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class GeotoolsJTSReferenceTester method shouldBlah.
@Test
public void shouldBlah() throws Exception {
CRSUtils forcedXYOrder = CRSUtils.createEpsgForcedXYAxisOrder();
GeometryFactory xyFactory = forcedXYOrder.createGeometryFactory("EPSG:4326");
Point forcedXYPoint = xyFactory.createPoint(new Coordinate(7.4, 52.3));
LOGGER.info("EPSG:4326 as JTS point (forced XY): {}", forcedXYPoint);
LOGGER.info("Transformed to EPSG:25832: {}", forcedXYOrder.transform(forcedXYPoint, "EPSG:4326", "EPSG:25832"));
CRSUtils respectEpsgOrder = CRSUtils.createEpsgStrictAxisOrder();
GeometryFactory strictFactory = respectEpsgOrder.createGeometryFactory("EPSG:4326");
Point strictPoint = strictFactory.createPoint(new Coordinate(52.3, 7.4));
LOGGER.info("EPSG:4326 as JTS point (strict EPSG order): {}", strictPoint);
LOGGER.info("Transformed to EPSG:25832: {}", respectEpsgOrder.transform(strictPoint, "EPSG:4326", "EPSG:25832"));
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class WGS84UtilTest method shouldCalculateShortestDistanceFromStatueOfLibertyToEiffelTower.
@Test
public void shouldCalculateShortestDistanceFromStatueOfLibertyToEiffelTower() throws FactoryException {
Point statueOfLiberty = createXYOrderedWgs84Point(-74.0444, 40.6892);
Point tourDeEiffel = createXYOrderedWgs84Point(2.2945, 48.8583);
assertThat(shortestDistanceBetween(statueOfLiberty, tourDeEiffel), closeTo(5837.0, 0.5));
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class IoParameters method transformToInnerCrs.
/**
* @param point
* a GeoJSON point to be transformed to internally used CRS:84.
* @param crsUtils
* a reference helper.
* @return a transformed GeoJSON instance.
* @throws IoParseException
* if point could not be transformed, or if requested CRS object could not be created.
*/
private GeojsonPoint transformToInnerCrs(GeojsonPoint point, CRSUtils crsUtils) {
try {
Point toTransformed = crsUtils.convertToPointFrom(point, getCrs());
Point crs84Point = (Point) crsUtils.transformOuterToInner(toTransformed, getCrs());
return crsUtils.convertToGeojsonFrom(crs84Point);
} catch (TransformException e) {
throw new IoParseException("Could not transform to internally used CRS:84.", e);
} catch (FactoryException e) {
throw new IoParseException("Check if 'crs' parameter is a valid EPSG CRS. Was: '" + getCrs() + "'.", e);
}
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class GeoJSONTest method testPointWithZCoordinate.
@Test
public void testPointWithZCoordinate() throws GeoJSONException, IOException {
Point geometry = randomPoint(2000);
geometry.apply(new RandomZCoordinateFilter());
geometry.geometryChanged();
readWriteTest(geometry);
}
Aggregations