Search in sources :

Example 1 with MultiLineString

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

the class PgGeometryMappingTest method testMultiLineStringMapping.

public void testMultiLineStringMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    MultiLineString multiLineString = new MultiLineString("SRID=4326;MULTILINESTRING((0 50,100 50),(50 0,50 100),(100 25,120 25,110 10,110 45))");
    SampleMultiLineString sampleMultiLineString;
    SampleMultiLineString sampleMultiLineString_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleMultiLineString = new SampleMultiLineString(5001, "MultiLineString", multiLineString);
        pm.makePersistent(sampleMultiLineString);
        id = JDOHelper.getObjectId(sampleMultiLineString);
        sampleMultiLineString = (SampleMultiLineString) pm.detachCopy(sampleMultiLineString);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleMultiLineString_read = (SampleMultiLineString) pm.getObjectById(id, true);
        assertEquals(sampleMultiLineString, sampleMultiLineString_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleMultiLineString(org.datanucleus.samples.pggeometry.SampleMultiLineString) MultiLineString(org.postgis.MultiLineString) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) SampleMultiLineString(org.datanucleus.samples.pggeometry.SampleMultiLineString)

Example 2 with MultiLineString

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

the class PgGeometrySpatialTest method testMLineFromWKB.

public void testMLineFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        MultiLineString geom = new MultiLineString("SRID=4326;MULTILINESTRING((0 50,100 50),(50 0,50 100),(100 25,120 25,110 10,110 45))");
        Short n = new Short((short) 3);
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mLineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), :n))");
        List list = (List) query.execute(geom, n);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given wkb", list.contains(getSampleLineString(3)));
    } finally {
        tx.commit();
    }
}
Also used : MultiLineString(org.postgis.MultiLineString) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Example 3 with MultiLineString

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

the class PgGeometrySpatialTest method testMLineFromText.

public void testMLineFromText() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        String wkt = "MULTILINESTRING((0 50,100 50),(50 0,50 100),(100 25,120 25,110 10,110 45))";
        Short srid = new Short((short) 4326);
        Short n = new Short((short) 3);
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mLineFromText(:wkt, :srid), :n))");
        List list = (List) query.execute(wkt, srid, n);
        assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given wkt", list.contains(getSampleLineString(3)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString)

Example 4 with MultiLineString

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

the class JtsGeometrySpatialTest method testMLineFromWKB.

public void testMLineFromWKB() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        MultiLineString geom = new MultiLineString("SRID=4326;MULTILINESTRING((0 50,100 50),(50 0,50 100),(100 25,120 25,110 10,110 45))");
        Short n = new Short((short) 3);
        Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.equals(Spatial.geometryN(Spatial.mLineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), :n))");
        List list = (List) query.execute(geom, n);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given wkb", list.contains(getSampleLineString(3)));
    } finally {
        tx.commit();
    }
}
Also used : MultiLineString(org.postgis.MultiLineString) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Example 5 with MultiLineString

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

the class JtsGeometrySpatialTest method testMLineFromText.

public void testMLineFromText() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        String wkt = "MULTILINESTRING((0 50,100 50),(50 0,50 100),(100 25,120 25,110 10,110 45))";
        Short srid = new Short((short) 4326);
        Short n = new Short((short) 3);
        Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.equals(Spatial.geometryN(Spatial.mLineFromText(:wkt, :srid), :n))");
        List list = (List) query.execute(wkt, srid, n);
        assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given wkt", list.contains(getSampleLineString(3)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) LineString(com.vividsolutions.jts.geom.LineString) SampleLineString(org.datanucleus.samples.jtsgeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)5 Transaction (javax.jdo.Transaction)5 MultiLineString (org.postgis.MultiLineString)5 List (java.util.List)4 Query (javax.jdo.Query)4 LineString (com.vividsolutions.jts.geom.LineString)1 SampleLineString (org.datanucleus.samples.jtsgeometry.SampleLineString)1 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)1 SampleMultiLineString (org.datanucleus.samples.pggeometry.SampleMultiLineString)1 LineString (org.postgis.LineString)1