use of com.baremaps.osm.domain.Node in project baremaps by baremaps.
the class OsmXmlSpliterator method readNode.
private Node readNode() throws XMLStreamException {
long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
Info info = readInfo();
double latitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LATITUDE));
double longitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LONGITUDE));
// read the content of the node
Map<String, String> tags = new HashMap<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch(reader.getLocalName()) {
case ELEMENT_NAME_TAG:
readTag(tags);
break;
default:
readUnknownElement();
break;
}
}
return new Node(id, info, tags, longitude, latitude);
}
use of com.baremaps.osm.domain.Node in project baremaps by baremaps.
the class DataBlockReader method readDenseNodes.
/**
* Read the dense nodes with the provided consumer.
*
* @param consumer the consumer
*/
public void readDenseNodes(Consumer<Node> consumer) {
for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
DenseNodes denseNodes = group.getDense();
long id = 0;
long lat = 0;
long lon = 0;
long timestamp = 0;
long changeset = 0;
int sid = 0;
int uid = 0;
// Index into the keysvals array.
int j = 0;
for (int i = 0; i < denseNodes.getIdCount(); i++) {
id = denseNodes.getId(i) + id;
Osmformat.DenseInfo denseInfo = denseNodes.getDenseinfo();
int version = denseInfo.getVersion(i);
uid = denseInfo.getUid(i) + uid;
sid = denseInfo.getUserSid(i) + sid;
timestamp = denseInfo.getTimestamp(i) + timestamp;
changeset = denseInfo.getChangeset(i) + changeset;
lat = denseNodes.getLat(i) + lat;
lon = denseNodes.getLon(i) + lon;
// If empty, assume that nothing here has keys or vals.
Map<String, String> tags = new HashMap<>();
if (denseNodes.getKeysValsCount() > 0) {
while (denseNodes.getKeysVals(j) != 0) {
int keyid = denseNodes.getKeysVals(j++);
int valid = denseNodes.getKeysVals(j++);
tags.put(getString(keyid), getString(valid));
}
// Skip over the '0' delimiter.
j++;
}
Info info = new Info(version, getTimestamp(timestamp), changeset, uid);
consumer.accept(new Node(id, info, tags, getLon(lon), getLat(lat)));
}
}
}
use of com.baremaps.osm.domain.Node in project baremaps by baremaps.
the class OsmChangeSpliterator method readNode.
private Node readNode() throws XMLStreamException {
long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
Info info = readInfo();
double latitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LATITUDE));
double longitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LONGITUDE));
// read the content of the node
Map<String, String> tags = new HashMap<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch(reader.getLocalName()) {
case ELEMENT_NAME_TAG:
readTag(tags);
break;
default:
readUnknownElement();
break;
}
}
return new Node(id, info, tags, latitude, longitude);
}
use of com.baremaps.osm.domain.Node 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.Node 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;
}
Aggregations