Search in sources :

Example 1 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method split.

private List<Tuple2<GeoJsonChunkMeta, JsonObject>> split(String file) throws IOException {
    byte[] json = IOUtils.toByteArray(GeoJsonSplitterTest.class.getResource(file));
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = new ArrayList<>();
    StringWindow window = new StringWindow();
    GeoJsonSplitter splitter = new GeoJsonSplitter(window);
    Observable.just(json).map(Buffer::buffer).doOnNext(window::append).lift(new JsonParserOperator()).flatMap(splitter::onEventObservable).toBlocking().forEach(result -> {
        JsonObject o = new JsonObject(result.getChunk());
        chunks.add(Tuple.tuple((GeoJsonChunkMeta) result.getMeta(), o));
    });
    return chunks;
}
Also used : StringWindow(io.georocket.util.StringWindow) Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) JsonParserOperator(io.georocket.util.JsonParserOperator)

Example 2 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method multiPolygon.

/**
 * Test if a MultiPolygon can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void multiPolygon() throws IOException {
    String filename = "multipolygon.json";
    long size = getFileSize(filename);
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(1, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertNull(m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(size, m1.getEnd());
    assertEquals("MultiPolygon", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("MultiPolygon", o1.getString("type"));
    assertEquals(1, o1.getJsonArray("coordinates").size());
    assertEquals(1, o1.getJsonArray("coordinates").getJsonArray(0).size());
    assertEquals(13, o1.getJsonArray("coordinates").getJsonArray(0).getJsonArray(0).size());
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 3 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method geometryCollection.

/**
 * Test if a GeometryCollection can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void geometryCollection() throws IOException {
    String filename = "geometrycollection.json";
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(2, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertEquals("geometries", m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(132, m1.getEnd());
    assertEquals("Point", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("Point", o1.getString("type"));
    assertEquals(8.6599, o1.getJsonArray("coordinates").getDouble(0).doubleValue(), 0.00001);
    Tuple2<GeoJsonChunkMeta, JsonObject> t2 = chunks.get(1);
    GeoJsonChunkMeta m2 = t2.v1;
    assertEquals("geometries", m2.getParentFieldName());
    assertEquals(0, m2.getStart());
    assertEquals(132, m2.getEnd());
    assertEquals("Point", m2.getType());
    JsonObject o2 = t2.v2;
    assertEquals("Point", o2.getString("type"));
    assertEquals(8.6576, o2.getJsonArray("coordinates").getDouble(0).doubleValue(), 0.00001);
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 4 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class GeoJsonSplitterTest method polygon.

/**
 * Test if a Polygon can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void polygon() throws IOException {
    String filename = "polygon.json";
    long size = getFileSize(filename);
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(1, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertNull(m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(size, m1.getEnd());
    assertEquals("Polygon", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("Polygon", o1.getString("type"));
    assertEquals(1, o1.getJsonArray("coordinates").size());
    assertEquals(13, o1.getJsonArray("coordinates").getJsonArray(0).size());
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 5 with GeoJsonChunkMeta

use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.

the class MultiMergerTest method geoJsonOneGeometry.

/**
 * Test if one GeoJSON geometry is rendered directly
 * @param context the Vert.x test context
 */
@Test
public void geoJsonOneGeometry(TestContext context) {
    String strChunk1 = "{\"type\":\"Polygon\"}";
    Buffer chunk1 = Buffer.buffer(strChunk1);
    GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Polygon", "geometries", 0, chunk1.length());
    doMerge(context, Observable.just(chunk1), Observable.just(cm1), strChunk1);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) Test(org.junit.Test)

Aggregations

GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)28 Test (org.junit.Test)27 Buffer (io.vertx.core.buffer.Buffer)17 JsonObject (io.vertx.core.json.JsonObject)11 Tuple2 (org.jooq.lambda.tuple.Tuple2)11 ChunkReadStream (io.georocket.storage.ChunkReadStream)5 BufferWriteStream (io.georocket.util.io.BufferWriteStream)5 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)5 Async (io.vertx.ext.unit.Async)5 TestContext (io.vertx.ext.unit.TestContext)5 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Rule (org.junit.Rule)5 RunWith (org.junit.runner.RunWith)5 Observable (rx.Observable)5 ChunkMeta (io.georocket.storage.ChunkMeta)2 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)2 XMLStartElement (io.georocket.util.XMLStartElement)2 Arrays (java.util.Arrays)2