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