use of com.vividsolutions.jts.io.WKTReader in project GeoGig by boundlessgeo.
the class GeometryDiffTest method testConflict.
@Test
public void testConflict() throws Exception {
Geometry oldGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
Geometry newGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45),(20 35, 45 10, 20 35))");
GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom));
Geometry newGeom2 = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(20 35, 45 10, 30 5, 10 30, 20 35))");
GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom2));
assertTrue(diff.conflicts(diff2));
}
use of com.vividsolutions.jts.io.WKTReader in project GeoGig by boundlessgeo.
the class GeometryDiffTest method testNoConflictRemovingPoints.
@Test
public void testNoConflictRemovingPoints() throws Exception {
Geometry oldGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
Geometry newGeom = new WKTReader().read("MULTILINESTRING ((40 40, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom));
Geometry newGeom2 = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))");
GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom2));
assertFalse(diff.conflicts(diff2));
Optional<?> merged = diff2.applyOn(Optional.of(newGeom));
assertTrue(merged.isPresent());
Geometry mergedGeom = (Geometry) merged.get();
assertEquals("MULTILINESTRING ((40 40, 45 30, 40 40), (20 35, 45 10, 31 6, 10 30, 20 35))", mergedGeom.toText());
}
use of com.vividsolutions.jts.io.WKTReader in project ignite by apache.
the class H2IndexingAbstractGeoSelfTest method checkLocalQuery.
/**
* Check local query.
*
* @throws ParseException If failed.
*/
private void checkLocalQuery() throws ParseException {
IgniteCache<Integer, Enemy> c1 = grid(0).cache("enemy");
IgniteCache<Integer, EnemyCamp> c2 = grid(0).cache("camp");
final Geometry lethalArea = new WKTReader().read("POLYGON((30 30, 30 70, 70 70, 70 30, 30 30))");
Set<Integer> localCampsIDs = new HashSet<>();
for (Cache.Entry<Integer, EnemyCamp> e : c2.localEntries()) localCampsIDs.add(e.getKey());
int expectedEnemies = 0;
for (Cache.Entry<Integer, Enemy> e : c1.localEntries()) {
final Integer campID = e.getValue().campId;
if (localCampsIDs.contains(campID)) {
final EnemyCamp camp = c2.get(campID);
if (lethalArea.covers(camp.coords))
expectedEnemies++;
}
}
final SqlFieldsQuery query = new SqlFieldsQuery("select e._val, c._val from \"enemy\".Enemy e, " + "\"camp\".EnemyCamp c where e.campId = c._key and c.coords && ?").setArgs(lethalArea);
List<List<?>> result = c1.query(query.setLocal(true)).getAll();
assertEquals(expectedEnemies, result.size());
}
use of com.vividsolutions.jts.io.WKTReader in project ignite by apache.
the class H2IndexingAbstractGeoSelfTest method checkDistributedQuery.
/**
* Check distributed query.
*
* @throws ParseException If failed.
*/
private void checkDistributedQuery() throws ParseException {
IgniteCache<Integer, Enemy> c1 = grid(0).cache("enemy");
IgniteCache<Integer, EnemyCamp> c2 = grid(0).cache("camp");
final Geometry lethalArea = new WKTReader().read("POLYGON((30 30, 30 70, 70 70, 70 30, 30 30))");
int expectedEnemies = 0;
for (Cache.Entry<Integer, Enemy> e : c1) {
final Integer campID = e.getValue().campId;
if (30 <= campID && campID < ENEMYCAMP_SAMPLES_COUNT) {
final EnemyCamp camp = c2.get(campID);
if (lethalArea.covers(camp.coords))
expectedEnemies++;
}
}
final SqlFieldsQuery query = new SqlFieldsQuery("select e._val, c._val from \"enemy\".Enemy e, " + "\"camp\".EnemyCamp c where e.campId = c._key and c.coords && ?").setArgs(lethalArea);
List<List<?>> result = c1.query(query.setDistributedJoins(true)).getAll();
assertEquals(expectedEnemies, result.size());
}
use of com.vividsolutions.jts.io.WKTReader in project ignite by apache.
the class H2IndexingAbstractGeoSelfTest method testPrimitiveGeometry.
/**
* @throws Exception If failed.
*/
public void testPrimitiveGeometry() throws Exception {
IgniteCache<Long, Geometry> cache = createCache("geom", true, Long.class, Geometry.class);
try {
WKTReader r = new WKTReader();
for (long i = 0; i < 100; i++) cache.put(i, r.read("POINT(" + i + " " + i + ")"));
String plan = cache.query(new SqlFieldsQuery("explain select _key from Geometry where _val && ?").setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))")).setLocal(true)).getAll().get(0).get(0).toString().toLowerCase();
assertTrue("__ explain: " + plan, plan.contains("_val_idx"));
} finally {
cache.destroy();
}
}
Aggregations