Search in sources :

Example 11 with Point

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

the class PgGeometrySpatialTest method testPointFromWKB.

public void testPointFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point geom = new Point("SRID=4326;POINT(75 75)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.pointFromWKB(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("Point 2 should be in the list of geometries with a given wkb", list.contains(getSamplePoint(2)));
    } 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)

Example 12 with Point

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

the class PgGeometrySpatialTest method testStartPoint.

public void testStartPoint() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(50 0)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.startPoint(geom), :point)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries with a given start point returned", 1, list.size());
        assertTrue("LineString 2 should be in the list of geometries with a given start point", list.contains(getSampleLineString(2)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.startPoint(geom)");
        query.setUnique(true);
        Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(2).getId()));
        assertEquals("Returned start 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 13 with Point

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

the class PgGeometrySpatialTest method testGeomFromWKB.

public void testGeomFromWKB() 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.geomFromWKB(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("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)

Example 14 with Point

use of org.postgis.Point in project sqlg by pietermartin.

the class TestGis method testPoint.

@Test
public void testPoint() {
    Point johannesburgPoint = new Point(26.2044, 28.0456);
    Vertex johannesburg = this.sqlgGraph.addVertex(T.label, "Gis", "point", johannesburgPoint);
    Point pretoriaPoint = new Point(25.7461, 28.1881);
    Vertex pretoria = this.sqlgGraph.addVertex(T.label, "Gis", "point", pretoriaPoint);
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(johannesburgPoint, this.sqlgGraph.traversal().V(johannesburg.id()).next().value("point"));
    Assert.assertEquals(pretoriaPoint, this.sqlgGraph.traversal().V(pretoria.id()).next().value("point"));
    Gis gis = this.sqlgGraph.gis();
    System.out.println(gis.distanceBetween(johannesburgPoint, pretoriaPoint));
    johannesburgPoint = new Point(26.2055, 28.0477);
    johannesburg.property("point", johannesburgPoint);
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(johannesburgPoint, this.sqlgGraph.traversal().V(johannesburg.id()).next().value("point"));
}
Also used : Gis(org.umlg.sqlg.gis.Gis) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Point(org.postgis.Point) GeographyPoint(org.umlg.sqlg.gis.GeographyPoint) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 15 with Point

use of org.postgis.Point in project sqlg by pietermartin.

the class TestGisBulkWithin method testBulkWithinLineString.

@Test
public void testBulkWithinLineString() {
    Point point1 = new Point(26.2044, 28.0456);
    Point point2 = new Point(26.2045, 28.0457);
    LineString lineString1 = new LineString(new Point[] { point1, point2 });
    Point point3 = new Point(26.2046, 28.0458);
    LineString lineString2 = new LineString(new Point[] { point1, point3 });
    LineString lineString3 = new LineString(new Point[] { point2, point3 });
    Point point4 = new Point(26.2047, 28.0459);
    LineString lineString4 = new LineString(new Point[] { point1, point4 });
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Gis", "line", lineString1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Gis", "line", lineString2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "Gis", "line", lineString3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "Gis", "line", lineString4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Gis").has("line", P.within(lineString1, lineString3, lineString4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) LineString(org.postgis.LineString) Point(org.postgis.Point) GeographyPoint(org.umlg.sqlg.gis.GeographyPoint) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

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