mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Use std::set to track the layer-wide feature attribute types.
Track them during parsing, not tiling. Remove the old string pool code.
This commit is contained in:
+21
-33
@@ -9,6 +9,8 @@
|
||||
#include <sqlite3.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include "main.hpp"
|
||||
#include "pool.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
#include "geometry.hpp"
|
||||
@@ -120,19 +122,17 @@ static void aprintf(std::string *buf, const char *format, ...) {
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
static int pvcmp(const void *v1, const void *v2) {
|
||||
const struct pool_val *const *pv1 = (const struct pool_val *const *) v1;
|
||||
const struct pool_val *const *pv2 = (const struct pool_val *const *) v2;
|
||||
|
||||
int n = strcmp((*pv1)->s, (*pv2)->s);
|
||||
if (n != 0) {
|
||||
return n;
|
||||
bool type_and_string::operator<(const type_and_string &o) const {
|
||||
if (string < o.string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (*pv1)->type - (*pv2)->type;
|
||||
if (string == o.string && type < o.type) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, struct pool **file_keys, int nlayers, int forcetable, const char *attribution) {
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution) {
|
||||
char *sql, *err;
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('name', %Q);", fname);
|
||||
@@ -240,37 +240,25 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername,
|
||||
quote(&buf, layername[i]);
|
||||
aprintf(&buf, "\", \"description\": \"\", \"minzoom\": %d, \"maxzoom\": %d, \"fields\": {", minzoom, maxzoom);
|
||||
|
||||
int n = 0;
|
||||
struct pool_val *pv;
|
||||
for (pv = file_keys[i]->head; pv != NULL; pv = pv->next) {
|
||||
n++;
|
||||
}
|
||||
std::set<type_and_string>::iterator j;
|
||||
bool first = true;
|
||||
for (j = file_keys[i].begin(); j != file_keys[i].end(); ++j) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
aprintf(&buf, ", ");
|
||||
}
|
||||
|
||||
struct pool_val *vals[n];
|
||||
n = 0;
|
||||
for (pv = file_keys[i]->head; pv != NULL; pv = pv->next) {
|
||||
vals[n++] = pv;
|
||||
}
|
||||
|
||||
qsort(vals, n, sizeof(struct pool_val *), pvcmp);
|
||||
|
||||
int j;
|
||||
for (j = 0; j < n; j++) {
|
||||
pv = vals[j];
|
||||
aprintf(&buf, "\"");
|
||||
quote(&buf, pv->s);
|
||||
quote(&buf, j->string.c_str());
|
||||
|
||||
if (pv->type == VT_NUMBER) {
|
||||
if (j->type == VT_NUMBER) {
|
||||
aprintf(&buf, "\": \"Number\"");
|
||||
} else if (pv->type == VT_BOOLEAN) {
|
||||
} else if (j->type == VT_BOOLEAN) {
|
||||
aprintf(&buf, "\": \"Boolean\"");
|
||||
} else {
|
||||
aprintf(&buf, "\": \"String\"");
|
||||
}
|
||||
|
||||
if (j + 1 < n) {
|
||||
aprintf(&buf, ", ");
|
||||
}
|
||||
}
|
||||
|
||||
aprintf(&buf, "} }");
|
||||
|
||||
Reference in New Issue
Block a user