Search in sources :

Example 26 with Point

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);
    });
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 27 with Point

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"));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 28 with Point

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));
}
Also used : Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 29 with Point

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);
    }
}
Also used : IoParseException(org.n52.io.IoParseException) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) Point(com.vividsolutions.jts.geom.Point) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint)

Example 30 with Point

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);
}
Also used : Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Test(org.junit.Test)

Aggregations

Point (com.vividsolutions.jts.geom.Point)48 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Geometry (com.vividsolutions.jts.geom.Geometry)15 Test (org.junit.Test)12 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)11 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)10 Polygon (com.vividsolutions.jts.geom.Polygon)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)4 ParseException (com.vividsolutions.jts.io.ParseException)4 ArrayList (java.util.ArrayList)4 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 StringReader (java.io.StringReader)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3