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);
}
}
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<>()));
}
}
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;
}
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);
}
}
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();
}
Aggregations