use of com.baremaps.osm.domain.Way in project baremaps by baremaps.
the class ImportUpdateDataTest method data.
@Test
@Tag("integration")
void data() throws Exception {
LongDataMap<Coordinate> coordinates = new LongDataOpenHashMap<>(new DataStore<>(new CoordinateDataType(), new OnHeapMemory()));
LongDataMap<List<Long>> references = new LongDataOpenHashMap<>(new DataStore<>(new LongListDataType(), new OnHeapMemory()));
// Import data
new ImportService(new URI("res://simple/data.osm.pbf"), blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
headerRepository.put(new Header(0l, LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0), "res://simple", "", ""));
// Check node importation
assertNull(nodeRepository.get(0l));
assertNotNull(nodeRepository.get(1l));
assertNotNull(nodeRepository.get(2l));
assertNotNull(nodeRepository.get(3l));
assertNull(nodeRepository.get(4l));
// Check way importation
assertNull(wayRepository.get(0l));
assertNotNull(wayRepository.get(1l));
assertNull(wayRepository.get(2l));
// Check relation importation
assertNull(relationRepository.get(0l));
assertNotNull(relationRepository.get(1l));
assertNull(relationRepository.get(2l));
// Check node properties
Node node = nodeRepository.get(1l);
Assertions.assertEquals(1, node.getLon());
Assertions.assertEquals(1, node.getLat());
// Check way properties
Way way = wayRepository.get(1l);
assertNotNull(way);
// Update the database
new UpdateService(blobStore, new PostgresCoordinateMap(dataSource), new PostgresReferenceMap(dataSource), headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
// Check deletions
assertNull(nodeRepository.get(0l));
assertNull(nodeRepository.get(1l));
// Check insertions
assertNotNull(nodeRepository.get(2l));
assertNotNull(nodeRepository.get(3l));
assertNotNull(nodeRepository.get(4l));
}
use of com.baremaps.osm.domain.Way in project baremaps by baremaps.
the class OpenStreetMapBenchmark method entityStream.
@Benchmark
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = 2)
@Measurement(iterations = 5)
public void entityStream() throws IOException {
AtomicLong nodes = new AtomicLong(0);
AtomicLong ways = new AtomicLong(0);
AtomicLong relations = new AtomicLong(0);
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(path))) {
new OsmPbfParser().entities(inputStream).forEach(new EntityConsumerAdapter() {
@Override
public void match(Node node) {
nodes.incrementAndGet();
}
@Override
public void match(Way way) {
ways.incrementAndGet();
}
@Override
public void match(Relation relation) {
relations.incrementAndGet();
}
});
}
}
use of com.baremaps.osm.domain.Way in project baremaps by baremaps.
the class OsmXmlSpliterator method readWay.
private Way readWay() throws XMLStreamException {
long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
Info info = readInfo();
// read the content of the node
Map<String, String> tags = new HashMap<>();
List<Long> members = new ArrayList<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch(reader.getLocalName()) {
case ELEMENT_NAME_TAG:
readTag(tags);
break;
case ELEMENT_NAME_NODE_REFERENCE:
readWayMember(members);
break;
default:
readUnknownElement();
break;
}
}
return new Way(id, info, tags, members);
}
use of com.baremaps.osm.domain.Way in project baremaps by baremaps.
the class OpenStreetMapTest method process.
void process(Stream<Entity> stream, long headerCount, long boundCount, long nodeCount, long wayCount, long relationCount) {
AtomicLong headers = new AtomicLong(0);
AtomicLong bounds = new AtomicLong(0);
AtomicLong nodes = new AtomicLong(0);
AtomicLong ways = new AtomicLong(0);
AtomicLong relations = new AtomicLong(0);
stream.forEach(new EntityConsumer() {
@Override
public void match(Header header) {
assertNotNull(header);
assertEquals("osmium/1.8.0", header.getWritingProgram());
headers.incrementAndGet();
}
@Override
public void match(Bound bound) {
assertNotNull(bound);
assertEquals(43.75169, bound.getMaxLat(), 0.000001);
assertEquals(7.448637, bound.getMaxLon(), 0.000001);
assertEquals(43.72335, bound.getMinLat(), 0.000001);
assertEquals(7.409205, bound.getMinLon(), 0.000001);
bounds.incrementAndGet();
}
@Override
public void match(Node node) {
assertNotNull(node);
nodes.incrementAndGet();
}
@Override
public void match(Way way) {
assertNotNull(way);
ways.incrementAndGet();
}
@Override
public void match(Relation relation) {
assertNotNull(relation);
relations.incrementAndGet();
}
});
assertEquals(headerCount, headers.get());
assertEquals(boundCount, bounds.get());
assertEquals(nodeCount, nodes.get());
assertEquals(wayCount, ways.get());
assertEquals(relationCount, relations.get());
}
use of com.baremaps.osm.domain.Way 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();
}
Aggregations