Search in sources :

Example 1 with OsmXmlParser

use of com.baremaps.osm.xml.OsmXmlParser 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 2 with OsmXmlParser

use of com.baremaps.osm.xml.OsmXmlParser 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)2 OsmXmlParser (com.baremaps.osm.xml.OsmXmlParser)2 InputStream (java.io.InputStream)2 Test (org.junit.jupiter.api.Test)2 Node (com.baremaps.osm.domain.Node)1 Relation (com.baremaps.osm.domain.Relation)1 Way (com.baremaps.osm.domain.Way)1 MockLongDataMap (com.baremaps.osm.store.MockLongDataMap)1 LongDataMap (com.baremaps.store.LongDataMap)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Disabled (org.junit.jupiter.api.Disabled)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Geometry (org.locationtech.jts.geom.Geometry)1