Search in sources :

Example 1 with MockLongDataMap

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