Search in sources :

Example 1 with BlockEntityConsumer

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;
}
Also used : Entity(com.baremaps.osm.domain.Entity) CreateGeometryConsumer(com.baremaps.osm.geometry.CreateGeometryConsumer) Blob(com.baremaps.blob.Blob) InputStream(java.io.InputStream) BlockEntityConsumer(com.baremaps.osm.function.BlockEntityConsumer) InputStreamProgress(com.baremaps.osm.progress.InputStreamProgress) ProgressLogger(com.baremaps.osm.progress.ProgressLogger) ReprojectEntityConsumer(com.baremaps.osm.geometry.ReprojectEntityConsumer) Block(com.baremaps.osm.domain.Block) DataStoreConsumer(com.baremaps.osm.store.DataStoreConsumer) OsmPbfParser(com.baremaps.osm.pbf.OsmPbfParser)

Example 2 with BlockEntityConsumer

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);
        }
    });
}
Also used : Entity(com.baremaps.osm.domain.Entity) BlockEntityConsumer(com.baremaps.osm.function.BlockEntityConsumer) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) StreamException(com.baremaps.stream.StreamException) StreamException(com.baremaps.stream.StreamException)

Aggregations

Entity (com.baremaps.osm.domain.Entity)2 BlockEntityConsumer (com.baremaps.osm.function.BlockEntityConsumer)2 InputStream (java.io.InputStream)2 Blob (com.baremaps.blob.Blob)1 Block (com.baremaps.osm.domain.Block)1 CreateGeometryConsumer (com.baremaps.osm.geometry.CreateGeometryConsumer)1 ReprojectEntityConsumer (com.baremaps.osm.geometry.ReprojectEntityConsumer)1 OsmPbfParser (com.baremaps.osm.pbf.OsmPbfParser)1 InputStreamProgress (com.baremaps.osm.progress.InputStreamProgress)1 ProgressLogger (com.baremaps.osm.progress.ProgressLogger)1 DataStoreConsumer (com.baremaps.osm.store.DataStoreConsumer)1 StreamException (com.baremaps.stream.StreamException)1 Stream (java.util.stream.Stream)1