mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Clean up internal naming related to tilestats (#190)
* Get rid of the type_and_string near-synonym for serial_val
* Rename file_keys to the more familiar tilestats
* "tas" (type_and_string) => "sv" (serial_val)
* "fk" (tile_keys) => "ts" (tilestats)
* Revert ""tas" (type_and_string) => "sv" (serial_val)"
This reverts commit 4854c57e22.
* More carefully this time: "tas" (type_and_string) => "sv" (serial_val)
This commit is contained in:
+49
-49
@@ -196,21 +196,21 @@ void mbtiles_erase_zoom(sqlite3 *outdb, int z) {
|
||||
}
|
||||
}
|
||||
|
||||
bool type_and_string::operator<(const type_and_string &o) const {
|
||||
if (string < o.string) {
|
||||
bool serial_val::operator<(const serial_val &o) const {
|
||||
if (s < o.s) {
|
||||
return true;
|
||||
}
|
||||
if (string == o.string && type < o.type) {
|
||||
if (s == o.s && type < o.type) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool type_and_string::operator!=(const type_and_string &o) const {
|
||||
bool serial_val::operator!=(const serial_val &o) const {
|
||||
if (type != o.type) {
|
||||
return true;
|
||||
}
|
||||
if (string != o.string) {
|
||||
if (s != o.s) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -261,7 +261,7 @@ void tilestats(std::map<std::string, layermap_entry> const &layermap1, size_t el
|
||||
state.nospace = true;
|
||||
state.json_write_string(geomtype);
|
||||
|
||||
size_t attrib_count = layer.second.file_keys.size();
|
||||
size_t attrib_count = layer.second.tilestats.size();
|
||||
if (attrib_count > max_tilestats_attributes) {
|
||||
attrib_count = max_tilestats_attributes;
|
||||
}
|
||||
@@ -277,7 +277,7 @@ void tilestats(std::map<std::string, layermap_entry> const &layermap1, size_t el
|
||||
state.json_write_array();
|
||||
|
||||
size_t attrs = 0;
|
||||
for (auto attribute : layer.second.file_keys) {
|
||||
for (auto attribute : layer.second.tilestats) {
|
||||
if (attrs == elements) {
|
||||
break;
|
||||
}
|
||||
@@ -338,15 +338,15 @@ void tilestats(std::map<std::string, layermap_entry> const &layermap1, size_t el
|
||||
vals++;
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_stringified(value.string);
|
||||
state.json_write_stringified(value.s);
|
||||
} else {
|
||||
std::string trunc = truncate16(value.string, 256);
|
||||
std::string trunc = truncate16(value.s, 256);
|
||||
|
||||
if (trunc.size() == value.string.size()) {
|
||||
if (trunc.size() == value.s.size()) {
|
||||
vals++;
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string(value.string);
|
||||
state.json_write_string(value.s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -714,7 +714,7 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lnames.size(); i++) {
|
||||
auto fk = layermap.find(lnames[i]);
|
||||
auto ts = layermap.find(lnames[i]);
|
||||
state.nospace = true;
|
||||
state.json_write_hash();
|
||||
|
||||
@@ -726,17 +726,17 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla
|
||||
state.nospace = true;
|
||||
state.json_write_string("description");
|
||||
state.nospace = true;
|
||||
state.json_write_string(fk->second.description);
|
||||
state.json_write_string(ts->second.description);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("minzoom");
|
||||
state.nospace = true;
|
||||
state.json_write_signed(fk->second.minzoom);
|
||||
state.json_write_signed(ts->second.minzoom);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("maxzoom");
|
||||
state.nospace = true;
|
||||
state.json_write_signed(fk->second.maxzoom);
|
||||
state.json_write_signed(ts->second.maxzoom);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("fields");
|
||||
@@ -745,7 +745,7 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla
|
||||
|
||||
bool first = true;
|
||||
size_t attribute_count = 0;
|
||||
for (auto j = fk->second.file_keys.begin(); j != fk->second.file_keys.end(); ++j) {
|
||||
for (auto j = ts->second.tilestats.begin(); j != ts->second.tilestats.end(); ++j) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
@@ -852,35 +852,35 @@ std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
for (auto fk = map->second.file_keys.begin(); fk != map->second.file_keys.end(); ++fk) {
|
||||
std::string attribname = fk->first;
|
||||
for (auto ts = map->second.tilestats.begin(); ts != map->second.tilestats.end(); ++ts) {
|
||||
std::string attribname = ts->first;
|
||||
if (trunc) {
|
||||
attribname = truncate16(attribname, 256);
|
||||
}
|
||||
|
||||
auto fk2 = out_entry->second.file_keys.find(attribname);
|
||||
auto ts2 = out_entry->second.tilestats.find(attribname);
|
||||
|
||||
if (fk2 == out_entry->second.file_keys.end()) {
|
||||
out_entry->second.file_keys.insert(std::pair<std::string, type_and_string_stats>(attribname, fk->second));
|
||||
if (ts2 == out_entry->second.tilestats.end()) {
|
||||
out_entry->second.tilestats.insert(std::pair<std::string, tilestat>(attribname, ts->second));
|
||||
} else {
|
||||
for (auto val : fk->second.sample_values) {
|
||||
auto pt = std::lower_bound(fk2->second.sample_values.begin(), fk2->second.sample_values.end(), val);
|
||||
if (pt == fk2->second.sample_values.end() || *pt != val) { // not found
|
||||
fk2->second.sample_values.insert(pt, val);
|
||||
for (auto val : ts->second.sample_values) {
|
||||
auto pt = std::lower_bound(ts2->second.sample_values.begin(), ts2->second.sample_values.end(), val);
|
||||
if (pt == ts2->second.sample_values.end() || *pt != val) { // not found
|
||||
ts2->second.sample_values.insert(pt, val);
|
||||
|
||||
if (fk2->second.sample_values.size() > max_tilestats_sample_values) {
|
||||
fk2->second.sample_values.pop_back();
|
||||
if (ts2->second.sample_values.size() > max_tilestats_sample_values) {
|
||||
ts2->second.sample_values.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fk2->second.type |= fk->second.type;
|
||||
ts2->second.type |= ts->second.type;
|
||||
|
||||
if (fk->second.min < fk2->second.min) {
|
||||
fk2->second.min = fk->second.min;
|
||||
if (ts->second.min < ts2->second.min) {
|
||||
ts2->second.min = ts->second.min;
|
||||
}
|
||||
if (fk->second.max > fk2->second.max) {
|
||||
fk2->second.max = fk->second.max;
|
||||
if (ts->second.max > ts2->second.max) {
|
||||
ts2->second.max = ts->second.max;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -901,41 +901,41 @@ std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
||||
return out;
|
||||
}
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &file_keys, std::string const &attrib, type_and_string const &val) {
|
||||
void add_to_tilestats(std::map<std::string, tilestat> &tilestats, std::string const &attrib, serial_val const &val) {
|
||||
if (val.type == mvt_null) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto fka = file_keys.find(attrib);
|
||||
if (fka == file_keys.end()) {
|
||||
file_keys.insert(std::pair<std::string, type_and_string_stats>(attrib, type_and_string_stats()));
|
||||
fka = file_keys.find(attrib);
|
||||
auto tsa = tilestats.find(attrib);
|
||||
if (tsa == tilestats.end()) {
|
||||
tilestats.insert(std::pair<std::string, tilestat>(attrib, tilestat()));
|
||||
tsa = tilestats.find(attrib);
|
||||
}
|
||||
|
||||
if (fka == file_keys.end()) {
|
||||
if (tsa == tilestats.end()) {
|
||||
fprintf(stderr, "Can't happen (tilestats)\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
if (val.type == mvt_double) {
|
||||
double d = atof(val.string.c_str());
|
||||
double d = atof(val.s.c_str());
|
||||
|
||||
if (d < fka->second.min) {
|
||||
fka->second.min = d;
|
||||
if (d < tsa->second.min) {
|
||||
tsa->second.min = d;
|
||||
}
|
||||
if (d > fka->second.max) {
|
||||
fka->second.max = d;
|
||||
if (d > tsa->second.max) {
|
||||
tsa->second.max = d;
|
||||
}
|
||||
}
|
||||
|
||||
auto pt = std::lower_bound(fka->second.sample_values.begin(), fka->second.sample_values.end(), val);
|
||||
if (pt == fka->second.sample_values.end() || *pt != val) { // not found
|
||||
fka->second.sample_values.insert(pt, val);
|
||||
auto pt = std::lower_bound(tsa->second.sample_values.begin(), tsa->second.sample_values.end(), val);
|
||||
if (pt == tsa->second.sample_values.end() || *pt != val) { // not found
|
||||
tsa->second.sample_values.insert(pt, val);
|
||||
|
||||
if (fka->second.sample_values.size() > max_tilestats_sample_values) {
|
||||
fka->second.sample_values.pop_back();
|
||||
if (tsa->second.sample_values.size() > max_tilestats_sample_values) {
|
||||
tsa->second.sample_values.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
fka->second.type |= (1 << val.type);
|
||||
tsa->second.type |= (1 << val.type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user