Search in sources :

Example 1 with LinearRing

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

the class TestGis method testGeographyPolygon.

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

Example 2 with LinearRing

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

the class TestGisBulkWithin method testBulkWithinGeographyPolygon.

@Test
public void testBulkWithinGeographyPolygon() throws SQLException {
    LinearRing linearRing1 = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    GeographyPolygon polygon1 = new GeographyPolygon(new LinearRing[] { linearRing1 });
    LinearRing linearRing2 = new LinearRing("1 1, 1 1, 1 2, 1 1, 1 1");
    GeographyPolygon polygon2 = new GeographyPolygon(new LinearRing[] { linearRing2 });
    LinearRing linearRing3 = new LinearRing("2 2, 1 1, 1 2, 1 1, 2 2");
    GeographyPolygon polygon3 = new GeographyPolygon(new LinearRing[] { linearRing3 });
    LinearRing linearRing4 = new LinearRing("1 3, 1 2, 2 2, 1 1, 1 3");
    GeographyPolygon polygon4 = new GeographyPolygon(new LinearRing[] { linearRing4 });
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Gis").has("polygon", P.within(polygon1, polygon3, polygon4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
Also used : GeographyPolygon(org.umlg.sqlg.gis.GeographyPolygon) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) LinearRing(org.postgis.LinearRing) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 3 with LinearRing

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

the class TestGisBulkWithin method testBulkWithinPolygon.

@Test
public void testBulkWithinPolygon() throws SQLException {
    LinearRing linearRing1 = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    Polygon polygon1 = new Polygon(new LinearRing[] { linearRing1 });
    LinearRing linearRing2 = new LinearRing("1 1, 1 1, 1 2, 1 1, 1 1");
    Polygon polygon2 = new Polygon(new LinearRing[] { linearRing2 });
    LinearRing linearRing3 = new LinearRing("2 2, 1 1, 1 2, 1 1, 2 2");
    Polygon polygon3 = new Polygon(new LinearRing[] { linearRing3 });
    LinearRing linearRing4 = new LinearRing("1 3, 1 2, 2 2, 1 1, 1 3");
    Polygon polygon4 = new Polygon(new LinearRing[] { linearRing4 });
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Gis").has("polygon", P.within(polygon1, polygon3, polygon4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
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 4 with LinearRing

use of org.postgis.LinearRing in project voltdb by VoltDB.

the class WayPolygonGeometryBuilder method createRing.

public LinearRing createRing(Way way) {
    List<Point> points = new ArrayList<Point>();
    for (WayNode wayNode : way.getWayNodes()) {
        NodeLocation nodeLocation;
        double longitude;
        double latitude;
        nodeLocation = locationStore.getNodeLocation(wayNode.getNodeId());
        longitude = nodeLocation.getLongitude();
        latitude = nodeLocation.getLatitude();
        if (nodeLocation.isValid()) {
            Point point = new Point(longitude, latitude);
            points.add(point);
        }
    }
    return new LinearRing(points.toArray(new Point[0]));
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) NodeLocation(org.openstreetmap.osmosis.pgsimple.common.NodeLocation) ArrayList(java.util.ArrayList) Point(org.postgis.Point) LinearRing(org.postgis.LinearRing)

Example 5 with LinearRing

use of org.postgis.LinearRing in project voltdb by VoltDB.

the class WayPolygonGeometryBuilder method createPolygon.

/**
     * OSM stores each ring of a polygon independently, the rings of a polygon
     * need to be combined through relationships. This method only returns a
     * single ring of a Polygon,
     *
     * @param way
     * @return
     */
public Polygon createPolygon(Way way) {
    LinearRing[] rings = new LinearRing[1];
    rings[0] = createRing(way);
    Polygon pg = new Polygon(rings);
    return pg;
}
Also used : LinearRing(org.postgis.LinearRing) Polygon(org.postgis.Polygon)

Aggregations

LinearRing (org.postgis.LinearRing)8 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)5 Test (org.junit.Test)5 GeographyPolygon (org.umlg.sqlg.gis.GeographyPolygon)5 BaseTest (org.umlg.sqlg.test.BaseTest)5 Polygon (org.postgis.Polygon)4 Point (org.postgis.Point)3 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleLinearRing (org.datanucleus.samples.pggeometry.SampleLinearRing)1 SampleMultiPoint (org.datanucleus.samples.pggeometry.SampleMultiPoint)1 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)1 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)1 NodeLocation (org.openstreetmap.osmosis.pgsimple.common.NodeLocation)1 LineString (org.postgis.LineString)1 MultiPoint (org.postgis.MultiPoint)1 GeographyPoint (org.umlg.sqlg.gis.GeographyPoint)1