2017-07-14 16:56:23 -07:00
|
|
|
#ifndef MVT_HPP
|
|
|
|
#define MVT_HPP
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2018-08-23 17:45:33 -07:00
|
|
|
#include <jsonpull/jsonpull.h>
|
2018-08-30 17:19:34 -07:00
|
|
|
#include "geometry.hpp"
|
2017-07-14 16:56:23 -07:00
|
|
|
|
2016-04-25 14:19:38 -07:00
|
|
|
struct mvt_value;
|
|
|
|
struct mvt_layer;
|
|
|
|
|
2018-07-23 15:11:48 -07:00
|
|
|
enum mvt_fmt {
|
|
|
|
mvt_blake,
|
|
|
|
mvt_original,
|
|
|
|
mvt_reordered,
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int mvt_format;
|
|
|
|
|
2016-04-25 12:13:52 -07:00
|
|
|
enum mvt_operation {
|
|
|
|
mvt_moveto = 1,
|
|
|
|
mvt_lineto = 2,
|
|
|
|
mvt_closepath = 7
|
|
|
|
};
|
|
|
|
|
2018-08-28 16:03:13 -07:00
|
|
|
struct mvt_geometry {
|
|
|
|
long long x = 0;
|
|
|
|
long long y = 0;
|
|
|
|
int /* mvt_operation */ op = 0;
|
|
|
|
std::vector<double> elevations;
|
|
|
|
|
|
|
|
mvt_geometry(int op, long long x, long long y);
|
|
|
|
mvt_geometry(int op, long long x, long long y, std::vector<double> elevation);
|
|
|
|
|
|
|
|
bool operator<(mvt_geometry const &s) const {
|
|
|
|
if (y < s.y || (y == s.y && x < s.x)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(mvt_geometry const &s) const {
|
|
|
|
return y == s.y && x == s.x;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-22 15:10:16 -07:00
|
|
|
enum mvt_geometry_type {
|
2016-04-22 17:10:33 -07:00
|
|
|
mvt_point = 1,
|
|
|
|
mvt_linestring = 2,
|
2018-09-17 16:57:08 -07:00
|
|
|
mvt_polygon = 3,
|
2018-10-18 16:15:35 -07:00
|
|
|
mvt_spline = 4,
|
2016-04-22 15:10:16 -07:00
|
|
|
};
|
|
|
|
|
2016-04-25 12:13:52 -07:00
|
|
|
struct mvt_feature {
|
2017-11-07 15:25:54 -08:00
|
|
|
std::vector<unsigned> tags{};
|
2018-07-20 14:27:22 -07:00
|
|
|
std::vector<unsigned long> properties{};
|
2017-11-07 15:25:54 -08:00
|
|
|
std::vector<mvt_geometry> geometry{};
|
2018-10-18 15:14:06 -07:00
|
|
|
std::vector<unsigned long> knots{};
|
2018-10-18 16:15:35 -07:00
|
|
|
size_t spline_degree = 2;
|
2017-11-07 12:58:27 -08:00
|
|
|
int /* mvt_geometry_type */ type = 0;
|
|
|
|
unsigned long long id = 0;
|
|
|
|
bool has_id = false;
|
2018-09-10 11:25:52 -07:00
|
|
|
std::string string_id = "";
|
2018-02-23 17:06:39 -08:00
|
|
|
bool dropped = false;
|
2018-10-09 17:32:53 -07:00
|
|
|
std::vector<unsigned long> node_attributes{};
|
2016-07-15 13:58:15 -07:00
|
|
|
|
2018-08-28 15:32:43 -07:00
|
|
|
// For use during decoding
|
2018-10-17 11:50:48 -07:00
|
|
|
std::vector<int> elevations{};
|
2018-08-28 15:32:43 -07:00
|
|
|
|
2016-07-15 13:58:15 -07:00
|
|
|
mvt_feature() {
|
|
|
|
has_id = false;
|
|
|
|
id = 0;
|
|
|
|
}
|
2016-04-22 15:10:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
enum mvt_value_type {
|
2016-04-22 17:10:33 -07:00
|
|
|
mvt_string,
|
|
|
|
mvt_float,
|
|
|
|
mvt_double,
|
|
|
|
mvt_int,
|
|
|
|
mvt_uint,
|
|
|
|
mvt_sint,
|
2017-08-24 17:27:30 -07:00
|
|
|
mvt_bool,
|
2016-09-28 15:00:09 -07:00
|
|
|
mvt_hash,
|
2016-09-29 10:12:08 -07:00
|
|
|
mvt_list,
|
2017-08-24 17:27:30 -07:00
|
|
|
mvt_null,
|
2016-04-22 15:10:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mvt_value {
|
|
|
|
mvt_value_type type;
|
|
|
|
std::string string_value;
|
2018-10-08 14:45:40 -07:00
|
|
|
|
2018-10-11 16:01:44 -07:00
|
|
|
std::vector<std::string> hash_keys;
|
2018-10-08 14:45:40 -07:00
|
|
|
std::vector<mvt_value> list_value;
|
|
|
|
|
2016-04-22 15:10:16 -07:00
|
|
|
union {
|
|
|
|
float float_value;
|
|
|
|
double double_value;
|
|
|
|
long long int_value;
|
|
|
|
unsigned long long uint_value;
|
|
|
|
long long sint_value;
|
|
|
|
bool bool_value;
|
2018-06-05 15:01:02 -07:00
|
|
|
int null_value;
|
2016-04-22 15:10:16 -07:00
|
|
|
} numeric_value;
|
2016-04-25 14:19:38 -07:00
|
|
|
|
|
|
|
bool operator<(const mvt_value &o) const;
|
2018-07-23 15:11:48 -07:00
|
|
|
std::string toString() const;
|
2017-11-07 12:58:27 -08:00
|
|
|
|
|
|
|
mvt_value() {
|
|
|
|
this->type = mvt_double;
|
|
|
|
this->string_value = "";
|
|
|
|
this->numeric_value.double_value = 0;
|
|
|
|
}
|
2016-04-22 15:10:16 -07:00
|
|
|
};
|
|
|
|
|
2018-09-27 16:27:37 -07:00
|
|
|
struct mvt_scaling {
|
2018-10-19 11:50:32 -07:00
|
|
|
long offset = 0;
|
|
|
|
double multiplier = 1;
|
|
|
|
double base = 0;
|
2018-09-13 17:04:22 -07:00
|
|
|
};
|
|
|
|
|
2018-08-17 11:21:06 -07:00
|
|
|
struct mvt_layer {
|
|
|
|
int version = 0;
|
|
|
|
std::string name = "";
|
|
|
|
std::vector<mvt_feature> features{};
|
|
|
|
std::vector<std::string> keys{};
|
|
|
|
std::vector<mvt_value> values{};
|
2018-10-23 14:22:10 -07:00
|
|
|
long long extent = 4096;
|
2018-10-11 12:21:07 -07:00
|
|
|
long zoom = -1;
|
|
|
|
long x = -1;
|
|
|
|
long y = -1;
|
2016-04-25 14:19:38 -07:00
|
|
|
|
2018-10-18 15:14:06 -07:00
|
|
|
std::vector<mvt_scaling> attribute_scalings;
|
|
|
|
ssize_t delta_list_scaling = -1;
|
|
|
|
ssize_t spline_scaling = -1;
|
2018-10-19 11:50:32 -07:00
|
|
|
mvt_scaling elevation_scaling;
|
|
|
|
bool has_elevation_scaling = false;
|
2018-10-18 15:14:06 -07:00
|
|
|
|
2018-09-12 14:23:34 -07:00
|
|
|
std::vector<std::string> string_values;
|
2018-09-04 16:07:12 -07:00
|
|
|
std::vector<float> float_values{};
|
|
|
|
std::vector<double> double_values{};
|
|
|
|
std::vector<unsigned long> uint64_values{};
|
|
|
|
|
2016-04-25 14:19:38 -07:00
|
|
|
// Add a key-value pair to a feature, using this layer's constant pool
|
|
|
|
void tag(mvt_feature &feature, std::string key, mvt_value value);
|
2018-07-20 14:27:22 -07:00
|
|
|
void tag_v3(mvt_feature &feature, std::string key, mvt_value value);
|
2016-09-28 17:19:47 -07:00
|
|
|
size_t tag_value(mvt_value const &value);
|
|
|
|
size_t tag_key(std::string const &key);
|
2018-08-14 16:47:53 -07:00
|
|
|
size_t tag_v3_key(std::string key);
|
2018-08-14 17:12:54 -07:00
|
|
|
void tag_v3_value(mvt_value value, std::vector<unsigned long> &onto);
|
2016-04-25 14:19:38 -07:00
|
|
|
|
|
|
|
// For tracking the key-value constants already used in this layer
|
2017-11-07 15:27:47 -08:00
|
|
|
std::map<std::string, size_t> key_map{};
|
|
|
|
std::map<mvt_value, size_t> value_map{};
|
2018-07-20 14:27:22 -07:00
|
|
|
std::map<mvt_value, unsigned long> property_map{};
|
|
|
|
|
2018-10-11 16:01:44 -07:00
|
|
|
mvt_value decode_property(std::vector<unsigned long> const &property, size_t &off) const;
|
2018-07-23 15:11:48 -07:00
|
|
|
void reorder_values();
|
2016-04-22 15:10:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mvt_tile {
|
2017-11-07 15:25:54 -08:00
|
|
|
std::vector<mvt_layer> layers{};
|
2016-04-25 12:13:52 -07:00
|
|
|
|
2018-10-12 13:40:04 -07:00
|
|
|
std::string encode(int z);
|
2017-05-11 12:08:47 -07:00
|
|
|
bool decode(std::string &message, bool &was_compressed);
|
2016-04-22 15:10:16 -07:00
|
|
|
};
|
|
|
|
|
2016-04-25 12:13:52 -07:00
|
|
|
bool is_compressed(std::string const &data);
|
|
|
|
int decompress(std::string const &input, std::string &output);
|
|
|
|
int compress(std::string const &input, std::string &output);
|
|
|
|
int dezig(unsigned n);
|
2018-08-23 17:45:33 -07:00
|
|
|
void tag_object_v3(mvt_layer &layer, json_object *j, std::vector<unsigned long> &onto);
|
2016-12-07 15:54:58 -08:00
|
|
|
|
|
|
|
mvt_value stringified_to_mvt_value(int type, const char *s);
|
2017-11-09 12:49:09 -08:00
|
|
|
|
|
|
|
bool is_integer(const char *s, long long *v);
|
|
|
|
bool is_unsigned_integer(const char *s, unsigned long long *v);
|
2018-10-09 17:32:53 -07:00
|
|
|
std::vector<mvt_geometry> to_feature(drawvec &geom, mvt_layer &layer, std::vector<unsigned long> &onto);
|
2017-07-14 16:56:23 -07:00
|
|
|
#endif
|