Search in sources :

Example 51 with Point

use of com.vividsolutions.jts.geom.Point in project eol-globi-data by jhpoelen.

the class EcoregionFinderImplTest method longhurstProvince.

@Test
public void longhurstProvince() throws EcoregionFinderException {
    EcoregionFinder finder = new EcoregionFinderFactoryImpl().createEcoregionFinder(EcoregionType.LONGHURST_BIOGEOGRAPHICAL_PROVINCES);
    Point aPointNearFlorida = GeoUtil.getPoint(26.863281, -82.756349);
    Map<String, Object> props = findEcoregionProperties(aPointNearFlorida, finder);
    assertThat(props.toString(), startsWith("{ProvCode=CARB, ProvDescr=Trades - Caribbean Province, the_geom=MULTIPOLYGON"));
    Collection<Ecoregion> ecoregion = finder.findEcoregion(26.863281, -82.756349);
    Ecoregion region = getFirst(ecoregion);
    assertThat(region.getName(), is("Trades - Caribbean Province"));
    assertThat(region.getId(), is("LBP:CARB"));
    assertThat(region.getPath(), is("Trades - Caribbean Province"));
}
Also used : Point(com.vividsolutions.jts.geom.Point) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 52 with Point

use of com.vividsolutions.jts.geom.Point in project incubator-rya by apache.

the class GeoIndexerTest method testRestrictPredicatesSearch.

@Test
public void testRestrictPredicatesSearch() throws Exception {
    conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);
        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Point point = gf.createPoint(new Coordinate(10, 10));
        final Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final IRI invalidPredicate = GeoConstants.GEO_AS_WKT;
        // These should not be stored because they are not in the predicate list
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj1"), invalidPredicate, pointValue)));
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj2"), invalidPredicate, pointValue)));
        final IRI pred1 = vf.createIRI("pred:1");
        final IRI pred2 = vf.createIRI("pred:2");
        // These should be stored because they are in the predicate list
        final Statement s3 = vf.createStatement(vf.createIRI("foo:subj3"), pred1, pointValue);
        final Statement s4 = vf.createStatement(vf.createIRI("foo:subj4"), pred2, pointValue);
        f.storeStatement(convertStatement(s3));
        f.storeStatement(convertStatement(s4));
        // This should not be stored because the object is not valid wkt
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)"))));
        // This should not be stored because the object is not a literal
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj6"), pred1, vf.createIRI("p:Point(10 10)"))));
        f.flush();
        final Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
        Assert.assertEquals(2, actual.size());
        Assert.assertTrue(actual.contains(s3));
        Assert.assertTrue(actual.contains(s4));
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Coordinate(com.vividsolutions.jts.geom.Coordinate) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) Statement(org.eclipse.rdf4j.model.Statement) Value(org.eclipse.rdf4j.model.Value) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 53 with Point

use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.

the class JtsGeometryMySQLTest method testMbrTouches.

public void testMbrTouches() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = (Point) wktReader.read("POINT(75 75)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrTouches(: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)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) Point(com.vividsolutions.jts.geom.Point)

Example 54 with Point

use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.

the class JtsGeometrySpatialTest method testGeomFromWKB.

public void testGeomFromWKB() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point geom = (Point) wktReader.read("POINT(10 10)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.equals(Spatial.geomFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
        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();
    }
}
Also used : 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 55 with Point

use of com.vividsolutions.jts.geom.Point in project tests by datanucleus.

the class JtsGeometrySpatialTest method testPointFromWKB.

public void testPointFromWKB() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point geom = (Point) wktReader.read("POINT(75 75)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.equals(Spatial.pointFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("Point 2 should be in the list of geometries with a given wkb", list.contains(getSamplePoint(2)));
    } finally {
        tx.commit();
    }
}
Also used : 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)

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