Search in sources :

Example 6 with Point

use of org.postgis.Point in project tests by datanucleus.

the class PgGeometrySpatialTest method testEndPoint.

public void testEndPoint() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(110 45)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.endPoint(geom), :point)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries with a given end point returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given end point", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.endPoint(geom)");
        query.setUnique(true);
        Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned end point should be equal to the given point", point, point_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point)

Example 7 with Point

use of org.postgis.Point in project tests by datanucleus.

the class PgGeometrySpatialTest method testTransform.

@Datastore(POSTGRESQL)
public void testTransform() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point geom = new Point("SRID=4326;POINT(10 10)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.transform(Spatial.geomFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), 4326))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries with a given wkb", list.contains(getSamplePoint(1)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 8 with Point

use of org.postgis.Point in project tests by datanucleus.

the class PgGeometrySpatialTest method testDistance.

@Datastore(POSTGRESQL)
public void testDistance() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(0 10)");
        Double distance = new Double(10.0);
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.distance(geom, :point) == :distance");
        List list = (List) query.execute(point, distance);
        assertEquals("Wrong number of geometries with a distance of " + distance + " to a given point returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries with a distance of " + distance + " to a given point", list.contains(getSamplePoint(1)));
        query = pm.newQuery(SamplePoint.class, "id == :id");
        query.setResult("Spatial.distance(geom, Spatial.geomFromText('POINT(0 10)', 4326))");
        query.setResultClass(Double.class);
        query.setUnique(true);
        Double distance_read = (Double) query.execute(new Long(getSamplePoint(1).getId()));
        assertEquals("Point 1 should be in the given distance from the given point", distance, distance_read);
    } finally {
        tx.commit();
    }
}
Also used : SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 9 with Point

use of org.postgis.Point in project tests by datanucleus.

the class PgGeometrySpatialTest method testContains.

public void testContains() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(30 30)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.contains(geom, :point)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which contain a given point returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which contain a given point", list.contains(getSamplePolygon(1)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.contains(geom, Spatial.geomFromText('POINT(30 30)', 4326))");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
        assertEquals("Polygon 1 should contain the given point", true, equals.booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point)

Example 10 with Point

use of org.postgis.Point in project tests by datanucleus.

the class PgGeometrySpatialTest method testTouches.

public void testTouches() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(75 75)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.touches(:point, geom)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which are touched by a given point returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which are touched by a given point", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries which are touched by a given point", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.touches(Spatial.geomFromText('POINT(75 75)', 4326), geom)");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
        assertEquals("Polygon 1 should be touched by the given point", true, equals.booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point)

Aggregations

Point (org.postgis.Point)33 PersistenceManager (javax.jdo.PersistenceManager)22 Transaction (javax.jdo.Transaction)22 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)21 List (java.util.List)18 Query (javax.jdo.Query)18 MultiPoint (org.postgis.MultiPoint)18 Datastore (org.datanucleus.tests.annotations.Datastore)7 Geometry (org.postgis.Geometry)7 LineString (org.postgis.LineString)6 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)5 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)5 Test (org.junit.Test)5 GeographyPoint (org.umlg.sqlg.gis.GeographyPoint)5 BaseTest (org.umlg.sqlg.test.BaseTest)5 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)4 SampleMultiPoint (org.datanucleus.samples.pggeometry.SampleMultiPoint)3 LinearRing (org.postgis.LinearRing)3 PGgeometry (org.postgis.PGgeometry)3 Connection (java.sql.Connection)1