Search in sources :

Example 11 with Polygon

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

the class TestGis method testPolygon.

@Test
public void testPolygon() throws SQLException {
    LinearRing linearRing = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    Polygon polygon1 = new Polygon(new LinearRing[] { linearRing });
    Vertex johannesburg = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
    this.sqlgGraph.tx().commit();
    Polygon polygon = this.sqlgGraph.traversal().V(johannesburg.id()).next().value("polygon");
    Assert.assertEquals(polygon1, polygon);
    linearRing = new LinearRing("0 0, 1 2, 2 2, 1 3, 0 0");
    polygon1 = new Polygon(new LinearRing[] { linearRing });
    johannesburg.property("polygon", polygon1);
    this.sqlgGraph.tx().commit();
    polygon = this.sqlgGraph.traversal().V(johannesburg.id()).next().value("polygon");
    Assert.assertEquals(polygon1, polygon);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) LinearRing(org.postgis.LinearRing) GeographyPolygon(org.umlg.sqlg.gis.GeographyPolygon) Polygon(org.postgis.Polygon) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 12 with Polygon

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

the class TestGis method testUpgradePostGisTypes.

@Test
public void testUpgradePostGisTypes() throws Exception {
    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);
    LineString lineString = new LineString(new Point[] { johannesburgPoint, pretoriaPoint });
    Vertex pretoria = this.sqlgGraph.addVertex(T.label, "Gis", "lineString", lineString);
    GeographyPoint geographyPointJohannesburg = new GeographyPoint(26.2044, 28.0456);
    Vertex johannesburgGeographyPoint = this.sqlgGraph.addVertex(T.label, "Gis", "geographyPoint", geographyPointJohannesburg);
    LinearRing linearRing = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    Polygon polygon1 = new Polygon(new LinearRing[] { linearRing });
    Vertex johannesburgPolygon = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
    linearRing = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    GeographyPolygon geographyPolygon = new GeographyPolygon(new LinearRing[] { linearRing });
    Vertex johannesburgGeographyPolygon = this.sqlgGraph.addVertex(T.label, "Gis", "geographyPolygon", geographyPolygon);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    Connection conn = this.sqlgGraph.tx().getConnection();
    try (Statement statement = conn.createStatement()) {
        statement.execute("DROP SCHEMA " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("sqlg_schema") + " CASCADE");
    }
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<Vertex> schemaVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", sqlgGraph1.getSqlDialect().getPublicSchema()).toList();
        Assert.assertEquals(1, schemaVertices.size());
        List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", sqlgGraph1.getSqlDialect().getPublicSchema()).out("schema_vertex").has("name", "Gis").out("vertex_property").has("name", "point").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals("POINT", propertyVertices.get(0).value("type"));
        Assert.assertEquals(johannesburgPoint, sqlgGraph1.traversal().V(johannesburg.id()).next().value("point"));
        Assert.assertEquals(lineString, sqlgGraph1.traversal().V(pretoria.id()).next().value("lineString"));
        Assert.assertEquals(geographyPointJohannesburg, sqlgGraph1.traversal().V(johannesburgGeographyPoint.id()).next().value("geographyPoint"));
        Assert.assertEquals(polygon1, sqlgGraph1.traversal().V(johannesburgPolygon.id()).next().value("polygon"));
        Assert.assertEquals(geographyPolygon, sqlgGraph1.traversal().V(johannesburgGeographyPolygon.id()).next().value("geographyPolygon"));
    }
}
Also used : GeographyPolygon(org.umlg.sqlg.gis.GeographyPolygon) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) LineString(org.postgis.LineString) Statement(java.sql.Statement) GeographyPoint(org.umlg.sqlg.gis.GeographyPoint) Connection(java.sql.Connection) Point(org.postgis.Point) GeographyPoint(org.umlg.sqlg.gis.GeographyPoint) LinearRing(org.postgis.LinearRing) GeographyPolygon(org.umlg.sqlg.gis.GeographyPolygon) Polygon(org.postgis.Polygon) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 13 with Polygon

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

the class PgGeometryMySQLTest method testMbrEqual.

public void testMbrEqual() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrEqual(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which are equal to a given polygon returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which are equal to a given polygon", 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) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon)

Example 14 with Polygon

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

the class PgGeometryMySQLTest method testMbrOverlaps.

public void testMbrOverlaps() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((10 10,50 10,50 50,10 50,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrOverlaps(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which overlap a given polygon returned", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which overlap a given polygon", 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) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon)

Example 15 with Polygon

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

the class PgGeometrySpatialTest method testPolyFromWKB.

public void testPolyFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon geom = new Polygon("SRID=4326;POLYGON((75 75,100 75,100 100,75 75))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(geom, Spatial.polyFromWKB(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("Polygon 2 should be in the list of geometries with a given wkb", 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) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) MultiPolygon(org.postgis.MultiPolygon)

Aggregations

Polygon (org.postgis.Polygon)19 PersistenceManager (javax.jdo.PersistenceManager)14 Transaction (javax.jdo.Transaction)14 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)14 List (java.util.List)13 Query (javax.jdo.Query)13 MultiPolygon (org.postgis.MultiPolygon)10 Geometry (org.postgis.Geometry)4 LinearRing (org.postgis.LinearRing)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Datastore (org.datanucleus.tests.annotations.Datastore)3 Test (org.junit.Test)3 GeographyPolygon (org.umlg.sqlg.gis.GeographyPolygon)3 BaseTest (org.umlg.sqlg.test.BaseTest)3 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)2 LineString (org.postgis.LineString)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 SampleMultiPolygon (org.datanucleus.samples.pggeometry.SampleMultiPolygon)1