Search in sources :

Example 1 with Way

use of com.baremaps.osm.domain.Way in project baremaps by baremaps.

the class DataBlockReader method readWays.

/**
 * Read the ways with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readWays(Consumer<Way> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Way way : group.getWaysList()) {
            long id = way.getId();
            int version = way.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(way.getInfo().getTimestamp());
            long changeset = way.getInfo().getChangeset();
            int uid = way.getInfo().getUid();
            Map<String, String> tags = getTags(way.getKeysList(), way.getValsList());
            long nid = 0;
            List<Long> nodes = new ArrayList<>();
            for (int index = 0; index < way.getRefsCount(); index++) {
                nid = nid + way.getRefs(index);
                nodes.add(nid);
            }
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Way(id, info, tags, nodes));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info) Way(com.baremaps.osm.domain.Way)

Example 2 with Way

use of com.baremaps.osm.domain.Way 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 Way

use of com.baremaps.osm.domain.Way in project baremaps by baremaps.

the class Import method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource datasource = PostgresUtils.datasource(database);
    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);
    Path directory = Files.createTempDirectory(Paths.get("."), "baremaps_");
    Path nodes = Files.createDirectories(directory.resolve("nodes"));
    Path referencesKeys = Files.createDirectories(directory.resolve("references_keys"));
    Path referencesValues = Files.createDirectories(directory.resolve("references_values"));
    LongDataMap<Coordinate> coordinates = new LongAlignedDataDenseMap<>(new LonLatDataType(), new OnDiskMemory(nodes));
    LongDataMap<List<Long>> references = new LongDataSortedMap<>(new AlignedDataList<>(new PairDataType<>(new LongDataType(), new LongDataType()), new OnDiskMemory(referencesKeys)), new DataStore<>(new LongListDataType(), new OnDiskMemory(referencesValues)));
    logger.info("Importing data");
    new ImportService(file, blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid).call();
    logger.info("Done");
    return 0;
}
Also used : PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) HeaderRepository(com.baremaps.osm.repository.HeaderRepository) LongListDataType(com.baremaps.store.type.LongListDataType) Node(com.baremaps.osm.domain.Node) Way(com.baremaps.osm.domain.Way) Relation(com.baremaps.osm.domain.Relation) ImportService(com.baremaps.osm.repository.ImportService) LongDataSortedMap(com.baremaps.store.LongDataSortedMap) LongAlignedDataDenseMap(com.baremaps.store.LongAlignedDataDenseMap) AlignedDataList(com.baremaps.store.AlignedDataList) List(java.util.List) BlobStore(com.baremaps.blob.BlobStore) PairDataType(com.baremaps.store.type.PairDataType) Path(java.nio.file.Path) PostgresWayRepository(com.baremaps.osm.postgres.PostgresWayRepository) OnDiskMemory(com.baremaps.store.memory.OnDiskMemory) LonLatDataType(com.baremaps.store.type.LonLatDataType) DataSource(javax.sql.DataSource) Coordinate(org.locationtech.jts.geom.Coordinate) PostgresNodeRepository(com.baremaps.osm.postgres.PostgresNodeRepository) PostgresRelationRepository(com.baremaps.osm.postgres.PostgresRelationRepository) LongDataType(com.baremaps.store.type.LongDataType) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository)

Example 4 with Way

use of com.baremaps.osm.domain.Way in project baremaps by baremaps.

the class PostgresWayRepository method copy.

/**
 * {@inheritDoc}
 */
public void copy(List<Way> values) throws RepositoryException {
    if (values.isEmpty()) {
        return;
    }
    try (Connection connection = dataSource.getConnection()) {
        PGConnection pgConnection = connection.unwrap(PGConnection.class);
        try (CopyWriter writer = new CopyWriter(new PGCopyOutputStream(pgConnection, copy))) {
            writer.writeHeader();
            for (Way value : values) {
                writer.startRow(8);
                writer.writeLong(value.getId());
                writer.writeInteger(value.getInfo().getVersion());
                writer.writeInteger(value.getInfo().getUid());
                writer.writeLocalDateTime(value.getInfo().getTimestamp());
                writer.writeLong(value.getInfo().getChangeset());
                writer.writeJsonb(toJson(value.getTags()));
                writer.writeLongList(value.getNodes());
                writer.writeGeometry(value.getGeometry());
            }
        }
    } catch (IOException | SQLException e) {
        throw new RepositoryException(e);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) Way(com.baremaps.osm.domain.Way) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Example 5 with Way

use of com.baremaps.osm.domain.Way in project baremaps by baremaps.

the class PostgresWayRepository method getValue.

private Way getValue(ResultSet resultSet) throws SQLException, JsonProcessingException {
    long id = resultSet.getLong(1);
    int version = resultSet.getInt(2);
    int uid = resultSet.getInt(3);
    LocalDateTime timestamp = resultSet.getObject(4, LocalDateTime.class);
    long changeset = resultSet.getLong(5);
    Map<String, String> tags = toMap(resultSet.getString(6));
    List<Long> nodes = new ArrayList<>();
    Array array = resultSet.getArray(7);
    if (array != null) {
        nodes = Arrays.asList((Long[]) array.getArray());
    }
    Geometry geometry = GeometryUtils.deserialize(resultSet.getBytes(8));
    Info info = new Info(version, timestamp, changeset, uid);
    return new Way(id, info, tags, nodes, geometry);
}
Also used : LocalDateTime(java.time.LocalDateTime) Array(java.sql.Array) Geometry(org.locationtech.jts.geom.Geometry) ArrayList(java.util.ArrayList) Info(com.baremaps.osm.domain.Info) Way(com.baremaps.osm.domain.Way)

Aggregations

Way (com.baremaps.osm.domain.Way)15 Node (com.baremaps.osm.domain.Node)8 Relation (com.baremaps.osm.domain.Relation)7 List (java.util.List)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 Info (com.baremaps.osm.domain.Info)4 ArrayList (java.util.ArrayList)4 BlobStore (com.baremaps.blob.BlobStore)3 PostgresHeaderRepository (com.baremaps.osm.postgres.PostgresHeaderRepository)3 PostgresNodeRepository (com.baremaps.osm.postgres.PostgresNodeRepository)3 PostgresRelationRepository (com.baremaps.osm.postgres.PostgresRelationRepository)3 PostgresWayRepository (com.baremaps.osm.postgres.PostgresWayRepository)3 HeaderRepository (com.baremaps.osm.repository.HeaderRepository)3 RepositoryException (com.baremaps.osm.repository.RepositoryException)3 LongListDataType (com.baremaps.store.type.LongListDataType)3 HashMap (java.util.HashMap)3 Header (com.baremaps.osm.domain.Header)2 EntityConsumerAdapter (com.baremaps.osm.function.EntityConsumerAdapter)2 OsmPbfParser (com.baremaps.osm.pbf.OsmPbfParser)2 PostgresCoordinateMap (com.baremaps.osm.postgres.PostgresCoordinateMap)2