File: pmtiles.h

package info (click to toggle)
tilemaker 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 83,488 kB
  • sloc: cpp: 29,461; ansic: 12,510; makefile: 229; ruby: 77; sh: 43
file content (59 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*! \file */ 
#ifndef _PMTILES_H
#define _PMTILES_H

#include <fstream>
#include "external/pmtiles.hpp"

struct TileOffset {
	uint64_t offset : 40;
	size_t length : 24;

	TileOffset(uint64_t offset, size_t length) : offset(offset),length(length) { }
	TileOffset();
};

// Maximum number of tiles in a leaf directory
#define LEAF_DIRECTORY_SIZE 10000000
// Combined size of header and root directory (= start of tile data)
#define HEADER_ROOT 16384
// Tile ID at which to start using leaf directories (=z6/0/0)
#define FIRST_LEAF_TILE 1365
// Threshold for using the root directory only
#define ROOT_ONLY 2200
// Maximum size in bytes of tiles considered "tiny" (i.e. potentially repeatable)
#define TINY_LENGTH 100
// Expire the tiny cache when it reaches this size
#define TINY_MAX_SIZE 10000

class PMTiles { 

public:
	PMTiles();
	virtual ~PMTiles();

	pmtiles::headerv3 header;
	bool isSparse = true;

	void open(std::string &filename);
	void saveTile(int zoom, int x, int y, std::string &data);
	void close(std::string &metadata);

private:
	std::ofstream outputStream;
	std::mutex fileMutex;	// guards file writes, numTilesWritten
	std::mutex indexMutex;	// guards access to sparseIndex, denseIndex, tinyCache, numTilesAddressed
	uint64_t leafStart = 0;
	uint64_t numTilesWritten = 0;
	uint64_t numTilesAddressed = 0;
	uint64_t numTileEntries = 0;
	std::map<uint64_t, TileOffset> sparseIndex;
	std::vector<TileOffset> denseIndex;
	std::unordered_map<std::string, TileOffset> tinyCache;

	void appendWithRLE(std::vector<pmtiles::entryv3> &entries, pmtiles::entryv3 &entry);
	void appendTileEntry(uint64_t tileId, TileOffset offset, std::vector<pmtiles::entryv3> &rootEntries, std::vector<pmtiles::entryv3> &entries);
	void flushEntries(std::vector<pmtiles::entryv3> &rootEntries, std::vector<pmtiles::entryv3> &entries);
};

#endif //_PMTILES_H