Skip to content

Commit

Permalink
mirror metadata into mergd.mbtiles
Browse files Browse the repository at this point in the history
still to do: treat bbox / vector_layers specially
  • Loading branch information
cldellow committed Oct 5, 2024
1 parent 427f2c1 commit 4c5abd8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/mbtiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MBTiles {
virtual ~MBTiles();
void openForWriting(std::string &filename);
void writeMetadata(std::string key, std::string value);
std::vector<std::pair<std::string, std::string>> readMetadata();
void saveTile(int zoom, int x, int y, std::string *data, bool isMerge);
void closeForWriting();

Expand Down
17 changes: 13 additions & 4 deletions src/mbtiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ void MBTiles::openForWriting(string &filename) {
}

void MBTiles::writeMetadata(string key, string value) {
m.lock();
Flock lock(lockfd);
db << "REPLACE INTO metadata (name,value) VALUES (?,?);" << key << value;
m.unlock();
}

std::vector<std::pair<std::string, std::string>> MBTiles::readMetadata() {
Flock lock(lockfd);

std::vector<std::pair<std::string, std::string>> rv;
db << "SELECT name, value FROM metadata;" >> [&](std::string name, std::string value) {
rv.push_back(std::make_pair(name, value));
};

return rv;
}

void MBTiles::insertOrReplace(int zoom, int x, int y, const std::string& data, bool isMerge) {
// NB: assumes we have the `m` mutex
// NB: assumes we have n flock on lockfd
int tmsY = pow(2, zoom) - 1 - y;
int s = isMerge ? 1 : 0;
preparedStatements[s].reset();
Expand All @@ -113,7 +123,6 @@ void MBTiles::insertOrReplace(int zoom, int x, int y, const std::string& data, b

void MBTiles::flushPendingStatements() {
Flock lock(lockfd);
// NB: assumes we have the `m` mutex

db << "BEGIN";

Expand Down
18 changes: 16 additions & 2 deletions src/tilemaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,22 @@ int main(const int argc, const char* argv[]) {
}
}

// TODO: Populate the `metadata` table
// See https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md#content
if (shard == 0) {
// Populate the `metadata` table
// See https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md#content

std::map<std::string, std::string> metadata;
for (auto& input : inputs) {
for (const auto& entry : input->mbtiles.readMetadata()) {
metadata[entry.first] = entry.second;
}
}

// Dump the metadata into merged.mbtiles
for (auto const& entry : metadata) {
merged.writeMetadata(entry.first, entry.second);
}
}

merged.closeForWriting();

Expand Down

0 comments on commit 4c5abd8

Please sign in to comment.