Search in sources :

Example 6 with LineString

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

the class VoltDBOsmSink method process.

public void process(WayContainer wayContainer) {
    Way way;
    List<Long> nodeIds;
    way = wayContainer.getEntity();
    nodeIds = new ArrayList<Long>(way.getWayNodes().size());
    for (WayNode wayNode : way.getWayNodes()) {
        nodeIds.add(wayNode.getNodeId());
    }
    // Keep invalid ways out of the database if desired by the user
    if (way.getWayNodes().size() > 1 || keepInvalidWays) {
        for (Tag tag : way.getTags()) {
            try {
                client.callProcedure(new InsertCallback(), INS_WAY_TAGS_PROC, way.getId(), tag.getKey(), tag.getValue());
            } catch (NoConnectionsException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // Add these to the ways_nodes_table;
        int sequence = 0;
        for (Long nodeId : nodeIds) {
            try {
                client.callProcedure(new InsertCallback(), INS_WAYS_NODES_PROC, way.getId(), nodeId, sequence);
            } catch (NoConnectionsException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            sequence++;
        }
        StringBuffer sb = new StringBuffer();
        // if the first node id == the last nodeId, we know that this is a
        // closed loop.
        long n0 = nodeIds.get(0);
        long nn = nodeIds.get(nodeIds.size() - 1);
        if (n0 == nn) {
            if (enableBboxBuilder) {
                Polygon pg = wayGeometryBuilder.createPolygon(way);
                pg.outerWKT(sb);
            }
        } else {
            // it's a lineString, but we don't support it yet.
            if (enableLinestringBuilder) {
                LineString lineString = wayGeometryBuilder.createWayLinestring(way);
                lineString.outerWKT(sb);
            } else {
                return;
            }
        }
        String bbox = sb.toString();
        try {
            client.callProcedure(new InsertCallback(), INS_WAYS_PROC, way.getId(), way.getVersion(), way.getUser().getId(), way.getTimestamp(), way.getChangesetId(), bbox);
        } catch (NoConnectionsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) IOException(java.io.IOException) LineString(org.postgis.LineString) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) NoConnectionsException(org.voltdb.client.NoConnectionsException) LineString(org.postgis.LineString) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Polygon(org.postgis.Polygon)

Example 7 with LineString

use of org.postgis.LineString in project chuidiang-ejemplos by chuidiang.

the class PostigsMain method insertStart.

private void insertStart() throws SQLException {
    float longitude = 10;
    float latitude = 20;
    PreparedStatement ps = conn.prepareStatement("insert into geometry_tracks(id,timestamp,trajectory) values (?,?,?)");
    for (int i = 1; i < 10000; i++) {
        ps.setLong(1, i);
        ps.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
        Point[] points = new Point[2];
        points[0] = new Point(longitude, latitude);
        points[1] = new Point(longitude, latitude);
        PGgeometry geometry = new PGgeometry(new LineString(points));
        ps.setObject(3, geometry);
        ps.executeUpdate();
        longitude++;
        latitude++;
    }
}
Also used : LineString(org.postgis.LineString) Point(org.postgis.Point) Point(org.postgis.Point) PGgeometry(org.postgis.PGgeometry)

Example 8 with LineString

use of org.postgis.LineString in project chuidiang-ejemplos by chuidiang.

the class TrackDao method secondTrajectoryInsert.

public void secondTrajectoryInsert(Map<Long, Track> tracks) throws SQLException {
    if (null == secondInsertPs) {
        secondInsertPs = conn.prepareStatement("update geometry_tracks set stop_timestamp=?,trajectory=? where fusion_id=?");
    }
    tracks.values().forEach(track -> {
        try {
            if (null == track.getLastPoint() || !firstInserted.contains(track.getId())) {
                return;
            }
            secondInsertPs.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
            Point[] points = new Point[2];
            points[0] = track.getLastPoint();
            points[1] = track.getActualPoint();
            PGgeometry geometry = new PGgeometry(new LineString(points));
            secondInsertPs.setObject(2, geometry);
            secondInsertPs.setLong(3, track.getId());
            secondInsertPs.addBatch();
            firstInserted.remove(track.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    secondInsertPs.executeLargeBatch();
}
Also used : LineString(org.postgis.LineString) Point(org.postgis.Point) PGgeometry(org.postgis.PGgeometry)

Example 9 with LineString

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

the class TestGis method testLine.

@Test
public void testLine() {
    Point johannesburgPoint = new Point(26.2044, 28.0456);
    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);
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(lineString, this.sqlgGraph.traversal().V(pretoria.id()).next().value("lineString"));
    johannesburgPoint = new Point(26.55, 30.0456);
    pretoriaPoint = new Point(26.7461, 29.1881);
    lineString = new LineString(new Point[] { johannesburgPoint, pretoriaPoint });
    pretoria.property("lineString", lineString);
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(lineString, this.sqlgGraph.traversal().V(pretoria.id()).next().value("lineString"));
}
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)

Example 10 with LineString

use of org.postgis.LineString 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)

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