Search in sources :

Example 16 with LineString

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

the class PgGeometrySpatialTest method testGeomCollFromText.

public void testGeomCollFromText() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        String wkt = "GEOMETRYCOLLECTION(POINT(10 10),LINESTRING(0 50, 100 50),POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)))";
        Short srid = new Short((short) 4326);
        Short n = new Short((short) 1);
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.geomCollFromText(: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("Polygon 1 should be in the list of geometries with a given wkt", 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) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString)

Example 17 with LineString

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

the class PgGeometrySpatialTest method testLineFromWKB.

public void testLineFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString geom = new LineString("SRID=4326;LINESTRING(50 0, 50 100)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(geom, Spatial.lineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("LineString 2 should be in the list of geometries with a given wkb", list.contains(getSampleLineString(2)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) List(java.util.List)

Example 18 with LineString

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

the class PgGeometrySpatialTest method testGeometryN.

public void testGeometryN() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Short n = new Short((short) 2);
        LineString lineString = new LineString("SRID=4326;LINESTRING(50 0,50 100)");
        Query query = pm.newQuery(SampleGeometryCollection.class, "geom != null && Spatial.asText(Spatial.geometryN(geom, :n)) == Spatial.asText(:lineString)");
        List list = (List) query.execute(n, lineString);
        assertEquals("Wrong number of collections whose " + n + "th geometry is equal to a given linestring returned", 1, list.size());
        assertTrue("Collection 2 should be in the list of collections whose " + n + "th geometry is equal to a given linestring", list.contains(getSampleGeometryCollection(2)));
        query = pm.newQuery(SampleGeometryCollection.class, "id == :id");
        query.setResult("Spatial.geometryN(geom, 2)");
        query.setUnique(true);
        Geometry lineString_read = (Geometry) query.execute(new Long(getSampleGeometryCollection(2).getId()));
        assertEquals("Second geometry of Collection 2 should be equal to the given linestring", lineString, lineString_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) SampleGeometryCollection(org.datanucleus.samples.pggeometry.SampleGeometryCollection) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) List(java.util.List)

Example 19 with LineString

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

the class PgGeometrySpatialTest method testBoundary.

@Datastore(POSTGRESQL)
public void testBoundary() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString boundary = new LineString("SRID=4326;LINESTRING(75 75,100 75,100 100,75 75)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.boundary(geom), :boundary)");
        List list = (List) query.execute(boundary);
        assertEquals("Wrong number of geometries with a given boundary returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries with a given boundary", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.boundary(geom)");
        query.setUnique(true);
        Geometry boundary_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Boundary of Polygon 2 should be equal to a given boundary", boundary, boundary_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Aggregations

LineString (org.postgis.LineString)19 PersistenceManager (javax.jdo.PersistenceManager)13 Transaction (javax.jdo.Transaction)13 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)13 MultiLineString (org.postgis.MultiLineString)13 List (java.util.List)12 Query (javax.jdo.Query)12 Point (org.postgis.Point)6 Datastore (org.datanucleus.tests.annotations.Datastore)5 Geometry (org.postgis.Geometry)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)3 Test (org.junit.Test)3 GeographyPoint (org.umlg.sqlg.gis.GeographyPoint)3 BaseTest (org.umlg.sqlg.test.BaseTest)3 PGgeometry (org.postgis.PGgeometry)2 Polygon (org.postgis.Polygon)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1