Search in sources :

Example 46 with WKTReader

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));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 47 with WKTReader

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());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 48 with WKTReader

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());
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Geometry(com.vividsolutions.jts.geom.Geometry) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 49 with WKTReader

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());
}
Also used : WKTReader(com.vividsolutions.jts.io.WKTReader) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Geometry(com.vividsolutions.jts.geom.Geometry) ArrayList(java.util.ArrayList) List(java.util.List) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 50 with WKTReader

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();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

WKTReader (com.vividsolutions.jts.io.WKTReader)50 Geometry (com.vividsolutions.jts.geom.Geometry)37 ParseException (com.vividsolutions.jts.io.ParseException)19 Test (org.junit.Test)17 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)6 MapLayer (au.org.emii.portal.menu.MapLayer)5 Metacard (ddf.catalog.data.Metacard)4 ArrayList (java.util.ArrayList)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Serializable (java.io.Serializable)3 SimpleDateFormat (java.text.SimpleDateFormat)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 Facet (au.org.ala.legend.Facet)2 UserDataDTO (au.org.ala.spatial.dto.UserDataDTO)2 WKTReducedDTO (au.org.ala.spatial.dto.WKTReducedDTO)2 MapComposer (au.org.emii.portal.composer.MapComposer)2 com.vividsolutions.jts.geom (com.vividsolutions.jts.geom)2 Envelope (com.vividsolutions.jts.geom.Envelope)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)2