use of org.postgis.Point 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();
}
use of org.postgis.Point in project chuidiang-ejemplos by chuidiang.
the class MainCommons method updateModel.
protected void updateModel() {
model.getTracks().forEach((id, track) -> {
track.setLastPoint(track.getActualPoint());
double longitude = track.getActualPoint().getX();
double latitude = track.getActualPoint().getY();
double radians = Math.toRadians(track.getCog());
longitude = longitude + Math.cos(radians) * 0.01;
latitude = latitude + Math.sin(radians) * 0.01;
track.setCog(track.getCog() + Math.random() * 10 - 4.5);
track.setActualPoint(new Point(longitude, latitude));
});
}
use of org.postgis.Point 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"));
}
use of org.postgis.Point 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"));
}
}
use of org.postgis.Point in project tests by datanucleus.
the class PgGeometryMappingTest method testLinearRingMapping.
public void testLinearRingMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
LinearRing linearRing = new LinearRing(new Point[] { new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0) });
linearRing.setSrid(4326);
SampleLinearRing sampleLinearRing;
SampleLinearRing sampleLinearRing_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleLinearRing = new SampleLinearRing(2101, "LinearRing", linearRing);
pm.makePersistent(sampleLinearRing);
id = JDOHelper.getObjectId(sampleLinearRing);
sampleLinearRing = (SampleLinearRing) pm.detachCopy(sampleLinearRing);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleLinearRing_read = (SampleLinearRing) pm.getObjectById(id, true);
assertEquals(sampleLinearRing, sampleLinearRing_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations