Search in sources :

Example 1 with Member

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

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

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

the class OsmChangeSpliterator method readRelationMember.

private void readRelationMember(List<Member> members) throws XMLStreamException {
    long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_REF));
    MemberType type = Member.MemberType.valueOf(reader.getAttributeValue(null, ATTRIBUTE_NAME_TYPE).toUpperCase());
    String role = reader.getAttributeValue(null, ATTRIBUTE_NAME_ROLE);
    members.add(new Member(id, type, role));
    reader.nextTag();
    reader.nextTag();
}
Also used : MemberType(com.baremaps.osm.domain.Member.MemberType) Member(com.baremaps.osm.domain.Member)

Example 4 with Member

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

the class OsmXmlSpliterator method readRelationMember.

private void readRelationMember(List<Member> members) throws XMLStreamException {
    long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_REF));
    MemberType type = Member.MemberType.valueOf(reader.getAttributeValue(null, ATTRIBUTE_NAME_TYPE).toUpperCase());
    String role = reader.getAttributeValue(null, ATTRIBUTE_NAME_ROLE);
    members.add(new Member(id, type, role));
    reader.nextTag();
    reader.nextTag();
}
Also used : MemberType(com.baremaps.osm.domain.Member.MemberType) Member(com.baremaps.osm.domain.Member)

Example 5 with Member

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

the class PostgresRelationRepository method copy.

/**
 * {@inheritDoc}
 */
@Override
public void copy(List<Relation> 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 (Relation value : values) {
                writer.startRow(10);
                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.getMembers().stream().map(Member::getRef).collect(Collectors.toList()));
                writer.writeIntegerList(value.getMembers().stream().map(Member::getType).map(MemberType::ordinal).collect(Collectors.toList()));
                writer.writeStringList(value.getMembers().stream().map(Member::getRole).collect(Collectors.toList()));
                writer.writeGeometry(value.getGeometry());
            }
        }
    } catch (IOException | SQLException ex) {
        throw new RepositoryException(ex);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) Relation(com.baremaps.osm.domain.Relation) MemberType(com.baremaps.osm.domain.Member.MemberType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) Member(com.baremaps.osm.domain.Member) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Aggregations

Member (com.baremaps.osm.domain.Member)8 Relation (com.baremaps.osm.domain.Relation)6 MemberType (com.baremaps.osm.domain.Member.MemberType)5 ArrayList (java.util.ArrayList)5 Info (com.baremaps.osm.domain.Info)4 LocalDateTime (java.time.LocalDateTime)2 HashMap (java.util.HashMap)2 Geometry (org.locationtech.jts.geom.Geometry)2 Osmformat (com.baremaps.osm.binary.Osmformat)1 PrimitiveGroup (com.baremaps.osm.binary.Osmformat.PrimitiveGroup)1 Node (com.baremaps.osm.domain.Node)1 Way (com.baremaps.osm.domain.Way)1 EntityConsumerAdapter (com.baremaps.osm.function.EntityConsumerAdapter)1 RepositoryException (com.baremaps.osm.repository.RepositoryException)1 CopyWriter (com.baremaps.postgres.jdbc.CopyWriter)1 LongDataMap (com.baremaps.store.LongDataMap)1 StreamException (com.baremaps.stream.StreamException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1