use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testEndPoint.
public void testEndPoint() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(110 45)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.endPoint(geom), :point)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries with a given end point returned", 1, list.size());
assertTrue("LineString 3 should be in the list of geometries with a given end point", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.endPoint(geom)");
query.setUnique(true);
Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
assertEquals("Returned end point should be equal to the given point", point, point_read);
} finally {
tx.commit();
}
}
use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testTransform.
@Datastore(POSTGRESQL)
public void testTransform() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point geom = new Point("SRID=4326;POINT(10 10)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.transform(Spatial.geomFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), 4326))");
List list = (List) query.execute(geom);
assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries with a given wkb", list.contains(getSamplePoint(1)));
} finally {
tx.commit();
}
}
use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testDistance.
@Datastore(POSTGRESQL)
public void testDistance() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(0 10)");
Double distance = new Double(10.0);
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.distance(geom, :point) == :distance");
List list = (List) query.execute(point, distance);
assertEquals("Wrong number of geometries with a distance of " + distance + " to a given point returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries with a distance of " + distance + " to a given point", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("Spatial.distance(geom, Spatial.geomFromText('POINT(0 10)', 4326))");
query.setResultClass(Double.class);
query.setUnique(true);
Double distance_read = (Double) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Point 1 should be in the given distance from the given point", distance, distance_read);
} finally {
tx.commit();
}
}
use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testContains.
public void testContains() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(30 30)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.contains(geom, :point)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which contain a given point returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries which contain a given point", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.contains(geom, Spatial.geomFromText('POINT(30 30)', 4326))");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Polygon 1 should contain the given point", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testTouches.
public void testTouches() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(75 75)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.touches(:point, geom)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which are touched by a given point returned", 2, list.size());
assertTrue("Polygon 1 should be in the list of geometries which are touched by a given point", list.contains(getSamplePolygon(1)));
assertTrue("Polygon 2 should be in the list of geometries which are touched by a given point", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.touches(Spatial.geomFromText('POINT(75 75)', 4326), geom)");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Polygon 1 should be touched by the given point", true, equals.booleanValue());
} finally {
tx.commit();
}
}
Aggregations