use of com.baremaps.osm.function.BlockEntityConsumer in project baremaps by baremaps.
the class ImportService method call.
@Override
public Void call() throws Exception {
Consumer<Block> cacheBlock = new DataStoreConsumer(coordinates, references);
Consumer<Entity> createGeometry = new CreateGeometryConsumer(coordinates, references);
Consumer<Entity> reprojectGeometry = new ReprojectEntityConsumer(4326, srid);
Consumer<Block> prepareGeometries = new BlockEntityConsumer(createGeometry.andThen(reprojectGeometry));
Function<Block, Block> prepareBlock = consumeThenReturn(cacheBlock.andThen(prepareGeometries));
Consumer<Block> saveBlock = new SaveBlockConsumer(headerRepository, nodeRepository, wayRepository, relationRepository);
Blob blob = blobStore.get(uri);
ProgressLogger progressLogger = new ProgressLogger(blob.getContentLength(), 5000);
try (InputStream inputStream = new InputStreamProgress(blob.getInputStream(), progressLogger)) {
batch(new OsmPbfParser().blocks(inputStream).map(prepareBlock)).forEach(saveBlock);
}
return null;
}
use of com.baremaps.osm.function.BlockEntityConsumer in project baremaps by baremaps.
the class OsmPbfParser method entities.
/**
* Creates an ordered stream of entities.
*
* @param inputStream an osm pbf {@link InputStream}
* @return a stream of blocks
*/
public Stream<Entity> entities(InputStream inputStream) {
return blocks(inputStream).flatMap(block -> {
try {
Stream.Builder<Entity> entities = Stream.builder();
block.visit(new BlockEntityConsumer(entities::add));
return entities.build();
} catch (Exception e) {
throw new StreamException(e);
}
});
}
Aggregations