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