Search in sources :

Example 56 with Point

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();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 57 with Point

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();
    }
}
Also used : SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 58 with Point

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();
    }
}
Also used : SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 59 with Point

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();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 60 with Point

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();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Aggregations

Point (com.vividsolutions.jts.geom.Point)157 Geometry (com.vividsolutions.jts.geom.Geometry)53 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)49 Coordinate (com.vividsolutions.jts.geom.Coordinate)46 ArrayList (java.util.ArrayList)27 Polygon (com.vividsolutions.jts.geom.Polygon)26 LineString (com.vividsolutions.jts.geom.LineString)25 SamplePoint (org.datanucleus.samples.jtsgeometry.SamplePoint)22 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)19 Transaction (javax.jdo.Transaction)19 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)18 Query (javax.jdo.Query)17 Test (org.junit.Test)17 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)15 HashMap (java.util.HashMap)15 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)12 QuadPointDouble (net.osmand.data.QuadPointDouble)12 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)10 LinearRing (com.vividsolutions.jts.geom.LinearRing)10