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