Search in sources :

Example 1 with Relation

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

the class DataBlockReader method readRelations.

/**
 * Read the relations with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readRelations(Consumer<Relation> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        for (Osmformat.Relation relation : group.getRelationsList()) {
            long id = relation.getId();
            int version = relation.getInfo().getVersion();
            LocalDateTime timestamp = getTimestamp(relation.getInfo().getTimestamp());
            long changeset = relation.getInfo().getChangeset();
            int uid = relation.getInfo().getUid();
            Map<String, String> tags = getTags(relation.getKeysList(), relation.getValsList());
            long mid = 0;
            List<Member> members = new ArrayList<>();
            for (int j = 0; j < relation.getMemidsCount(); j++) {
                mid = mid + relation.getMemids(j);
                String role = getString(relation.getRolesSid(j));
                MemberType type = type(relation.getTypes(j));
                members.add(new Member(mid, type, role));
            }
            Info info = new Info(version, timestamp, changeset, uid);
            consumer.accept(new Relation(id, info, tags, members));
        }
    }
}
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) Relation(com.baremaps.osm.domain.Relation) MemberType(com.baremaps.osm.domain.Member.MemberType) Member(com.baremaps.osm.domain.Member)

Example 2 with Relation

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

the class OsmChangeSpliterator method readRelation.

private Relation readRelation() 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<Member> members = new ArrayList<>();
    reader.nextTag();
    while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
        switch(reader.getLocalName()) {
            case ELEMENT_NAME_TAG:
                readTag(tags);
                break;
            case ELEMENT_NAME_MEMBER:
                readRelationMember(members);
                break;
            default:
                readUnknownElement();
                break;
        }
    }
    return new Relation(id, info, tags, members);
}
Also used : Relation(com.baremaps.osm.domain.Relation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Info(com.baremaps.osm.domain.Info) Member(com.baremaps.osm.domain.Member)

Example 3 with Relation

use of com.baremaps.osm.domain.Relation 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 4 with Relation

use of com.baremaps.osm.domain.Relation 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 5 with Relation

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

the class PostgresRelationRepository method get.

/**
 * {@inheritDoc}
 */
@Override
public List<Relation> get(List<Long> keys) throws RepositoryException {
    if (keys.isEmpty()) {
        return List.of();
    }
    try (Connection connection = dataSource.getConnection();
        PreparedStatement statement = connection.prepareStatement(selectIn)) {
        statement.setArray(1, connection.createArrayOf("int8", keys.toArray()));
        try (ResultSet result = statement.executeQuery()) {
            Map<Long, Relation> values = new HashMap<>();
            while (result.next()) {
                Relation value = getValue(result);
                values.put(value.getId(), value);
            }
            return keys.stream().map(values::get).collect(Collectors.toList());
        }
    } catch (SQLException | JsonProcessingException e) {
        throw new RepositoryException(e);
    }
}
Also used : Relation(com.baremaps.osm.domain.Relation) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RepositoryException(com.baremaps.osm.repository.RepositoryException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Relation (com.baremaps.osm.domain.Relation)15 Node (com.baremaps.osm.domain.Node)8 Way (com.baremaps.osm.domain.Way)8 Member (com.baremaps.osm.domain.Member)6 List (java.util.List)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 ArrayList (java.util.ArrayList)5 Info (com.baremaps.osm.domain.Info)4 BlobStore (com.baremaps.blob.BlobStore)3 MemberType (com.baremaps.osm.domain.Member.MemberType)3 EntityConsumerAdapter (com.baremaps.osm.function.EntityConsumerAdapter)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 Geometry (org.locationtech.jts.geom.Geometry)3 OsmPbfParser (com.baremaps.osm.pbf.OsmPbfParser)2 PostgresCoordinateMap (com.baremaps.osm.postgres.PostgresCoordinateMap)2