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