Search in sources :

Example 1 with Entity

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

the class OpenStreetMapTest method monacoOsmPbf.

@Test
void monacoOsmPbf() throws IOException, URISyntaxException {
    try (InputStream inputStream = MONACO_OSM_PBF.openStream()) {
        Stream<Entity> stream = new OsmPbfParser().entities(inputStream);
        process(stream, 1, 1, 25002, 4018, 243);
    }
}
Also used : Entity(com.baremaps.osm.domain.Entity) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) InputStream(java.io.InputStream) OsmPbfParser(com.baremaps.osm.pbf.OsmPbfParser) Test(org.junit.jupiter.api.Test)

Example 2 with Entity

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

the class XmlEntitySpliteratorTest method tryAdvance.

@Test
void tryAdvance() throws IOException {
    try (InputStream input = DATA_OSM_XML.openStream()) {
        Spliterator<Entity> spliterator = new OsmXmlSpliterator(input);
        spliterator.forEachRemaining(fileBlock -> assertNotNull(fileBlock));
        assertFalse(spliterator.tryAdvance(new HoldingConsumer<>()));
    }
}
Also used : Entity(com.baremaps.osm.domain.Entity) InputStream(java.io.InputStream) HoldingConsumer(com.baremaps.stream.HoldingConsumer) Test(org.junit.jupiter.api.Test)

Example 3 with Entity

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

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

the class OpenStreetMapTest method monacoOsmBz2.

@Test
void monacoOsmBz2() throws IOException, URISyntaxException {
    try (InputStream inputStream = new BZip2CompressorInputStream(MONACO_OSM_BZ2.openStream())) {
        Stream<Entity> stream = new OsmXmlParser().entities(inputStream);
        process(stream, 1, 1, 24951, 4015, 243);
    }
}
Also used : Entity(com.baremaps.osm.domain.Entity) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) InputStream(java.io.InputStream) OsmXmlParser(com.baremaps.osm.xml.OsmXmlParser) Test(org.junit.jupiter.api.Test)

Example 5 with Entity

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

the class RelationGeometryTest method handleRelation.

Geometry handleRelation(String file) throws IOException {
    InputStream input = new GZIPInputStream(this.getClass().getResourceAsStream(file));
    List<Entity> entities = new OsmXmlParser().entities(input).collect(Collectors.toList());
    LongDataMap<Coordinate> coordinates = new MockLongDataMap<>(entities.stream().filter(e -> e instanceof Node).map(e -> (Node) e).collect(Collectors.toMap(n -> n.getId(), n -> new Coordinate(n.getLon(), n.getLat()))));
    LongDataMap<List<Long>> references = new MockLongDataMap<>(entities.stream().filter(e -> e instanceof Way).map(e -> (Way) e).collect(Collectors.toMap(w -> w.getId(), w -> w.getNodes())));
    Relation relation = entities.stream().filter(e -> e instanceof Relation).map(e -> (Relation) e).findFirst().get();
    new CreateGeometryConsumer(coordinates, references).match(relation);
    return relation.getGeometry();
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) GZIPInputStream(java.util.zip.GZIPInputStream) Relation(com.baremaps.osm.domain.Relation) LongDataMap(com.baremaps.store.LongDataMap) Coordinate(org.locationtech.jts.geom.Coordinate) IOException(java.io.IOException) Disabled(org.junit.jupiter.api.Disabled) Way(com.baremaps.osm.domain.Way) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) Entity(com.baremaps.osm.domain.Entity) OsmXmlParser(com.baremaps.osm.xml.OsmXmlParser) Node(com.baremaps.osm.domain.Node) Geometry(org.locationtech.jts.geom.Geometry) MockLongDataMap(com.baremaps.osm.store.MockLongDataMap) InputStream(java.io.InputStream) Entity(com.baremaps.osm.domain.Entity) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) OsmXmlParser(com.baremaps.osm.xml.OsmXmlParser) Node(com.baremaps.osm.domain.Node) Way(com.baremaps.osm.domain.Way) GZIPInputStream(java.util.zip.GZIPInputStream) Relation(com.baremaps.osm.domain.Relation) Coordinate(org.locationtech.jts.geom.Coordinate) List(java.util.List) MockLongDataMap(com.baremaps.osm.store.MockLongDataMap)

Aggregations

Entity (com.baremaps.osm.domain.Entity)9 InputStream (java.io.InputStream)8 Test (org.junit.jupiter.api.Test)5 Blob (com.baremaps.blob.Blob)2 Change (com.baremaps.osm.domain.Change)2 BlockEntityConsumer (com.baremaps.osm.function.BlockEntityConsumer)2 CreateGeometryConsumer (com.baremaps.osm.geometry.CreateGeometryConsumer)2 ReprojectEntityConsumer (com.baremaps.osm.geometry.ReprojectEntityConsumer)2 OsmPbfParser (com.baremaps.osm.pbf.OsmPbfParser)2 InputStreamProgress (com.baremaps.osm.progress.InputStreamProgress)2 ProgressLogger (com.baremaps.osm.progress.ProgressLogger)2 OsmXmlParser (com.baremaps.osm.xml.OsmXmlParser)2 StreamException (com.baremaps.stream.StreamException)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)2 OsmChangeParser (com.baremaps.osm.change.OsmChangeParser)1 Block (com.baremaps.osm.domain.Block)1 ChangeType (com.baremaps.osm.domain.Change.ChangeType)1 Header (com.baremaps.osm.domain.Header)1 Node (com.baremaps.osm.domain.Node)1