use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.
the class JtsGeometrySpatialTest method testBboxTest.
@Datastore(POSTGRESQL)
public void testBboxTest() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(90 90)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.bboxTest(:point, geom)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which pass the bbox test with a given point returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries which pass the bbox test with a given point", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.bboxTest(Spatial.geomFromText('POINT(90 90)', 4326), geom)");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(Long.valueOf(getSamplePolygon(2).getId()));
assertEquals("Polygon 2 should pass bbox test with the given point", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.
the class JtsGeometrySpatialTest method testBuffer.
@Datastore(POSTGRESQL)
public void testBuffer() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(0 0)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.within(:point.buffer(20))");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which are within the buffer of a given point returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries which are within the buffer of a given point", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("geom.buffer(20)");
query.setUnique(true);
Geometry buffer = (Geometry) query.execute(Long.valueOf(getSamplePoint(1).getId()));
assertEquals("Returned buffer should be a polygon", "POLYGON", buffer.getGeometryType().toUpperCase());
assertEquals("Returned buffer should have the given srid", 4326, buffer.getSRID());
assertTrue("Given point should be within the returned buffer", point.within(buffer));
} finally {
tx.commit();
}
}
use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.
the class JtsGeometrySpatialTest method testDistance.
public void testDistance() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(0 10)");
Double distance = Double.valueOf(10.0);
Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.distance(: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("geom.distance(Spatial.geomFromText('POINT(0 10)', 4326))");
query.setResultClass(Double.class);
query.setUnique(true);
Double distance_read = (Double) query.execute(Long.valueOf(getSamplePoint(1).getId()));
assertEquals("Point 1 should be in the given distance from the given point", distance, distance_read);
} finally {
tx.commit();
}
}
use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.
the class JtsGeometrySpatialTest method testCentroid.
@Datastore(POSTGRESQL)
public void testCentroid() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point centroid = (Point) wktReader.read("POINT(50 50)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.getCentroid().toText() == Spatial.asText(:centroid)");
List list = (List) query.execute(centroid);
assertEquals("Wrong number of geometries with a given centroid returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a given centroid", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("geom.getCentroid()");
query.setUnique(true);
Geometry centroid_read = (Geometry) query.execute(Long.valueOf(getSamplePolygon(1).getId()));
assertTrue("Given point shoul be centroid of Polygon 1", centroid_read.equalsExact(centroid));
} finally {
tx.commit();
}
}
use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.
the class JtsGeometrySpatialTest method testContains.
public void testContains() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(30 30)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.contains(: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("geom.contains(Spatial.geomFromText('POINT(30 30)', 4326))");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(Long.valueOf(getSamplePolygon(1).getId()));
assertEquals("Polygon 1 should contain the given point", true, equals.booleanValue());
} finally {
tx.commit();
}
}
Aggregations