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));
}
}
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));
}
}
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;
}
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"));
}
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();
}
}
Aggregations