use of com.baremaps.osm.geometry.CreateGeometryConsumer 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;
}
use of com.baremaps.osm.geometry.CreateGeometryConsumer 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;
}
Aggregations