Search in sources :

Example 1 with State

use of com.baremaps.osm.domain.State in project baremaps by baremaps.

the class OpenStreetMapTest method monacoStateTxt.

@Test
void monacoStateTxt() throws URISyntaxException, IOException {
    try (InputStream inputStream = MONACO_STATE_TXT.openStream()) {
        State state = new OsmStateParser().state(inputStream);
        assertEquals(2788, state.getSequenceNumber());
        assertEquals(LocalDateTime.parse("2020-11-10T21:42:03"), state.getTimestamp());
    }
}
Also used : BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) InputStream(java.io.InputStream) State(com.baremaps.osm.domain.State) OsmStateParser(com.baremaps.osm.state.OsmStateParser) Test(org.junit.jupiter.api.Test)

Example 2 with State

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

use of com.baremaps.osm.domain.State in project baremaps by baremaps.

the class OsmStateParser method state.

/**
 * Parse an OSM state file.
 *
 * @param input the OpenStreetMap state file
 * @return the state
 */
public State state(InputStream input) throws IOException {
    InputStreamReader reader = new InputStreamReader(input, StandardCharsets.UTF_8);
    Map<String, String> map = new HashMap<>();
    for (String line : CharStreams.readLines(reader)) {
        String[] array = line.split("=");
        if (array.length == 2) {
            map.put(array[0], array[1]);
        }
    }
    long sequenceNumber = Long.parseLong(map.get("sequenceNumber"));
    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
    LocalDateTime timestamp = LocalDateTime.parse(map.get("timestamp").replace("\\", ""), format);
    return new State(sequenceNumber, timestamp);
}
Also used : LocalDateTime(java.time.LocalDateTime) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) State(com.baremaps.osm.domain.State) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

State (com.baremaps.osm.domain.State)3 OsmStateParser (com.baremaps.osm.state.OsmStateParser)2 InputStream (java.io.InputStream)2 Blob (com.baremaps.blob.Blob)1 OsmChangeParser (com.baremaps.osm.change.OsmChangeParser)1 Change (com.baremaps.osm.domain.Change)1 Entity (com.baremaps.osm.domain.Entity)1 Header (com.baremaps.osm.domain.Header)1 ChangeEntityConsumer (com.baremaps.osm.function.ChangeEntityConsumer)1 CreateGeometryConsumer (com.baremaps.osm.geometry.CreateGeometryConsumer)1 ReprojectEntityConsumer (com.baremaps.osm.geometry.ReprojectEntityConsumer)1 InputStreamProgress (com.baremaps.osm.progress.InputStreamProgress)1 ProgressLogger (com.baremaps.osm.progress.ProgressLogger)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 HashMap (java.util.HashMap)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)1