Search in sources :

Example 96 with Point

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

the class GeoWaveIndexerTest method testRestrictPredicatesSearch.

@Test
public void testRestrictPredicatesSearch() throws Exception {
    conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(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 97 with Point

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

the class MongoGeoIndexerIT method testRestrictPredicatesSearch.

@Test
public void testRestrictPredicatesSearch() throws Exception {
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
        f.setConf(conf);
        f.init();
        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));
        assertEquals(2, actual.size());
        assertTrue(actual.contains(s3));
        assertTrue(actual.contains(s4));
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) MongoGeoIndexer(org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer) 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 98 with Point

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

the class GeoMongoDBStorageStrategy method getQuery.

public Document getQuery(final GeoQuery queryObj) throws MalformedQueryException {
    final Geometry geo = queryObj.getGeo();
    final GeoQueryType queryType = queryObj.getQueryType();
    if (queryType == GeoQueryType.WITHIN && !(geo instanceof Polygon)) {
        // They can also be applied to MultiPolygons, but those are not supported either.
        throw new MalformedQueryException("Mongo Within operations can only be performed on Polygons.");
    } else if (queryType == GeoQueryType.NEAR && !(geo instanceof Point)) {
        // They can also be applied to Point, but those are not supported either.
        throw new MalformedQueryException("Mongo near operations can only be performed on Points.");
    }
    Document query;
    if (queryType.equals(GeoQueryType.EQUALS)) {
        if (geo.getNumPoints() == 1) {
            final List<Object> circle = new ArrayList<>();
            circle.add(getPoint(geo));
            circle.add(maxDistance);
            final Document polygon = new Document("$centerSphere", circle);
            query = new Document(GEO, new Document(GeoQueryType.WITHIN.getKeyword(), polygon));
        } else {
            query = new Document(GEO, getCorrespondingPoints(geo));
        }
    } else if (queryType.equals(GeoQueryType.NEAR)) {
        final Document geoDoc = new Document("$geometry", getDBPoint(geo));
        if (queryObj.getMaxDistance() != 0) {
            geoDoc.append("$maxDistance", queryObj.getMaxDistance());
        }
        if (queryObj.getMinDistance() != 0) {
            geoDoc.append("$minDistance", queryObj.getMinDistance());
        }
        query = new Document(GEO, new Document(queryType.getKeyword(), geoDoc));
    } else {
        final Document geoDoc = new Document("$geometry", getCorrespondingPoints(geo));
        query = new Document(GEO, new Document(queryType.getKeyword(), geoDoc));
    }
    return query;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ArrayList(java.util.ArrayList) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon) Document(org.bson.Document)

Example 99 with Point

use of com.vividsolutions.jts.geom.Point in project polymap4-core by Polymap4.

the class RFeatureStoreTests method testCreateSimpleSchemaAndFeature.

public void testCreateSimpleSchemaAndFeature() throws Exception {
    log.debug("creating schema...");
    SimpleFeatureType schema = createSimpleSchema();
    ds.createSchema(schema);
    RFeatureStore fs = (RFeatureStore) ds.getFeatureSource(schema.getName());
    assertEquals(0, Iterables.size(iterable(fs.getFeatures())));
    // add feature
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
    Point point = new GeometryBuilder().point(10, 100);
    fb.set("name", "value");
    fb.set("geom", point);
    DefaultFeatureCollection features = new DefaultFeatureCollection();
    features.add(fb.buildFeature(null));
    fs.addFeatures(features);
    // check size
    assertEquals(1, Iterables.size(iterable(fs.getFeatures())));
    // check properties
    fs.getFeatures().accepts(new FeatureVisitor() {

        public void visit(Feature feature) {
            log.debug("Feature: " + feature);
            assertEquals("value", ((SimpleFeature) feature).getAttribute("name"));
            assertEquals(point, ((SimpleFeature) feature).getAttribute("geom"));
            assertEquals(point, ((SimpleFeature) feature).getDefaultGeometry());
        }
    }, null);
    // modify property
    Feature feature = Iterables.getOnlyElement(iterable(fs.getFeatures()));
    fs.modifyFeatures((AttributeDescriptor) feature.getProperty("name").getDescriptor(), "changed", ff.id(Collections.singleton(feature.getIdentifier())));
    Feature feature2 = Iterables.getOnlyElement(iterable(fs.getFeatures()));
    assertEquals("changed", ((SimpleFeature) feature2).getAttribute("name"));
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureVisitor(org.opengis.feature.FeatureVisitor) Point(com.vividsolutions.jts.geom.Point) GeometryBuilder(org.geotools.geometry.jts.GeometryBuilder) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 100 with Point

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

the class JtsGeometrySpatialTest method testTouches.

public void testTouches() throws SQLException, ParseException {
    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 && :point.touches(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(Long.valueOf(getSamplePolygon(1).getId()));
        assertEquals("Polygon 1 should be touched by 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)117 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)42 Geometry (com.vividsolutions.jts.geom.Geometry)41 Coordinate (com.vividsolutions.jts.geom.Coordinate)36 Polygon (com.vividsolutions.jts.geom.Polygon)23 SamplePoint (org.datanucleus.samples.jtsgeometry.SamplePoint)22 LineString (com.vividsolutions.jts.geom.LineString)21 ArrayList (java.util.ArrayList)21 List (java.util.List)19 PersistenceManager (javax.jdo.PersistenceManager)19 Transaction (javax.jdo.Transaction)19 Query (javax.jdo.Query)17 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)16 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)14 HashMap (java.util.HashMap)13 QuadPointDouble (net.osmand.data.QuadPointDouble)12 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)9 Map (java.util.Map)8 Test (org.junit.Test)8 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)7