Search in sources :

Example 1 with Point

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

the class PgGeometryMappingTest method testPointMapping.

public void testPointMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    Point point = new Point("SRID=4326;POINT(10 10)");
    SamplePoint samplePoint;
    SamplePoint samplePoint_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        samplePoint = new SamplePoint(1001, "Point 1", point);
        pm.makePersistent(samplePoint);
        id = JDOHelper.getObjectId(samplePoint);
        samplePoint = (SamplePoint) pm.detachCopy(samplePoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        samplePoint_read = (SamplePoint) pm.getObjectById(id, true);
        assertEquals(samplePoint, samplePoint_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) SampleMultiPoint(org.datanucleus.samples.pggeometry.SampleMultiPoint)

Example 2 with Point

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

the class PgGeometryMappingTest method testGeometryMapping.

public void testGeometryMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    Point point = new Point("SRID=4326;POINT(10 10)");
    SampleGeometry sampleGeometry;
    SampleGeometry sampleGeometry_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometry = new SampleGeometry(1001, "Geometry (Point)", point);
        pm.makePersistent(sampleGeometry);
        id = JDOHelper.getObjectId(sampleGeometry);
        sampleGeometry = (SampleGeometry) pm.detachCopy(sampleGeometry);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometry_read = (SampleGeometry) pm.getObjectById(id, true);
        assertEquals(sampleGeometry, sampleGeometry_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.pggeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) SampleMultiPoint(org.datanucleus.samples.pggeometry.SampleMultiPoint)

Example 3 with Point

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

the class PgGeometryMySQLTest method testMbrWithin.

public void testMbrWithin() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    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 && MySQL.mbrWithin(:point, geom)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries where a given point is within returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries where a given point is within", list.contains(getSamplePolygon(1)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point)

Example 4 with Point

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

the class PgGeometryMySQLTest method testMbrTouches.

public void testMbrTouches() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    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 && MySQL.mbrTouches(: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)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point)

Example 5 with Point

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

the class PgGeometryMySQLTest method testMbrContains.

public void testMbrContains() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    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 && MySQL.mbrContains(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)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) 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