use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testRelate.
@Datastore(POSTGRESQL)
public void testRelate() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25,25 75)");
// crosses
String pattern = "T*T******";
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.relate(geom, :lineString, :pattern)");
List list = (List) query.execute(lineString, pattern);
assertEquals("Wrong number of geometries which are related to a given linestring returned (crosses)", 1, list.size());
assertTrue("LineString 1 should be in the list of geometries which are related to a given linestring (crosses)", list.contains(getSampleLineString(1)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.relate(geom, Spatial.geomFromText('LINESTRING(25 25,25 75)', 4326), 'T*T******')");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSampleLineString(1).getId()));
assertEquals("LineString 1 should be crossed by the given linestring (relate mask T*T******)", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testLineFromText.
public void testLineFromText() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
String wkt = "LINESTRING(50 0, 50 100)";
Short srid = new Short((short) 4326);
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(geom, Spatial.lineFromText(:wkt, :srid))");
List list = (List) query.execute(wkt, srid);
assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
assertTrue("LineString 2 should be in the list of geometries with a given wkt", list.contains(getSampleLineString(2)));
} finally {
tx.commit();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testMLineFromText.
public void testMLineFromText() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
String wkt = "MULTILINESTRING((0 50,100 50),(50 0,50 100),(100 25,120 25,110 10,110 45))";
Short srid = new Short((short) 4326);
Short n = new Short((short) 3);
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mLineFromText(:wkt, :srid), :n))");
List list = (List) query.execute(wkt, srid, n);
assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
assertTrue("LineString 3 should be in the list of geometries with a given wkt", list.contains(getSampleLineString(3)));
} finally {
tx.commit();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testExteriorRingMethod.
public void testExteriorRingMethod() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString exteriorRing = new LineString("SRID=4326;LINESTRING(25 25,75 25,75 75,25 75,25 25)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.asText(Spatial.exteriorRing(geom)) == Spatial.asText(:exteriorRing)");
List list = (List) query.execute(exteriorRing);
assertEquals("Wrong number of geometries with a given exterior ring returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a given exterior ring", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.exteriorRing(geom)");
query.setUnique(true);
Geometry exteriorRing_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Exterior ring of Polygon 1 should be equal to the given linestring", exteriorRing, exteriorRing_read);
} finally {
tx.commit();
}
}
use of org.postgis.LineString 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));
}
Aggregations