Search in sources :

Example 1 with DiffService

use of com.baremaps.osm.repository.DiffService in project baremaps by baremaps.

the class ImportUpdateMonacoTest method monaco.

@Test
@Tag("integration")
void monaco() 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://monaco/monaco-210801.osm.pbf"), blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(3047l, headerRepository.selectLatest().getReplicationSequenceNumber());
    // Fix the replicationUrl so that we can update the database with local files
    headerRepository.delete(3047l);
    headerRepository.put(new Header(3047l, LocalDateTime.of(2021, 8, 01, 20, 21, 41, 0), "res://monaco/monaco-updates", "", ""));
    coordinates = new PostgresCoordinateMap(dataSource);
    references = new PostgresReferenceMap(dataSource);
    // Generate the diff and update the database
    long replicationSequenceNumber = headerRepository.selectLatest().getReplicationSequenceNumber();
    while (replicationSequenceNumber < 3075) {
        new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call();
        new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
        long nextReplicationSequenceNumber = headerRepository.selectLatest().getReplicationSequenceNumber();
        assertEquals(replicationSequenceNumber + 1, nextReplicationSequenceNumber);
        replicationSequenceNumber = nextReplicationSequenceNumber;
    }
}
Also used : LongListDataType(com.baremaps.store.type.LongListDataType) DiffService(com.baremaps.osm.repository.DiffService) URI(java.net.URI) ImportService(com.baremaps.osm.repository.ImportService) Header(com.baremaps.osm.domain.Header) UpdateService(com.baremaps.osm.repository.UpdateService) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateDataType(com.baremaps.store.type.CoordinateDataType) List(java.util.List) LongDataOpenHashMap(com.baremaps.store.LongDataOpenHashMap) OnHeapMemory(com.baremaps.store.memory.OnHeapMemory) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 2 with DiffService

use of com.baremaps.osm.repository.DiffService in project baremaps by baremaps.

the class Diff method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource datasource = PostgresUtils.datasource(database);
    LongDataMap<Coordinate> coordinates = new PostgresCoordinateMap(datasource);
    LongDataMap<List<Long>> references = new PostgresReferenceMap(datasource);
    HeaderRepository headerRepository = new PostgresHeaderRepository(datasource);
    Repository<Long, Node> nodeRepository = new PostgresNodeRepository(datasource);
    Repository<Long, Way> wayRepository = new PostgresWayRepository(datasource);
    Repository<Long, Relation> relationRepository = new PostgresRelationRepository(datasource);
    logger.info("Saving diff");
    Path tmpTiles = Files.createFile(Paths.get("diff.tmp"));
    try (PrintWriter printWriter = new PrintWriter(Files.newBufferedWriter(tmpTiles))) {
        new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid, zoom).call();
    }
    blobStore.put(this.tiles, Blob.builder().withContentLength(Files.size(tmpTiles)).withInputStream(Files.newInputStream(tmpTiles)).build());
    Files.deleteIfExists(tmpTiles);
    logger.info("Done");
    return 0;
}
Also used : Path(java.nio.file.Path) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) HeaderRepository(com.baremaps.osm.repository.HeaderRepository) PostgresWayRepository(com.baremaps.osm.postgres.PostgresWayRepository) PostgresReferenceMap(com.baremaps.osm.postgres.PostgresReferenceMap) Node(com.baremaps.osm.domain.Node) DiffService(com.baremaps.osm.repository.DiffService) PostgresCoordinateMap(com.baremaps.osm.postgres.PostgresCoordinateMap) Way(com.baremaps.osm.domain.Way) DataSource(javax.sql.DataSource) Relation(com.baremaps.osm.domain.Relation) Coordinate(org.locationtech.jts.geom.Coordinate) PostgresNodeRepository(com.baremaps.osm.postgres.PostgresNodeRepository) List(java.util.List) PostgresRelationRepository(com.baremaps.osm.postgres.PostgresRelationRepository) BlobStore(com.baremaps.blob.BlobStore) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) PrintWriter(java.io.PrintWriter)

Example 3 with DiffService

use of com.baremaps.osm.repository.DiffService in project baremaps by baremaps.

the class ImportUpdateLiechtensteinTest method liechtenstein.

@Test
@Tag("integration")
void liechtenstein() 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://liechtenstein/liechtenstein.osm.pbf"), blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2434l, headerRepository.selectLatest().getReplicationSequenceNumber());
    // Fix the replicationUrl so that we can update the database with local files
    headerRepository.put(new Header(2434l, LocalDateTime.of(2019, 11, 18, 21, 19, 5, 0), "res://liechtenstein", "", ""));
    coordinates = new PostgresCoordinateMap(dataSource);
    references = new PostgresReferenceMap(dataSource);
    assertEquals(0, new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call().size());
    // Update the database
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2435l, headerRepository.selectLatest().getReplicationSequenceNumber());
    assertEquals(2, new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call().size());
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2436l, headerRepository.selectLatest().getReplicationSequenceNumber());
    assertEquals(0, new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call().size());
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2437l, headerRepository.selectLatest().getReplicationSequenceNumber());
}
Also used : LongListDataType(com.baremaps.store.type.LongListDataType) DiffService(com.baremaps.osm.repository.DiffService) URI(java.net.URI) ImportService(com.baremaps.osm.repository.ImportService) Header(com.baremaps.osm.domain.Header) UpdateService(com.baremaps.osm.repository.UpdateService) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateDataType(com.baremaps.store.type.CoordinateDataType) List(java.util.List) LongDataOpenHashMap(com.baremaps.store.LongDataOpenHashMap) OnHeapMemory(com.baremaps.store.memory.OnHeapMemory) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

DiffService (com.baremaps.osm.repository.DiffService)3 List (java.util.List)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 Header (com.baremaps.osm.domain.Header)2 ImportService (com.baremaps.osm.repository.ImportService)2 UpdateService (com.baremaps.osm.repository.UpdateService)2 LongDataOpenHashMap (com.baremaps.store.LongDataOpenHashMap)2 OnHeapMemory (com.baremaps.store.memory.OnHeapMemory)2 CoordinateDataType (com.baremaps.store.type.CoordinateDataType)2 LongListDataType (com.baremaps.store.type.LongListDataType)2 URI (java.net.URI)2 Tag (org.junit.jupiter.api.Tag)2 Test (org.junit.jupiter.api.Test)2 BlobStore (com.baremaps.blob.BlobStore)1 Node (com.baremaps.osm.domain.Node)1 Relation (com.baremaps.osm.domain.Relation)1 Way (com.baremaps.osm.domain.Way)1 PostgresCoordinateMap (com.baremaps.osm.postgres.PostgresCoordinateMap)1 PostgresHeaderRepository (com.baremaps.osm.postgres.PostgresHeaderRepository)1 PostgresNodeRepository (com.baremaps.osm.postgres.PostgresNodeRepository)1