Search in sources :

Example 1 with ProgressLogger

use of com.baremaps.osm.progress.ProgressLogger in project baremaps by baremaps.

the class UpdateService method call.

@Override
public Void call() throws Exception {
    Header header = headerRepository.selectLatest();
    String replicationUrl = header.getReplicationUrl();
    Long sequenceNumber = header.getReplicationSequenceNumber() + 1;
    Consumer<Entity> createGeometry = new CreateGeometryConsumer(coordinates, references);
    Consumer<Entity> reprojectGeometry = new ReprojectEntityConsumer(4326, srid);
    Consumer<Change> prepareGeometries = new ChangeEntityConsumer(createGeometry.andThen(reprojectGeometry));
    Function<Change, Change> prepareChange = consumeThenReturn(prepareGeometries);
    Consumer<Change> saveChange = new SaveChangeConsumer(nodeRepository, wayRepository, relationRepository);
    URI changeUri = resolve(replicationUrl, sequenceNumber, "osc.gz");
    Blob changeBlob = blobStore.get(changeUri);
    ProgressLogger progressLogger = new ProgressLogger(changeBlob.getContentLength(), 5000);
    try (InputStream blobInputStream = changeBlob.getInputStream();
        InputStream progressInputStream = new InputStreamProgress(blobInputStream, progressLogger);
        InputStream gzipInputStream = new GZIPInputStream(progressInputStream)) {
        new OsmChangeParser().changes(gzipInputStream).map(prepareChange).forEach(saveChange);
    }
    URI stateUri = resolve(replicationUrl, sequenceNumber, "state.txt");
    Blob stateBlob = blobStore.get(stateUri);
    try (InputStream stateInputStream = stateBlob.getInputStream()) {
        State state = new OsmStateParser().state(stateInputStream);
        headerRepository.put(new Header(state.getSequenceNumber(), state.getTimestamp(), header.getReplicationUrl(), header.getSource(), header.getWritingProgram()));
    }
    return null;
}
Also used : Entity(com.baremaps.osm.domain.Entity) CreateGeometryConsumer(com.baremaps.osm.geometry.CreateGeometryConsumer) Blob(com.baremaps.blob.Blob) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) InputStreamProgress(com.baremaps.osm.progress.InputStreamProgress) ProgressLogger(com.baremaps.osm.progress.ProgressLogger) Change(com.baremaps.osm.domain.Change) URI(java.net.URI) GZIPInputStream(java.util.zip.GZIPInputStream) ChangeEntityConsumer(com.baremaps.osm.function.ChangeEntityConsumer) Header(com.baremaps.osm.domain.Header) State(com.baremaps.osm.domain.State) ReprojectEntityConsumer(com.baremaps.osm.geometry.ReprojectEntityConsumer) OsmChangeParser(com.baremaps.osm.change.OsmChangeParser) OsmStateParser(com.baremaps.osm.state.OsmStateParser)

Example 2 with ProgressLogger

use of com.baremaps.osm.progress.ProgressLogger 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 3 with ProgressLogger

use of com.baremaps.osm.progress.ProgressLogger in project baremaps by baremaps.

the class DiffService method call.

@Override
public List<Tile> call() throws Exception {
    logger.info("Importing changes");
    Header header = headerRepository.selectLatest();
    String replicationUrl = header.getReplicationUrl();
    Long sequenceNumber = header.getReplicationSequenceNumber() + 1;
    URI changeUri = resolve(replicationUrl, sequenceNumber, "osc.gz");
    Blob blob = blobStore.get(changeUri);
    ProgressLogger progressLogger = new ProgressLogger(blob.getContentLength(), 5000);
    ProjectionTransformer projectionTransformer = new ProjectionTransformer(srid, 4326);
    try (InputStream changesInputStream = new GZIPInputStream(new InputStreamProgress(blob.getInputStream(), progressLogger))) {
        return new OsmChangeParser().changes(changesInputStream).flatMap(this::geometriesForChange).map(projectionTransformer::transform).flatMap(this::tilesForGeometry).distinct().collect(Collectors.toList());
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Blob(com.baremaps.blob.Blob) Header(com.baremaps.osm.domain.Header) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) InputStreamProgress(com.baremaps.osm.progress.InputStreamProgress) ProgressLogger(com.baremaps.osm.progress.ProgressLogger) OsmChangeParser(com.baremaps.osm.change.OsmChangeParser) URI(java.net.URI) ProjectionTransformer(com.baremaps.osm.geometry.ProjectionTransformer)

Aggregations

Blob (com.baremaps.blob.Blob)3 InputStreamProgress (com.baremaps.osm.progress.InputStreamProgress)3 ProgressLogger (com.baremaps.osm.progress.ProgressLogger)3 InputStream (java.io.InputStream)3 OsmChangeParser (com.baremaps.osm.change.OsmChangeParser)2 Entity (com.baremaps.osm.domain.Entity)2 Header (com.baremaps.osm.domain.Header)2 CreateGeometryConsumer (com.baremaps.osm.geometry.CreateGeometryConsumer)2 ReprojectEntityConsumer (com.baremaps.osm.geometry.ReprojectEntityConsumer)2 URI (java.net.URI)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 Block (com.baremaps.osm.domain.Block)1 Change (com.baremaps.osm.domain.Change)1 State (com.baremaps.osm.domain.State)1 BlockEntityConsumer (com.baremaps.osm.function.BlockEntityConsumer)1 ChangeEntityConsumer (com.baremaps.osm.function.ChangeEntityConsumer)1 ProjectionTransformer (com.baremaps.osm.geometry.ProjectionTransformer)1 OsmPbfParser (com.baremaps.osm.pbf.OsmPbfParser)1 OsmStateParser (com.baremaps.osm.state.OsmStateParser)1 DataStoreConsumer (com.baremaps.osm.store.DataStoreConsumer)1